1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-24 19:52:37 +01:00

input: properly log hid_error (strfmt wchar_t)

This commit is contained in:
Megamouse 2022-05-07 14:55:33 +02:00
parent 5476b9098e
commit 9a93b150f0
3 changed files with 29 additions and 3 deletions

View File

@ -13,27 +13,39 @@
#include <Windows.h>
#else
#include <errno.h>
#include <locale>
#include <codecvt>
#endif
#ifdef _WIN32
std::string wchar_to_utf8(std::wstring_view src)
{
#ifdef _WIN32
std::string utf8_string;
const auto tmp_size = WideCharToMultiByte(CP_UTF8, 0, src.data(), src.size(), nullptr, 0, nullptr, nullptr);
utf8_string.resize(tmp_size);
WideCharToMultiByte(CP_UTF8, 0, src.data(), src.size(), utf8_string.data(), tmp_size, nullptr, nullptr);
return utf8_string;
#else
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter{};
return converter.to_bytes(src.data());
#endif
}
std::wstring utf8_to_wchar(std::string_view src)
{
#ifdef _WIN32
std::wstring wchar_string;
const auto tmp_size = MultiByteToWideChar(CP_UTF8, 0, src.data(), src.size(), nullptr, 0);
wchar_string.resize(tmp_size);
MultiByteToWideChar(CP_UTF8, 0, src.data(), src.size(), wchar_string.data(), tmp_size);
return wchar_string;
#else
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter{};
return converter.from_bytes(src.data());
#endif
}
#ifdef _WIN32
std::string fmt::win_error_to_string(unsigned long error, void* module_handle)
{
std::string message;
@ -134,6 +146,11 @@ void fmt_class_string<const char*>::format(std::string& out, u64 arg)
}
}
void fmt_class_string<const wchar_t*>::format(std::string& out, u64 arg)
{
out += wchar_to_utf8(reinterpret_cast<const wchar_t*>(arg));
}
template <>
void fmt_class_string<std::string>::format(std::string& out, u64 arg)
{

View File

@ -226,6 +226,17 @@ struct fmt_class_string<char8_t*, void> : fmt_class_string<const char8_t*>
{
};
template <>
struct fmt_class_string<const wchar_t*, void>
{
static void format(std::string& out, u64 arg);
};
template <>
struct fmt_class_string<wchar_t*, void> : fmt_class_string<const wchar_t*>
{
};
namespace fmt
{
// Both uchar and std::byte are allowed

View File

@ -8,10 +8,8 @@
#include "util/types.hpp"
#ifdef _WIN32
std::wstring utf8_to_wchar(std::string_view src);
std::string wchar_to_utf8(std::wstring_view src);
#endif
// Copy null-terminated string from a std::string or a char array to a char array with truncation
template <typename D, typename T>