| 235 | } |
| 236 | |
| 237 | std::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 | |
| 269 | std::string KeyHandler::ReadValue(cm::string_view name, |
| 270 | ValueTypeSet supportedTypes, |
no test coverage detected