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

Function convert_impl

src/spellers/HunspellInterface.cpp:122–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120
121template <typename OutputCharType, typename InputCharType>
122static std::basic_string<OutputCharType> convert_impl(const IconvWrapperT &conv, std::basic_string_view<InputCharType> input) {
123 static std::vector<char> buf;
124 if constexpr (std::is_same_v<OutputCharType, char>)
125 buf.resize((input.length() + 1) * 6);
126 else
127 buf.resize((input.length() + 1) * sizeof(OutputCharType));
128 if (conv.get() == iconv_t(-1)) {
129 return {};
130 }
131 size_t in_size = (input.length() + 1) * sizeof(InputCharType);
132 size_t out_size = buf.size();
133 char *out_buf = buf.data();
134 auto in_buf = input.data();
135 size_t res = iconv(conv.get(), reinterpret_cast<const char **>(&in_buf), &in_size, &out_buf, &out_size);
136 if (res == static_cast<size_t>(-1)) {
137 return {};
138 }
139 return {reinterpret_cast<OutputCharType *>(buf.data())};
140}
141
142std::string DicInfo::to_dictionary_encoding(std::wstring_view input) const { return convert_impl<char>(converter, input); }
143

Callers

nothing calls this directly

Calls 4

iconvFunction · 0.85
dataMethod · 0.80
getMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected