common\string_util.cpp: switch to boost::locale::conv for UTF16ToUTF8() and UTF8ToUTF16() (#6623)

This commit is contained in:
SachinVin 2023-06-18 22:30:00 +05:30 committed by GitHub
parent 06db4ffb17
commit 4c8a98a321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 11 deletions

2
externals/boost vendored

@ -1 +1 @@
Subproject commit 80a171a179c1f901e4f8dfc8962417f44865ceec Subproject commit 32f5cd8ebb35b29ccb3860861bd285f80804bc85

View File

@ -139,11 +139,6 @@ add_library(citra_common STATIC
) )
if (MSVC) if (MSVC)
target_compile_definitions(citra_common PRIVATE
# The standard library doesn't provide any replacement for codecvt yet
# so we can disable this deprecation warning for the time being.
_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
)
target_compile_options(citra_common PRIVATE target_compile_options(citra_common PRIVATE
/W4 /W4

View File

@ -4,12 +4,14 @@
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
#include <codecvt>
#include <cstdlib> #include <cstdlib>
#include <locale> #include <locale>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <boost/locale/encoding_utf.hpp>
#include "common/common_paths.h" #include "common/common_paths.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "common/string_util.h" #include "common/string_util.h"
@ -155,13 +157,11 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st
} }
std::string UTF16ToUTF8(std::u16string_view input) { std::string UTF16ToUTF8(std::u16string_view input) {
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert; return boost::locale::conv::utf_to_utf<char>(input.data(), input.data() + input.size());
return convert.to_bytes(input.data(), input.data() + input.size());
} }
std::u16string UTF8ToUTF16(std::string_view input) { std::u16string UTF8ToUTF16(std::string_view input) {
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert; return boost::locale::conv::utf_to_utf<char16_t>(input.data(), input.data() + input.size());
return convert.from_bytes(input.data(), input.data() + input.size());
} }
#ifdef _WIN32 #ifdef _WIN32