From 65c1df094f90c8fbc3114b70ea012a494ddafdc1 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 11 Nov 2017 14:07:28 +0100 Subject: [PATCH 1/2] Remove unneeded check in StringUtil::UTF16ToUTF8 No code is relying on this unexplained null byte check, since the only code that calls UTF16ToUTF8 on non-Windows systems is UTF16BEToUTF8, which explicitly strips null bytes. --- Source/Core/Common/StringUtil.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index c904f150da..d4aefefc59 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -569,11 +569,7 @@ std::string UTF8ToSHIFTJIS(const std::string& input) std::string UTF16ToUTF8(const std::wstring& input) { - std::string result = CodeToUTF8("UTF-16LE", input); - - // TODO: why is this needed? - result.erase(std::remove(result.begin(), result.end(), 0x00), result.end()); - return result; + return CodeToUTF8("UTF-16LE", input); } #endif From 2c10ba9be1bd42264b097ca771ee808d3022a736 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 11 Nov 2017 17:32:44 +0100 Subject: [PATCH 2/2] Simplify StringUtil::UTF16ToUTF8 --- Source/Core/Common/StringUtil.cpp | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index d4aefefc59..de06d3c3aa 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -410,24 +410,6 @@ void StringPopBackIf(std::string* s, char c) #ifdef _WIN32 -std::string UTF16ToUTF8(const std::wstring& input) -{ - auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast(input.size()), - nullptr, 0, nullptr, nullptr); - - std::string output; - output.resize(size); - - if (size == 0 || - size != WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast(input.size()), - &output[0], static_cast(output.size()), nullptr, nullptr)) - { - output.clear(); - } - - return output; -} - std::wstring CPToUTF16(u32 code_page, const std::string& input) { auto const size = @@ -470,6 +452,11 @@ std::wstring UTF8ToUTF16(const std::string& input) return CPToUTF16(CP_UTF8, input); } +std::string UTF16ToUTF8(const std::wstring& input) +{ + return UTF16ToCP(CP_UTF8, input); +} + std::string SHIFTJISToUTF8(const std::string& input) { return UTF16ToUTF8(CPToUTF16(CODEPAGE_SHIFT_JIS, input));