MCPcopy Create free account
hub / github.com/CppMicroServices/CppMicroServices / ToUTF8String

Function ToUTF8String

util/src/String.cpp:65–80  ·  view source on GitHub ↗

function return empty string if inWStr is empty or if the conversion failed

Source from the content-addressed store, hash-verified

63
64 // function return empty string if inWStr is empty or if the conversion failed
65 std::string
66 ToUTF8String(std::wstring const& inWStr)
67 {
68 if (inWStr.empty())
69 {
70 return std::string();
71 }
72 int char_count = WideCharToMultiByte(CP_UTF8, 0, inWStr.c_str(), -1, NULL, 0, NULL, NULL);
73 std::unique_ptr<char[]> str(new char[char_count]);
74 char_count = WideCharToMultiByte(CP_UTF8, 0, inWStr.c_str(), -1, str.get(), char_count, NULL, NULL);
75 if (char_count == 0)
76 {
77 ThrowInvalidArgument("Failed to convert UTF16 string to UTF8.");
78 }
79 return str.get();
80 }
81 } // namespace util
82} // namespace cppmicroservices
83#endif

Callers 4

GetTempDirectoryFunction · 0.85
GetLastWin32ErrorStrFunction · 0.85
GetExecutablePathFunction · 0.85

Calls 3

ThrowInvalidArgumentFunction · 0.85
getMethod · 0.80
emptyMethod · 0.45

Tested by 1

GetTempDirectoryFunction · 0.68