| 120 | |
| 121 | template <typename OutputCharType, typename InputCharType> |
| 122 | static 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 | |
| 142 | std::string DicInfo::to_dictionary_encoding(std::wstring_view input) const { return convert_impl<char>(converter, input); } |
| 143 | |