You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2023/01/24 00:18:57 UTC

[logging-log4cxx] branch simplify_string_helper created (now c2359d26)

This is an automated email from the ASF dual-hosted git repository.

swebb2066 pushed a change to branch simplify_string_helper
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


      at c2359d26 Use the standard library instead of APR where possible

This branch includes the following new commits:

     new c2359d26 Use the standard library instead of APR where possible

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[logging-log4cxx] 01/01: Use the standard library instead of APR where possible

Posted by sw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

swebb2066 pushed a commit to branch simplify_string_helper
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git

commit c2359d2664edbf4199611c0b8aed40aed5624700
Author: Stephen Webb <st...@sabreautonomous.com.au>
AuthorDate: Tue Jan 24 11:18:35 2023 +1100

    Use the standard library instead of APR where possible
---
 src/main/cpp/stringhelper.cpp | 70 ++++++++++++++++++-------------------------
 1 file changed, 29 insertions(+), 41 deletions(-)

diff --git a/src/main/cpp/stringhelper.cpp b/src/main/cpp/stringhelper.cpp
index 78a7821a..066ab5d6 100644
--- a/src/main/cpp/stringhelper.cpp
+++ b/src/main/cpp/stringhelper.cpp
@@ -21,20 +21,9 @@
 #include <log4cxx/helpers/transcoder.h>
 #include <algorithm>
 #include <vector>
-#include <apr_strings.h>
-#include <log4cxx/helpers/pool.h>
-#if !defined(LOG4CXX)
-	#define LOG4CXX 1
-#endif
-#include <log4cxx/private/log4cxx_private.h>
-#include <cctype>
 #include <iterator>
-#include <apr.h>
-//LOG4CXX-417: need stdlib.h for atoi on some systems.
-#ifdef APR_HAVE_STDLIB_H
-	#include <stdlib.h>
-#endif
-
+#include <algorithm>
+#include <cctype>
 
 using namespace log4cxx;
 using namespace log4cxx::helpers;
@@ -119,22 +108,33 @@ bool StringHelper::endsWith(const LogString& s, const LogString& suffix)
 
 int StringHelper::toInt(const LogString& s)
 {
+#if LOG4CXX_LOGCHAR_IS_UNICHAR
 	std::string as;
 	Transcoder::encode(s, as);
-	return atoi(as.c_str());
+	return std::stoi(as);
+#else
+	return std::stoi(s);
+#endif
 }
 
 int64_t StringHelper::toInt64(const LogString& s)
 {
+#if LOG4CXX_LOGCHAR_IS_UNICHAR
 	std::string as;
 	Transcoder::encode(s, as);
-	return apr_atoi64(as.c_str());
+	return std::stoll(as);
+#else
+	return std::stoll(s);
+#endif
 }
 
-void StringHelper::toString(int n, Pool& pool, LogString& s)
+void StringHelper::toString(int n, Pool& pool, LogString& dst)
 {
-	char* fmt = pool.itoa(n);
-	Transcoder::decode(fmt, s);
+#if LOG4CXX_LOGCHAR_IS_WCHAR
+	dst.append(std::to_wstring(n));
+#else
+	Transcoder::decode(std::to_string(n), dst);
+#endif
 }
 
 void StringHelper::toString(bool val, LogString& dst)
@@ -152,33 +152,21 @@ void StringHelper::toString(bool val, LogString& dst)
 
 void StringHelper::toString(int64_t n, Pool& pool, LogString& dst)
 {
-	if (n >= INT_MIN && n <= INT_MAX)
-	{
-		toString((int) n, pool, dst);
-	}
-	else
-	{
-		const int64_t BILLION = APR_INT64_C(1000000000);
-		int billions = (int) (n / BILLION);
-		char* upper = pool.itoa(billions);
-		int remain = (int) (n - billions * BILLION);
-
-		if (remain < 0)
-		{
-			remain *= -1;
-		}
-
-		char* lower = pool.itoa(remain);
-		Transcoder::decode(upper, dst);
-		dst.append(9 - strlen(lower), 0x30 /* '0' */);
-		Transcoder::decode(lower, dst);
-	}
+#if LOG4CXX_LOGCHAR_IS_WCHAR
+	dst.append(std::to_wstring(n));
+#else
+	Transcoder::decode(std::to_string(n), dst);
+#endif
 }
 
 
-void StringHelper::toString(size_t n, Pool& pool, LogString& s)
+void StringHelper::toString(size_t n, Pool& pool, LogString& dst)
 {
-	toString((int64_t) n, pool, s);
+#if LOG4CXX_LOGCHAR_IS_WCHAR
+	dst.append(std::to_wstring(n));
+#else
+	Transcoder::decode(std::to_string(n), dst);
+#endif
 }
 
 LogString StringHelper::format(const LogString& pattern, const std::vector<LogString>& params)