MCPcopy Create free account
hub / github.com/Predelnik/DSpellCheck / utf8_to_mapped_wstring

Function utf8_to_mapped_wstring

src/npp/TextUtils.cpp:6–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include "common/utf8.h"
5
6MappedWstring 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
31MappedWstring to_mapped_wstring(std::string_view str) {
32 if (str.empty())

Callers 1

to_mapped_wstringMethod · 0.85

Calls 6

utf8_is_contFunction · 0.85
utf8_incFunction · 0.85
dataMethod · 0.80
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected