MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / utf8_encode

Function utf8_encode

wmi/wmi.cpp:9–18  ·  view source on GitHub ↗

Taken from https://stackoverflow.com/questions/215963/ Convert a wide Unicode string to an UTF8 string

Source from the content-addressed store, hash-verified

7// Taken from https://stackoverflow.com/questions/215963/
8// Convert a wide Unicode string to an UTF8 string
9std::string utf8_encode(const std::wstring& wstr)
10{
11 if (wstr.empty()) return std::string();
12
13 int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int) wstr.size(), nullptr, 0, nullptr, nullptr);
14 std::string strTo(size_needed, 0);
15 WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int) wstr.size(), &strTo[0], size_needed, nullptr, nullptr);
16
17 return strTo;
18}
19
20// Convert an UTF8 string to a wide Unicode String
21std::wstring utf8_decode(const std::string& str)

Callers 1

queryMethod · 0.85

Calls 2

emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected