75 if (utf8.empty())
return std::wstring();
78 const DWORD conversionFlags = MB_ERR_INVALID_CHARS;
83 const int utf16Length = ::MultiByteToWideChar(
92 if (utf16Length == 0) {
94 DWORD error = ::GetLastError();
96 throw utf8_conversion_error(
97 (error == ERROR_NO_UNICODE_TRANSLATION)
98 ?
"Invalid UTF-8 sequence found in input string."
99 :
"Can't get length of UTF-16 string (MultiByteToWideChar "
101 utf8_conversion_error::conversion_utf16_from_utf8, error);
108 utf16.resize(utf16Length);
113 if (!::MultiByteToWideChar(
125 DWORD error = ::GetLastError();
126 throw utf8_conversion_error(
127 "Can't convert string from UTF-8 to UTF-16 (MultiByteToWideChar "
129 utf8_conversion_error::conversion_utf16_from_utf8, error);