diff options
| author | Léo Lam <leo@leolam.fr> | 2020-10-26 19:01:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-26 19:01:26 +0100 |
| commit | 07e6d008bd6c34b8af07247935bc8aa6abc596df (patch) | |
| tree | e5084fc3c855e85bcff41046533ec765135e3656 /Source/Core/Common/StringUtil.cpp | |
| parent | 7f66de062c3c0b7d0f1e49682f8663dc978e76fc (diff) | |
| parent | 4e8df93f4179a684b507d9c712b7e8121fc83119 (diff) | |
Merge pull request #9187 from lioncash/commonlog
Common: Migrate logging to fmt
Diffstat (limited to 'Source/Core/Common/StringUtil.cpp')
| -rw-r--r-- | Source/Core/Common/StringUtil.cpp | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index 5ef8b01d24..8889301549 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -179,7 +179,7 @@ std::string StringFromFormatV(const char* format, va_list args) #endif if (vasprintf(&buf, format, args) < 0) { - ERROR_LOG(COMMON, "Unable to allocate memory for string"); + ERROR_LOG_FMT(COMMON, "Unable to allocate memory for string"); buf = nullptr; } @@ -442,24 +442,22 @@ std::wstring CPToUTF16(u32 code_page, std::string_view input) std::string UTF16ToCP(u32 code_page, std::wstring_view input) { - std::string output; + if (input.empty()) + return {}; - if (0 != input.size()) - { - // "If cchWideChar [input buffer size] is set to 0, the function fails." -MSDN - auto const size = WideCharToMultiByte( - code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0, nullptr, nullptr); + // "If cchWideChar [input buffer size] is set to 0, the function fails." -MSDN + auto const size = WideCharToMultiByte(code_page, 0, input.data(), static_cast<int>(input.size()), + nullptr, 0, nullptr, nullptr); - output.resize(size); + std::string output(size, '\0'); - if (size != WideCharToMultiByte(code_page, 0, input.data(), static_cast<int>(input.size()), - &output[0], static_cast<int>(output.size()), nullptr, nullptr)) - { - const DWORD error_code = GetLastError(); - ERROR_LOG(COMMON, "WideCharToMultiByte Error in String '%s': %lu", - std::wstring(input).c_str(), error_code); - output.clear(); - } + if (size != WideCharToMultiByte(code_page, 0, input.data(), static_cast<int>(input.size()), + output.data(), static_cast<int>(output.size()), nullptr, nullptr)) + { + const DWORD error_code = GetLastError(); + ERROR_LOG_FMT(COMMON, "WideCharToMultiByte Error in String '{}': {}", WStringToUTF8(input), + error_code); + return {}; } return output; @@ -508,7 +506,7 @@ std::string CodeTo(const char* tocode, const char* fromcode, std::basic_string_v iconv_t const conv_desc = iconv_open(tocode, fromcode); if ((iconv_t)-1 == conv_desc) { - ERROR_LOG(COMMON, "Iconv initialization failure [%s]: %s", fromcode, strerror(errno)); + ERROR_LOG_FMT(COMMON, "Iconv initialization failure [{}]: {}", fromcode, strerror(errno)); } else { @@ -541,7 +539,7 @@ std::string CodeTo(const char* tocode, const char* fromcode, std::basic_string_v } else { - ERROR_LOG(COMMON, "iconv failure [%s]: %s", fromcode, strerror(errno)); + ERROR_LOG_FMT(COMMON, "iconv failure [{}]: {}", fromcode, strerror(errno)); break; } } |
