30 using char_type = char;
31 using fallback_encoder_type =
char_map<
"cp-1252">;
32 using fallback_char_type = fallback_encoder_type::char_type;
34 [[nodiscard]]
constexpr std::endian guess_endian(
void const *ptr,
size_t size, std::endian endian)
const noexcept
36 return std::endian::native;
41 hilet str = std::string_view(&cu, 1_uz);
42 auto first = str.begin();
43 hilet[code_point, valid] = fallback_encoder_type{}.read(first, str.end());
44 return {code_point,
false};
47 template<
typename It,
typename EndIt>
50 if (it == last or (first_cu & 0xc0) == 0x80) {
57 hi_axiom(length >= 2);
70 if ((cu & 0xc0) != 0x80) {
80 for (uint8_t actual_length = 2; actual_length != length; ++actual_length) {
83 return {0xfffd,
false};
87 if ((cu & 0b11'000000) != 0b10'000000) {
89 return {0xfffd,
false};
96 cp |= cu & 0b00'111111;
101 valid &= cp < 0x11'0000;
103 valid &= cp < 0xd800 or cp >= 0xe000;
107 return {0xfffd,
false};
113 template<
typename It,
typename EndIt>
116 hi_axiom(it != last);
120 if (not to_bool(cu & 0x80)) [[likely]] {
125 return read(it, last, cu);
131 hi_axiom(code_point < 0x11'0000);
132 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
134 return {
narrow_cast<uint8_t>((code_point > 0x7f) + (code_point > 0x7ff) + (code_point > 0xffff) + 1),
true};
137 template<
typename It>
138 constexpr void write(
char32_t code_point, It& dst)
const noexcept
140 hi_axiom(code_point < 0x11'0000);
141 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
143 hilet num_cu =
truncate<uint8_t>((code_point > 0x7f) + (code_point > 0x7ff) + (code_point > 0xffff));
146 leading_ones >>= num_cu;
151 auto shift = num_cu * 6;
177#if defined(HI_HAS_SSE2)
178 template<
typename It>
179 hi_force_inline __m128i read_ascii_chunk16(It it)
const noexcept
181 return _mm_loadu_si128(
reinterpret_cast<__m128i
const *
>(
std::addressof(*it)));
184 template<
typename It>
185 hi_force_inline
void write_ascii_chunk16(__m128i chunk, It dst)
const noexcept
187 _mm_storeu_si128(
reinterpret_cast<__m128i *
>(
std::addressof(*dst)), chunk);