summaryrefslogtreecommitdiff
path: root/Source/Core/Common/StringUtil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/Common/StringUtil.cpp')
-rw-r--r--Source/Core/Common/StringUtil.cpp34
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;
}
}