| 90 | { |
| 91 | #ifdef PDAL_WIN32_STL |
| 92 | std::wstring toNative(const std::string& in) |
| 93 | { |
| 94 | if (in.empty()) |
| 95 | return std::wstring(); |
| 96 | |
| 97 | // The first call determines the length of the conversion. The second does the |
| 98 | // actual conversion. |
| 99 | int len = MultiByteToWideChar(CP_UTF8, 0, in.data(), in.length(), nullptr, 0); |
| 100 | std::wstring out(len, 0); |
| 101 | if (MultiByteToWideChar(CP_UTF8, 0, in.data(), in.length(), out.data(), len) == 0) |
| 102 | { |
| 103 | char buf[200] {}; |
| 104 | len = FormatMessageA(0, 0, GetLastError(), 0, buf, 199, 0); |
| 105 | throw pdal_error("Can't convert UTF8 to UTF16: " + std::string(buf, len)); |
| 106 | } |
| 107 | return out; |
| 108 | } |
| 109 | |
| 110 | std::string fromNative(const std::wstring& in) |
| 111 | { |
no test coverage detected