| 4 | #include "common/utf8.h" |
| 5 | |
| 6 | MappedWstring utf8_to_mapped_wstring(std::string_view str) { |
| 7 | if (str.empty()) |
| 8 | return {}; |
| 9 | ptrdiff_t len = str.length(); |
| 10 | std::vector<wchar_t> buf; |
| 11 | std::vector<TextPosition> mapping; |
| 12 | buf.reserve(len); |
| 13 | mapping.reserve(len); |
| 14 | auto it = str.data(); |
| 15 | // sadly this garbage skipping is required due to bad find prev mistake algorithm |
| 16 | while (utf8_is_cont(*it)) |
| 17 | ++it; |
| 18 | size_t char_cnt = 1; |
| 19 | while (it - str.data() < len) { |
| 20 | auto next = utf8_inc(it); |
| 21 | buf.resize(char_cnt); |
| 22 | MultiByteToWideChar(CP_UTF8, 0, it, static_cast<int>(next - it), buf.data() + char_cnt - 1, 1); |
| 23 | mapping.push_back(it - str.data()); |
| 24 | ++char_cnt; |
| 25 | it = next; |
| 26 | } |
| 27 | mapping.push_back(it - str.data()); |
| 28 | return {std::wstring{buf.begin(), buf.end()}, std::move(mapping)}; |
| 29 | } |
| 30 | |
| 31 | MappedWstring to_mapped_wstring(std::string_view str) { |
| 32 | if (str.empty()) |
no test coverage detected