mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-03 05:21:25 +12:00
input: properly log hid_error (strfmt wchar_t)
This commit is contained in:
parent
5476b9098e
commit
9a93b150f0
3 changed files with 29 additions and 3 deletions
|
@ -13,27 +13,39 @@
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#else
|
#else
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <locale>
|
||||||
|
#include <codecvt>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
std::string wchar_to_utf8(std::wstring_view src)
|
std::string wchar_to_utf8(std::wstring_view src)
|
||||||
{
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
std::string utf8_string;
|
std::string utf8_string;
|
||||||
const auto tmp_size = WideCharToMultiByte(CP_UTF8, 0, src.data(), src.size(), nullptr, 0, nullptr, nullptr);
|
const auto tmp_size = WideCharToMultiByte(CP_UTF8, 0, src.data(), src.size(), nullptr, 0, nullptr, nullptr);
|
||||||
utf8_string.resize(tmp_size);
|
utf8_string.resize(tmp_size);
|
||||||
WideCharToMultiByte(CP_UTF8, 0, src.data(), src.size(), utf8_string.data(), tmp_size, nullptr, nullptr);
|
WideCharToMultiByte(CP_UTF8, 0, src.data(), src.size(), utf8_string.data(), tmp_size, nullptr, nullptr);
|
||||||
return utf8_string;
|
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)
|
std::wstring utf8_to_wchar(std::string_view src)
|
||||||
{
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
std::wstring wchar_string;
|
std::wstring wchar_string;
|
||||||
const auto tmp_size = MultiByteToWideChar(CP_UTF8, 0, src.data(), src.size(), nullptr, 0);
|
const auto tmp_size = MultiByteToWideChar(CP_UTF8, 0, src.data(), src.size(), nullptr, 0);
|
||||||
wchar_string.resize(tmp_size);
|
wchar_string.resize(tmp_size);
|
||||||
MultiByteToWideChar(CP_UTF8, 0, src.data(), src.size(), wchar_string.data(), tmp_size);
|
MultiByteToWideChar(CP_UTF8, 0, src.data(), src.size(), wchar_string.data(), tmp_size);
|
||||||
return wchar_string;
|
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 fmt::win_error_to_string(unsigned long error, void* module_handle)
|
||||||
{
|
{
|
||||||
std::string message;
|
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 <>
|
template <>
|
||||||
void fmt_class_string<std::string>::format(std::string& out, u64 arg)
|
void fmt_class_string<std::string>::format(std::string& out, u64 arg)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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
|
namespace fmt
|
||||||
{
|
{
|
||||||
// Both uchar and std::byte are allowed
|
// Both uchar and std::byte are allowed
|
||||||
|
|
|
@ -8,10 +8,8 @@
|
||||||
|
|
||||||
#include "util/types.hpp"
|
#include "util/types.hpp"
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
std::wstring utf8_to_wchar(std::string_view src);
|
std::wstring utf8_to_wchar(std::string_view src);
|
||||||
std::string wchar_to_utf8(std::wstring_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
|
// Copy null-terminated string from a std::string or a char array to a char array with truncation
|
||||||
template <typename D, typename T>
|
template <typename D, typename T>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue