mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 05:47:56 -07:00
Merge pull request #7578 from jordan-woyak/master
Fix spurious error logs for conversions of empty strings on Windows.
This commit is contained in:
commit
2bb61afe6e
@ -471,20 +471,25 @@ std::wstring CPToUTF16(u32 code_page, const std::string& input)
|
|||||||
|
|
||||||
std::string UTF16ToCP(u32 code_page, const std::wstring& input)
|
std::string UTF16ToCP(u32 code_page, const std::wstring& input)
|
||||||
{
|
{
|
||||||
auto const size = WideCharToMultiByte(code_page, 0, input.data(), static_cast<int>(input.size()),
|
|
||||||
nullptr, 0, nullptr, false);
|
|
||||||
|
|
||||||
std::string output;
|
std::string output;
|
||||||
output.resize(size);
|
|
||||||
|
|
||||||
if (size == 0 ||
|
if (0 != input.size())
|
||||||
size != WideCharToMultiByte(code_page, 0, input.data(), static_cast<int>(input.size()),
|
|
||||||
&output[0], static_cast<int>(output.size()), nullptr, false))
|
|
||||||
{
|
{
|
||||||
const DWORD error_code = GetLastError();
|
// "If cchWideChar [input buffer size] is set to 0, the function fails." -MSDN
|
||||||
ERROR_LOG(COMMON, "WideCharToMultiByte Error in String '%s': %lu", input.c_str(), error_code);
|
auto const size = WideCharToMultiByte(
|
||||||
output.clear();
|
code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0, nullptr, false);
|
||||||
|
|
||||||
|
output.resize(size);
|
||||||
|
|
||||||
|
if (size != WideCharToMultiByte(code_page, 0, input.data(), static_cast<int>(input.size()),
|
||||||
|
&output[0], static_cast<int>(output.size()), nullptr, false))
|
||||||
|
{
|
||||||
|
const DWORD error_code = GetLastError();
|
||||||
|
ERROR_LOG(COMMON, "WideCharToMultiByte Error in String '%s': %lu", input.c_str(), error_code);
|
||||||
|
output.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user