| 76 | } |
| 77 | |
| 78 | std::wstring ToWString(const std::string& source, bool utf8) |
| 79 | { |
| 80 | std::wstring result; |
| 81 | if (source.length() > 0) { |
| 82 | UINT codepage = CP_UTF8; |
| 83 | if (!utf8) { |
| 84 | codepage = AreFileApisANSI() ? GetACP() : GetOEMCP(); |
| 85 | } |
| 86 | int sizeRequired = ::MultiByteToWideChar( |
| 87 | codepage, 0, source.c_str(), static_cast<int>(source.length()), nullptr, 0); |
| 88 | if (sizeRequired == 0) { |
| 89 | throw windows_error("failed to convert string to wide character"); |
| 90 | } |
| 91 | result.resize(sizeRequired, L'\0'); |
| 92 | ::MultiByteToWideChar(codepage, 0, source.c_str(), |
| 93 | static_cast<int>(source.length()), &result[0], sizeRequired); |
| 94 | } |
| 95 | |
| 96 | return result; |
| 97 | } |
| 98 | |
| 99 | static std::locale loc(""); |
| 100 | static auto locToLowerW = [](wchar_t in) -> wchar_t { |
no test coverage detected