| 31 | } |
| 32 | |
| 33 | std::wstring ToWide(const std::string& narrow) noexcept |
| 34 | { |
| 35 | try { |
| 36 | if (narrow.empty()) { |
| 37 | return {}; |
| 38 | } |
| 39 | std::wstring wide; |
| 40 | // TODO: replace with resize_and_overwrite when it becomes widely available |
| 41 | wide.resize(narrow.size() + 1); |
| 42 | const auto actual = MultiByteToWideChar(CP_UTF8, 0, narrow.data(), (int)narrow.size(), wide.data(), (int)wide.size()); |
| 43 | if (actual > 0) { |
| 44 | wide.resize(actual); |
| 45 | return wide; |
| 46 | } |
| 47 | pmlog_error("failed conversion to wide").hr(); |
| 48 | } |
| 49 | catch (...) { |
| 50 | pmlog_error(ReportException()); |
| 51 | } |
| 52 | return {}; |
| 53 | } |
| 54 | |
| 55 | std::string ToNarrow(const std::wstring& wide) noexcept |
| 56 | { |