function returns empty string if inStr is empty or if the conversion failed
| 45 | |
| 46 | // function returns empty string if inStr is empty or if the conversion failed |
| 47 | std::wstring |
| 48 | ToWString(std::string const& inStr) |
| 49 | { |
| 50 | if (inStr.empty()) |
| 51 | { |
| 52 | return std::wstring(); |
| 53 | } |
| 54 | int wchar_count = MultiByteToWideChar(CP_UTF8, 0, inStr.c_str(), -1, NULL, 0); |
| 55 | std::unique_ptr<wchar_t[]> wBuf(new wchar_t[wchar_count]); |
| 56 | wchar_count = MultiByteToWideChar(CP_UTF8, 0, inStr.c_str(), -1, wBuf.get(), wchar_count); |
| 57 | if (wchar_count == 0) |
| 58 | { |
| 59 | ThrowInvalidArgument("Failed to convert " + inStr + " to UTF16."); |
| 60 | } |
| 61 | return wBuf.get(); |
| 62 | } |
| 63 | |
| 64 | // function return empty string if inWStr is empty or if the conversion failed |
| 65 | std::string |
no test coverage detected