| 207 | } |
| 208 | |
| 209 | std::wstring KeyHandler::ToWide(cm::string_view str) |
| 210 | { |
| 211 | std::wstring wstr; |
| 212 | |
| 213 | if (str.empty()) { |
| 214 | return wstr; |
| 215 | } |
| 216 | |
| 217 | auto const wlength = |
| 218 | MultiByteToWideChar(KWSYS_ENCODING_DEFAULT_CODEPAGE, 0, str.data(), |
| 219 | int(str.size()), nullptr, 0); |
| 220 | if (wlength > 0) { |
| 221 | auto wdata = cm::make_unique<wchar_t[]>(wlength); |
| 222 | auto const r = |
| 223 | MultiByteToWideChar(KWSYS_ENCODING_DEFAULT_CODEPAGE, 0, str.data(), |
| 224 | int(str.size()), wdata.get(), wlength); |
| 225 | if (r > 0) { |
| 226 | wstr = std::wstring(wdata.get(), wlength); |
| 227 | } else { |
| 228 | throw registry_error(FormatSystemError(GetLastError())); |
| 229 | } |
| 230 | } else { |
| 231 | throw registry_error(FormatSystemError(GetLastError())); |
| 232 | } |
| 233 | |
| 234 | return wstr; |
| 235 | } |
| 236 | |
| 237 | std::string KeyHandler::ToNarrow(wchar_t const* wstr, int size) |
| 238 | { |