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

Function ToWString

util/src/String.cpp:47–62  ·  view source on GitHub ↗

function returns empty string if inStr is empty or if the conversion failed

Source from the content-addressed store, hash-verified

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

Callers 5

dlopenFunction · 0.85
LoadMethod · 0.85
ExistsFunction · 0.85
IsRelativeFunction · 0.85
BundlePEFileMethod · 0.85

Calls 3

ThrowInvalidArgumentFunction · 0.85
getMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected