Simplify StringUtil::UTF16ToUTF8
This commit is contained in:
parent
65c1df094f
commit
2c10ba9be1
|
@ -410,24 +410,6 @@ void StringPopBackIf(std::string* s, char c)
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
std::string UTF16ToUTF8(const std::wstring& input)
|
|
||||||
{
|
|
||||||
auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()),
|
|
||||||
nullptr, 0, nullptr, nullptr);
|
|
||||||
|
|
||||||
std::string output;
|
|
||||||
output.resize(size);
|
|
||||||
|
|
||||||
if (size == 0 ||
|
|
||||||
size != WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()),
|
|
||||||
&output[0], static_cast<int>(output.size()), nullptr, nullptr))
|
|
||||||
{
|
|
||||||
output.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::wstring CPToUTF16(u32 code_page, const std::string& input)
|
std::wstring CPToUTF16(u32 code_page, const std::string& input)
|
||||||
{
|
{
|
||||||
auto const size =
|
auto const size =
|
||||||
|
@ -470,6 +452,11 @@ std::wstring UTF8ToUTF16(const std::string& input)
|
||||||
return CPToUTF16(CP_UTF8, 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)
|
std::string SHIFTJISToUTF8(const std::string& input)
|
||||||
{
|
{
|
||||||
return UTF16ToUTF8(CPToUTF16(CODEPAGE_SHIFT_JIS, input));
|
return UTF16ToUTF8(CPToUTF16(CODEPAGE_SHIFT_JIS, input));
|
||||||
|
|
Loading…
Reference in New Issue