debug: convert UTF-8 to ACP on Windows
Our source code assumes all-UTF-8 strings, on Windows the 8-bit active code page is admin-adjustable. Hence we need to convert at runtime. Signed-off-by: Simon Rozman <simon.rozman@amebis.si>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "compat.hpp"
|
||||
#include "string.hpp"
|
||||
#include "unicode.hpp"
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@@ -22,8 +23,15 @@ namespace stdex
|
||||
_Unreferenced_(format);
|
||||
_Unreferenced_(arg);
|
||||
#elif defined(_WIN32)
|
||||
auto tmp = stdex::vsprintf(format, stdex::locale_default, arg);
|
||||
OutputDebugStringA(tmp.c_str());
|
||||
auto tmp = stdex::vsprintf(format, stdex::locale_utf8, arg);
|
||||
auto cp = static_cast<stdex::charset_id>(GetACP());
|
||||
if (cp != stdex::charset_id::utf8) {
|
||||
auto tmpW = stdex::str2wstr(tmp, stdex::charset_id::utf8);
|
||||
auto tmpA = stdex::wstr2str(tmpW, cp);
|
||||
OutputDebugStringA(tmpA.c_str());
|
||||
}
|
||||
else
|
||||
OutputDebugStringA(tmp.c_str());
|
||||
#else
|
||||
vfprintf(stdout, format, arg);
|
||||
#endif
|
||||
@@ -35,7 +43,7 @@ namespace stdex
|
||||
_Unreferenced_(format);
|
||||
_Unreferenced_(arg);
|
||||
#elif defined(_WIN32)
|
||||
auto tmp = stdex::vsprintf(format, stdex::locale_default, arg);
|
||||
auto tmp = stdex::vsprintf(format, stdex::locale_utf8, arg);
|
||||
OutputDebugStringW(tmp.c_str());
|
||||
#else
|
||||
vfwprintf(stdout, format, arg);
|
||||
@@ -74,8 +82,15 @@ namespace stdex
|
||||
_Unreferenced_(format);
|
||||
_Unreferenced_(arg);
|
||||
#elif defined(_WIN32)
|
||||
auto tmp = stdex::vsprintf(format, stdex::locale_default, arg);
|
||||
OutputDebugStringA(tmp.c_str());
|
||||
auto tmp = stdex::vsprintf(format, stdex::locale_utf8, arg);
|
||||
auto cp = static_cast<stdex::charset_id>(GetACP());
|
||||
if (cp != stdex::charset_id::utf8) {
|
||||
auto tmpW = stdex::str2wstr(tmp, stdex::charset_id::utf8);
|
||||
auto tmpA = stdex::wstr2str(tmpW, cp);
|
||||
OutputDebugStringA(tmpA.c_str());
|
||||
}
|
||||
else
|
||||
OutputDebugStringA(tmp.c_str());
|
||||
#else
|
||||
vfprintf(stderr, format, arg);
|
||||
#endif
|
||||
@@ -87,7 +102,7 @@ namespace stdex
|
||||
_Unreferenced_(format);
|
||||
_Unreferenced_(arg);
|
||||
#elif defined(_WIN32)
|
||||
auto tmp = stdex::vsprintf(format, stdex::locale_default, arg);
|
||||
auto tmp = stdex::vsprintf(format, stdex::locale_utf8, arg);
|
||||
OutputDebugStringW(tmp.c_str());
|
||||
#else
|
||||
vfwprintf(stderr, format, arg);
|
||||
|
||||
Reference in New Issue
Block a user