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

Function convert

src/common/Utility.cpp:27–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25#include <cassert>
26
27static std::vector<char> convert(const char *source_enc, const char *target_enc, const void *source_data_ptr, size_t source_len, size_t max_dest_len) {
28 std::vector<char> buf(max_dest_len);
29 auto out_buf = buf.data();
30 iconv_t converter = iconv_open(target_enc, source_enc);
31 auto char_ptr = static_cast<const char *>(source_data_ptr);
32 size_t res = iconv(converter, &char_ptr, &source_len, &out_buf, &max_dest_len);
33 iconv_close(converter);
34
35 if (res == static_cast<size_t>(-1))
36 return {};
37 return buf;
38}
39
40std::wstring to_wstring(std::string_view source) {
41 auto bytes = convert("CHAR", "UCS-2LE//IGNORE", source.data(), source.length(), sizeof(wchar_t) * (source.length() + 1));

Callers 5

to_wstringFunction · 0.70
to_stringFunction · 0.70
to_utf8_stringFunction · 0.70
utf8_to_wstringFunction · 0.70
utf8_to_stringFunction · 0.70

Calls 4

iconv_openFunction · 0.85
iconvFunction · 0.85
iconv_closeFunction · 0.85
dataMethod · 0.80

Tested by

no test coverage detected