| 53 | } |
| 54 | |
| 55 | std::string ToNarrow(const std::wstring& wide) noexcept |
| 56 | { |
| 57 | try { |
| 58 | std::string narrow; |
| 59 | // TODO: replace with resize_and_overwrite when it becomes widely available |
| 60 | narrow.resize(wide.size() * 2); |
| 61 | const auto actual = WideCharToMultiByte(CP_UTF8, 0, wide.data(), (int)wide.size(), |
| 62 | narrow.data(), (int)narrow.size(), nullptr, nullptr); |
| 63 | if (actual > 0) { |
| 64 | narrow.resize(actual); |
| 65 | return narrow; |
| 66 | } |
| 67 | // TODO: (maybe) check for insufficient buffer error and do redo with two-pass (or just double buffer again) |
| 68 | pmlog_error("failed conversion to narrow").hr(); |
| 69 | } |
| 70 | catch (...) { |
| 71 | pmlog_error(ReportException()); |
| 72 | } |
| 73 | return {}; |
| 74 | } |
| 75 | |
| 76 | template<class S> |
| 77 | S TrimWhitespace(const S& input) |
no test coverage detected