mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-20 19:54:19 +01:00
[util] Use transcodeString in tows and fromws helpers
This commit is contained in:
parent
1c08725acd
commit
ec7de66419
@ -252,11 +252,10 @@ namespace dxvk {
|
||||
|
||||
if (options->customDeviceId >= 0)
|
||||
deviceProp.deviceID = options->customDeviceId;
|
||||
|
||||
const char* description = deviceProp.deviceName;
|
||||
// Custom device description
|
||||
if (!options->customDeviceDesc.empty())
|
||||
description = options->customDeviceDesc.c_str();
|
||||
|
||||
std::string description = options->customDeviceDesc.empty()
|
||||
? std::string(deviceProp.deviceName)
|
||||
: options->customDeviceDesc;
|
||||
|
||||
// XXX nvapi workaround for a lot of Unreal Engine 4 games
|
||||
if (options->customVendorId < 0 && options->customDeviceId < 0
|
||||
|
@ -202,42 +202,32 @@ namespace dxvk::str {
|
||||
}
|
||||
|
||||
|
||||
std::string fromws(const WCHAR *ws) {
|
||||
size_t len = ::WideCharToMultiByte(CP_UTF8,
|
||||
0, ws, -1, nullptr, 0, nullptr, nullptr);
|
||||
|
||||
if (len <= 1)
|
||||
return "";
|
||||
|
||||
len -= 1;
|
||||
std::string fromws(const WCHAR* ws) {
|
||||
size_t srcLen = length(ws);
|
||||
size_t dstLen = transcodeString<char>(
|
||||
nullptr, 0, ws, srcLen);
|
||||
|
||||
std::string result;
|
||||
result.resize(len);
|
||||
::WideCharToMultiByte(CP_UTF8, 0, ws, -1,
|
||||
&result.at(0), len, nullptr, nullptr);
|
||||
result.resize(dstLen);
|
||||
|
||||
transcodeString(result.data(),
|
||||
dstLen, ws, srcLen);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void tows(const char* mbs, WCHAR* wcs, size_t wcsLen) {
|
||||
::MultiByteToWideChar(
|
||||
CP_UTF8, 0, mbs, -1,
|
||||
wcs, wcsLen);
|
||||
}
|
||||
|
||||
std::wstring tows(const char* mbs) {
|
||||
size_t len = ::MultiByteToWideChar(CP_UTF8,
|
||||
0, mbs, -1, nullptr, 0);
|
||||
|
||||
if (len <= 1)
|
||||
return L"";
|
||||
|
||||
len -= 1;
|
||||
size_t srcLen = length(mbs);
|
||||
size_t dstLen = transcodeString<wchar_t>(
|
||||
nullptr, 0, mbs, srcLen);
|
||||
|
||||
std::wstring result;
|
||||
result.resize(len);
|
||||
::MultiByteToWideChar(CP_UTF8, 0, mbs, -1,
|
||||
&result.at(0), len);
|
||||
result.resize(dstLen);
|
||||
|
||||
transcodeString(result.data(),
|
||||
dstLen, mbs, srcLen);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -161,15 +161,20 @@ namespace dxvk::str {
|
||||
return totalLength;
|
||||
}
|
||||
|
||||
std::string fromws(const WCHAR *ws);
|
||||
|
||||
void tows(const char* mbs, WCHAR* wcs, size_t wcsLen);
|
||||
|
||||
template <size_t N>
|
||||
void tows(const char* mbs, WCHAR (&wcs)[N]) {
|
||||
return tows(mbs, wcs, N);
|
||||
}
|
||||
/**
|
||||
* \brief Creates string object from wide char array
|
||||
*
|
||||
* \param [in] ws Null-terminated wide string
|
||||
* \returns Regular string object
|
||||
*/
|
||||
std::string fromws(const WCHAR* ws);
|
||||
|
||||
/**
|
||||
* \brief Creates wide string object from char array
|
||||
*
|
||||
* \param [in] mbs Null-terminated string
|
||||
* \returns Wide string object
|
||||
*/
|
||||
std::wstring tows(const char* mbs);
|
||||
|
||||
inline void format1(std::stringstream&) { }
|
||||
|
Loading…
x
Reference in New Issue
Block a user