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/25 22:55:06 UTC
[logging-log4cxx] branch master updated: Use the standard library instead of APR where possible (#188)
This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
The following commit(s) were added to refs/heads/master by this push:
new fe236988 Use the standard library instead of APR where possible (#188)
fe236988 is described below
commit fe2369888c0ca6362161248937e4312825d4cbbb
Author: Stephen Webb <st...@ieee.org>
AuthorDate: Thu Jan 26 09:55:00 2023 +1100
Use the standard library instead of APR where possible (#188)
---
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)