Browse Source

Merge pull request #955 from SergiusTheBest/use-plog-utf8-converter

Use plog::UTF8Converter instead of std::codecvt_utf8
Paul-Louis Ageneau 1 year ago
parent
commit
a3b2fce69a
3 changed files with 4 additions and 16 deletions
  1. 0 1
      CMakeLists.txt
  2. 0 1
      Jamfile
  3. 4 14
      src/global.cpp

+ 0 - 1
CMakeLists.txt

@@ -54,7 +54,6 @@ if(WIN32)
 	if(MSVC)
 	if(MSVC)
 		add_definitions(-DNOMINMAX)
 		add_definitions(-DNOMINMAX)
 		add_definitions(-D_CRT_SECURE_NO_WARNINGS)
 		add_definitions(-D_CRT_SECURE_NO_WARNINGS)
-		add_definitions(-D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
 	endif()
 	endif()
 endif()
 endif()
 
 

+ 0 - 1
Jamfile

@@ -26,7 +26,6 @@ lib libdatachannel
 	<toolset>msvc:<define>WIN32_LEAN_AND_MEAN
 	<toolset>msvc:<define>WIN32_LEAN_AND_MEAN
 	<toolset>msvc:<define>NOMINMAX
 	<toolset>msvc:<define>NOMINMAX
 	<toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS
 	<toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS
-	<toolset>msvc:<define>_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
 	<library>/libdatachannel//usrsctp
 	<library>/libdatachannel//usrsctp
 	<library>/libdatachannel//juice
 	<library>/libdatachannel//juice
 	<library>/libdatachannel//plog
 	<library>/libdatachannel//plog

+ 4 - 14
src/global.cpp

@@ -7,6 +7,7 @@
  */
  */
 
 
 #include "plog/Appenders/ColorConsoleAppender.h"
 #include "plog/Appenders/ColorConsoleAppender.h"
+#include "plog/Converters/UTF8Converter.h"
 #include "plog/Formatters/FuncMessageFormatter.h"
 #include "plog/Formatters/FuncMessageFormatter.h"
 #include "plog/Formatters/TxtFormatter.h"
 #include "plog/Formatters/TxtFormatter.h"
 #include "plog/Init.h"
 #include "plog/Init.h"
@@ -19,11 +20,6 @@
 
 
 #include <mutex>
 #include <mutex>
 
 
-#ifdef _WIN32
-#include <codecvt>
-#include <locale>
-#endif
-
 namespace {
 namespace {
 
 
 void plogInit(plog::Severity severity, plog::IAppender *appender) {
 void plogInit(plog::Severity severity, plog::IAppender *appender) {
@@ -58,16 +54,10 @@ struct LogAppender : public plog::IAppender {
 		auto formatted = plog::FuncMessageFormatter::format(record);
 		auto formatted = plog::FuncMessageFormatter::format(record);
 		formatted.pop_back(); // remove newline
 		formatted.pop_back(); // remove newline
 
 
-#ifdef _WIN32
-		using convert_type = std::codecvt_utf8<wchar_t>;
-		std::wstring_convert<convert_type, wchar_t> converter;
-		std::string str = converter.to_bytes(formatted);
-#else
-		std::string str = formatted;
-#endif
+		const auto& converted = plog::UTF8Converter::convert(formatted); // does nothing on non-Windows systems
 
 
-		if (!callback(static_cast<LogLevel>(severity), str))
-			std::cout << plog::severityToString(severity) << " " << str << std::endl;
+		if (!callback(static_cast<LogLevel>(severity), converted))
+			std::cout << plog::severityToString(severity) << " " << converted << std::endl;
 	}
 	}
 };
 };