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

Method ToNarrow

Source/cmWindowsRegistry.cxx:237–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235}
236
237std::string KeyHandler::ToNarrow(wchar_t const* wstr, int size)
238{
239 std::string str;
240
241 if (size == 0 || (size == -1 && wstr[0] == L'\0')) {
242 return str;
243 }
244
245 auto const length =
246 WideCharToMultiByte(KWSYS_ENCODING_DEFAULT_CODEPAGE, 0, wstr, size,
247 nullptr, 0, nullptr, nullptr);
248 if (length > 0) {
249 auto data = cm::make_unique<char[]>(length);
250 auto const r =
251 WideCharToMultiByte(KWSYS_ENCODING_DEFAULT_CODEPAGE, 0, wstr, size,
252 data.get(), length, nullptr, nullptr);
253 if (r > 0) {
254 if (size == -1) {
255 str = std::string(data.get());
256 } else {
257 str = std::string(data.get(), length);
258 }
259 } else {
260 throw registry_error(FormatSystemError(GetLastError()));
261 }
262 } else {
263 throw registry_error(FormatSystemError(GetLastError()));
264 }
265
266 return str;
267}
268
269std::string KeyHandler::ReadValue(cm::string_view name,
270 ValueTypeSet supportedTypes,

Callers 3

ReadValueMethod · 0.95
GetValueNamesMethod · 0.95
GetSubKeysMethod · 0.95

Calls 2

registry_errorClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected