| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#ifndef VSUTF16_H |
| 22 |
#define VSUTF16_H |
| 23 |
|
| 24 |
#include <string> |
| 25 |
#ifndef NOMINMAX |
| 26 |
#define NOMINMAX |
| 27 |
#endif |
| 28 |
#include <windows.h> |
| 29 |
|
| 30 |
static std::string utf16_to_utf8(const std::wstring &wstr) { |
| 31 |
int required_size = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr); |
| 32 |
std::string buffer; |
| 33 |
buffer.resize(required_size - 1); |
| 34 |
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), static_cast<int>(wstr.size()), &buffer[0], required_size, nullptr, nullptr); |
| 35 |
return buffer; |
| 36 |
} |
| 37 |
|
| 38 |
static std::wstring utf16_from_utf8(const std::string &str) { |
| 39 |
int required_size = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0); |
| 40 |
std::wstring wbuffer; |
| 41 |
wbuffer.resize(required_size - 1); |
| 42 |
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), static_cast<int>(str.size()), &wbuffer[0], required_size); |
| 43 |
return wbuffer; |
| 44 |
} |
| 45 |
|
| 46 |
#endif |