Fix unicode string convertion on Windows
[sdk/tools/netcoredbg.git] / src / debug / netcoredbg / cputil.cpp
1 #include "cputil.h"
2
3 #include <codecvt>
4 #include <locale>
5
6 #ifdef _MSC_VER
7
8 static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,wchar_t> convert;
9
10 std::string to_utf8(const wchar_t *wstr)
11 {
12     return convert.to_bytes(wstr);
13 }
14
15 #else
16
17 static std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
18
19 std::string to_utf8(const char16_t *wstr)
20 {
21     return convert.to_bytes(wstr);
22 }
23
24 #endif
25
26 std::string to_utf8(char16_t wch)
27 {
28     return convert.to_bytes(wch);
29 }
30
31 #ifdef _MSC_VER
32 std::wstring
33 #else
34 std::u16string
35 #endif
36 to_utf16(const std::string &utf8)
37 {
38     return convert.from_bytes(utf8);
39 }