From c0335ac86a517d829e6de7c4df298ecdbd2d301a Mon Sep 17 00:00:00 2001 From: Stephen Webb Date: Fri, 4 Aug 2023 15:00:31 +1000 Subject: [PATCH] Replace duplicate code --- src/main/cpp/file.cpp | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/main/cpp/file.cpp b/src/main/cpp/file.cpp index 325abb724..59cf84261 100644 --- a/src/main/cpp/file.cpp +++ b/src/main/cpp/file.cpp @@ -51,21 +51,21 @@ File::File() : { } -template -static LogString decodeLS(const S* src) +template +static LogString decodeChar(const CharT* src) { LogString dst; if (src != 0) { - Transcoder::decode(std::basic_string(src), dst); + Transcoder::decode(src, dst); } return dst; } template -static LogString decodeLS(const std::basic_string& src) +static LogString decodeLS(const S& src) { LogString dst; Transcoder::decode(src, dst); @@ -79,7 +79,7 @@ File::File(const std::string& name1) } File::File(const char* name1) - : m_priv(std::make_unique(decodeLS(name1))) + : m_priv(std::make_unique(decodeChar(name1))) { } @@ -90,7 +90,7 @@ File::File(const std::wstring& name1) } File::File(const wchar_t* name1) - : m_priv(std::make_unique(decodeLS(name1))) + : m_priv(std::make_unique(decodeChar(name1))) { } #endif @@ -107,27 +107,15 @@ File::File(const UniChar* name1) } #endif -#if LOG4CXX_QSTRING_API -static LogString decodeLS(const QString& src) -{ - LogString dst; - Transcoder::decode(src, dst); - return dst; -} -File::File(const QString& name) +#if LOG4CXX_CFSTRING_API +File::File(const CFStringRef& name) : m_priv(std::make_unique(decodeLS(name))) { } #endif -#if LOG4CXX_CFSTRING_API -static LogString decodeLS(const CFStringRef& src) -{ - LogString dst; - Transcoder::decode(src, dst); - return dst; -} -File::File(const CFStringRef& name) +#if LOG4CXX_QSTRING_API +File::File(const QString& name) : m_priv(std::make_unique(decodeLS(name))) { }