summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/unicode.cpp
diff options
context:
space:
mode:
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
//-------------------------------------------------