99 using from_char_type = from_encoder_type::char_type;
100 using to_char_type = to_encoder_type::char_type;
110 template<
typename OutRange,
typename InRange>
111 [[nodiscard]]
constexpr OutRange
convert(InRange&& src)
const noexcept
118 hilet[size, valid] = _size(cbegin(src), cend(src));
121 if constexpr (From == To and std::is_same_v<InRange, OutRange>) {
134 if (From == To and valid) {
140 _convert(cbegin(src), cend(src),
begin(r));
152 template<
typename OutRange,
typename It,
typename EndIt>
153 [[nodiscard]]
constexpr OutRange
convert(It first, EndIt last)
const noexcept
157 hilet[size, valid] = _size(first, last);
164 if (From == To and valid) {
169 _convert(first, last,
begin(r));
182 template<
typename OutRange = std::basic_
string<to_
char_type>>
183 [[nodiscard]] OutRange
read(
void const *ptr,
size_t size, std::endian endian = std::endian::native)
noexcept
185 hi_assert_not_null(ptr);
187 hilet num_chars = size /
sizeof(from_char_type);
189 endian = from_encoder_type{}.guess_endian(ptr, size, endian);
190 if (endian == std::endian::native) {
191 if (floor(ptr,
sizeof(from_char_type)) == ptr) {
193 reinterpret_cast<from_char_type
const *
>(ptr),
reinterpret_cast<from_char_type
const *
>(ptr) + num_chars);
204 for (
auto& c : tmp) {
205 c = std::byteswap(c);
216 template<
typename InRange>
217 [[nodiscard]]
constexpr to_string_type
operator()(InRange&& src)
const noexcept
223#if defined(HI_HAS_SSE2)
224 using chunk16_type = __m128i;
226 using chunk16_type = void;
229 constexpr static bool _has_read_ascii_chunk16 =
true;
230 constexpr static bool _has_write_ascii_chunk16 =
true;
232 template<
typename It,
typename EndIt>
233 [[nodiscard]]
constexpr void _size_ascii(It& it, EndIt last,
size_t& count)
const noexcept
235 if (not std::is_constant_evaluated()) {
236#if defined(HI_HAS_SSE2)
237 if constexpr (_has_read_ascii_chunk16 and _has_write_ascii_chunk16) {
239 hilet chunk = from_encoder_type{}.read_ascii_chunk16(it);
240 hilet ascii_mask = _mm_movemask_epi8(chunk);
245 count += partial_count;
256 template<
typename SrcIt,
typename SrcEndIt,
typename DstIt>
257 void _convert_ascii(SrcIt& src, SrcEndIt src_last, DstIt& dst)
const noexcept
259 if (not std::is_constant_evaluated()) {
260#if defined(HI_HAS_SSE2)
261 if constexpr (_has_read_ascii_chunk16 and _has_write_ascii_chunk16) {
263 hilet chunk = from_encoder_type{}.read_ascii_chunk16(src);
264 hilet ascii_mask = _mm_movemask_epi8(chunk);
270 to_encoder_type{}.write_ascii_chunk16(chunk, dst);
279 template<
typename It,
typename EndIt>
280 [[nodiscard]]
constexpr std::pair<size_t, bool> _size(It it, EndIt last)
const noexcept
287 _size_ascii(it, last, count);
293 hilet[code_point, read_valid] = from_encoder_type{}.read(it, last);
296 hilet[write_count, write_valid] = to_encoder_type{}.size(code_point);
297 count += write_count;
298 valid &= write_valid;
301 return {
count, valid};
304 template<
typename SrcIt,
typename SrcEndIt,
typename DstIt>
305 void _convert(SrcIt src, SrcEndIt src_last, DstIt dst)
const noexcept
310 _convert_ascii(src, src_last, dst);
312 if (src == src_last) {
316 hilet[code_point, from_valid] = from_encoder_type{}.read(src, src_last);
317 to_encoder_type{}.write(code_point, dst);
constexpr OutRange convert(It first, EndIt last) const noexcept
Convert text between the given encodings.
Definition char_converter.hpp:153
OutRange read(void const *ptr, size_t size, std::endian endian=std::endian::native) noexcept
Read text from a byte array.
Definition char_converter.hpp:183