MCPcopy Create free account
hub / github.com/Kitware/CMake / ToWide

Method ToWide

Source/kwsys/EncodingCXX.cxx:126–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124}
125
126std::wstring Encoding::ToWide(std::string const& str)
127{
128 std::wstring wstr;
129#if defined(_WIN32)
130 int const wlength =
131 MultiByteToWideChar(KWSYS_ENCODING_DEFAULT_CODEPAGE, 0, str.data(),
132 int(str.size()), nullptr, 0);
133 if (wlength > 0) {
134 wchar_t* wdata = new wchar_t[wlength];
135 int r = MultiByteToWideChar(KWSYS_ENCODING_DEFAULT_CODEPAGE, 0, str.data(),
136 int(str.size()), wdata, wlength);
137 if (r > 0) {
138 wstr = std::wstring(wdata, wlength);
139 }
140 delete[] wdata;
141 }
142#else
143 size_t pos = 0;
144 size_t nullPos = 0;
145 do {
146 if (pos < str.size() && str.at(pos) != '\0') {
147 wstr += ToWide(str.c_str() + pos);
148 }
149 nullPos = str.find('\0', pos);
150 if (nullPos != std::string::npos) {
151 pos = nullPos + 1;
152 wstr += wchar_t('\0');
153 }
154 } while (nullPos != std::string::npos);
155#endif
156 return wstr;
157}
158
159std::string Encoding::ToNarrow(std::wstring const& str)
160{

Callers

nothing calls this directly

Calls 6

kwsysEncoding_mbstowcsFunction · 0.85
c_strMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45
atMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected