summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/unicode.cpp
diff options
context:
space:
mode:
author Nathan Woods <npwoods@mess.org>2017-01-02 11:59:25 -0500
committer Nathan Woods <npwoods@mess.org>2017-01-02 11:59:25 -0500
commit3231c3f64821a9914be338bb603d083a01b577de (patch)
tree4d7f1bd1d379076eab691a3e032b77c8e2c8d5b6 /src/lib/util/unicode.cpp
parenta64328499ca0e94c94bb81e51ff5a7e5c0df4336 (diff)
[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.
Diffstat (limited to 'src/lib/util/unicode.cpp')
-rw-r--r--src/lib/util/unicode.cpp36
1 files changed, 36 insertions, 0 deletions
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 <codecvt>
+#include <locale>
+
#include "unicode.h"
#ifdef _WIN32
+#include "strconv.h"
#define UTF8PROC_DLLEXPORT
#endif
@@ -352,6 +356,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<std::codecvt_utf8<wchar_t>> 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<std::codecvt_utf8<wchar_t>> converter;
+ return converter.to_bytes(string);
+#endif
+}
+
+
+//-------------------------------------------------
// internal_normalize_unicode - uses utf8proc to
// normalize unicode
//-------------------------------------------------