1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-03-02 04:29:14 +01:00
dxvk/src/util/util_string.cpp
Joshua Ashton bf14371f9e [util] Wide character conversion changes
Replaces tows with an easier helper that fits in nicer with fixed-size arrays in DXGI, etc.

Prefer UTF8 in tows/fromws.
2019-11-26 01:53:49 +01:00

28 lines
539 B
C++

#include "util_string.h"
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 result;
result.resize(len);
::WideCharToMultiByte(CP_UTF8, 0, ws, -1,
&result.at(0), len, nullptr, nullptr);
return result;
}
void tows(const char* mbs, WCHAR* wcs, size_t wcsLen) {
::MultiByteToWideChar(
CP_UTF8, 0, mbs, -1,
wcs, wcsLen);
}
}