Skip to content

Commit fbc81a7

Browse files
Use plog::UTF8Converter instead of std::codecvt_utf8
Plog has a built-in UTF-8 conversion, so `std::codecvt_utf8` is not required. This makes code simpler and gets rid of `std::codecvt_utf8` deprecation warnings. Also it fixes using a more recent plog version (>= 1.1.10) that supports utf8everywhere mode. That mode is triggered by the `/utf-8` switch in MSVC.
1 parent be51f7e commit fbc81a7

File tree

3 files changed

+4
-16
lines changed

3 files changed

+4
-16
lines changed

CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ if(WIN32)
5454
if(MSVC)
5555
add_definitions(-DNOMINMAX)
5656
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
57-
add_definitions(-D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
5857
endif()
5958
endif()
6059

Jamfile

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ lib libdatachannel
2626
<toolset>msvc:<define>WIN32_LEAN_AND_MEAN
2727
<toolset>msvc:<define>NOMINMAX
2828
<toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS
29-
<toolset>msvc:<define>_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
3029
<library>/libdatachannel//usrsctp
3130
<library>/libdatachannel//juice
3231
<library>/libdatachannel//plog

src/global.cpp

+4-14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include "plog/Appenders/ColorConsoleAppender.h"
10+
#include "plog/Converters/UTF8Converter.h"
1011
#include "plog/Formatters/FuncMessageFormatter.h"
1112
#include "plog/Formatters/TxtFormatter.h"
1213
#include "plog/Init.h"
@@ -19,11 +20,6 @@
1920

2021
#include <mutex>
2122

22-
#ifdef _WIN32
23-
#include <codecvt>
24-
#include <locale>
25-
#endif
26-
2723
namespace {
2824

2925
void plogInit(plog::Severity severity, plog::IAppender *appender) {
@@ -58,16 +54,10 @@ struct LogAppender : public plog::IAppender {
5854
auto formatted = plog::FuncMessageFormatter::format(record);
5955
formatted.pop_back(); // remove newline
6056

61-
#ifdef _WIN32
62-
using convert_type = std::codecvt_utf8<wchar_t>;
63-
std::wstring_convert<convert_type, wchar_t> converter;
64-
std::string str = converter.to_bytes(formatted);
65-
#else
66-
std::string str = formatted;
67-
#endif
57+
const auto& converted = plog::UTF8Converter::convert(formatted); // does nothing on non-Windows systems
6858

69-
if (!callback(static_cast<LogLevel>(severity), str))
70-
std::cout << plog::severityToString(severity) << " " << str << std::endl;
59+
if (!callback(static_cast<LogLevel>(severity), converted))
60+
std::cout << plog::severityToString(severity) << " " << converted << std::endl;
7161
}
7262
};
7363

0 commit comments

Comments
 (0)