From ba111959fa9ac4a40dfb1e7bafe2d2d4a7ef371b Mon Sep 17 00:00:00 2001 From: 34will Date: Wed, 10 Jan 2018 14:49:35 +0000 Subject: [PATCH 1/3] Modified StringUtil to use a u16string instead of a wstring in the non-win32 UTF16BEToUTR8 method. --- Source/Core/Common/StringUtil.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index de06d3c3aa..83384479ee 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -472,6 +472,14 @@ std::string CP1252ToUTF8(const std::string& input) return UTF16ToUTF8(CPToUTF16(CODEPAGE_WINDOWS_1252, input)); } +std::string UTF16BEToUTF8(const char16_t* str, size_t max_size) +{ + const char16_t* str_end = std::find(str, str + max_size, '\0'); + std::wstring result(static_cast(str_end - str), '\0'); + std::transform(str, str_end, result.begin(), static_cast(Common::swap16)); + return UTF16ToUTF8(result); +} + #else template @@ -559,12 +567,12 @@ std::string UTF16ToUTF8(const std::wstring& input) return CodeToUTF8("UTF-16LE", input); } -#endif - std::string UTF16BEToUTF8(const char16_t* str, size_t max_size) { const char16_t* str_end = std::find(str, str + max_size, '\0'); - std::wstring result(static_cast(str_end - str), '\0'); + std::u16string result(static_cast(str_end - str), '\0'); std::transform(str, str_end, result.begin(), static_cast(Common::swap16)); - return UTF16ToUTF8(result); + return CodeToUTF8("UTF-16LE", result); } + +#endif From a949e98d9b3b77493a0e38e7f2227e57c8c6e066 Mon Sep 17 00:00:00 2001 From: 34will Date: Thu, 11 Jan 2018 16:55:23 +0000 Subject: [PATCH 2/3] Modified UTF16BEUTF8 to just convert the UTF-16 C-string into a std::u16string, and pass it into CodeToUTF8 with the 'from' parameter being "UTF-16BE", rather than manually performing the big endian to little endian encoding. --- Source/Core/Common/StringUtil.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index 83384479ee..e2a7b7cfb7 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -570,9 +570,7 @@ std::string UTF16ToUTF8(const std::wstring& input) std::string UTF16BEToUTF8(const char16_t* str, size_t max_size) { const char16_t* str_end = std::find(str, str + max_size, '\0'); - std::u16string result(static_cast(str_end - str), '\0'); - std::transform(str, str_end, result.begin(), static_cast(Common::swap16)); - return CodeToUTF8("UTF-16LE", result); + return CodeToUTF8("UTF-16BE", std::u16string(str, static_cast(str_end - str))); } #endif From 86a787bdf9df5ef54cf38bfd16ae24c73bd9e83c Mon Sep 17 00:00:00 2001 From: 34will Date: Thu, 11 Jan 2018 19:54:16 +0000 Subject: [PATCH 3/3] Modified StringUtil to change UTF16ToUTF8 to use a wstring_convert and codecvt_utf8 to convert a UTF16 wstring to a UTF8 string. --- Source/Core/Common/StringUtil.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index e2a7b7cfb7..8ac8a4a229 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -29,6 +29,7 @@ constexpr u32 CODEPAGE_SHIFT_JIS = 932; constexpr u32 CODEPAGE_WINDOWS_1252 = 1252; #else +#include #include #include #include @@ -564,7 +565,8 @@ std::string UTF8ToSHIFTJIS(const std::string& input) std::string UTF16ToUTF8(const std::wstring& input) { - return CodeToUTF8("UTF-16LE", input); + std::wstring_convert, wchar_t> converter; + return converter.to_bytes(input); } std::string UTF16BEToUTF8(const char16_t* str, size_t max_size)