From 3231c3f64821a9914be338bb603d083a01b577de Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Mon, 2 Jan 2017 11:59:25 -0500 Subject: [Imgtool] Changed to use wcout/wcerr in order to support Unicode console output I really don't like the prevalence of '#ifdef WIN32' in this change, both the _setmode() and bypassing codecvt. I strongly suspect that the latter is the consequence of some mistake that in practice doesn't cause problems in MSVC. I welcome all eyes. --- src/lib/util/unicode.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/lib/util/unicode.cpp') diff --git a/src/lib/util/unicode.cpp b/src/lib/util/unicode.cpp index b3e92e4094e..1f28fe55c47 100644 --- a/src/lib/util/unicode.cpp +++ b/src/lib/util/unicode.cpp @@ -8,9 +8,13 @@ ***************************************************************************/ +#include +#include + #include "unicode.h" #ifdef _WIN32 +#include "strconv.h" #define UTF8PROC_DLLEXPORT #endif @@ -351,6 +355,38 @@ int utf16f_from_uchar(char16_t *utf16string, size_t count, char32_t uchar) } +//------------------------------------------------- +// wstring_from_utf8 +//------------------------------------------------- + +std::wstring wstring_from_utf8(const std::string &utf8string) +{ +#ifdef WIN32 + // for some reason, using codecvt yields bad results on MinGW (but not MSVC) + return osd::text::to_wstring(utf8string); +#else + std::wstring_convert> converter; + return converter.from_bytes(utf8string); +#endif +} + + +//------------------------------------------------- +// utf8_from_wstring +//------------------------------------------------- + +std::string utf8_from_wstring(const std::wstring &string) +{ +#ifdef WIN32 + // for some reason, using codecvt yields bad results on MinGW (but not MSVC) + return osd::text::from_wstring(string); +#else + std::wstring_convert> converter; + return converter.to_bytes(string); +#endif +} + + //------------------------------------------------- // internal_normalize_unicode - uses utf8proc to // normalize unicode -- cgit v1.2.3-70-g09d2