27 using char_type = char;
28 using fallback_encoder_type =
char_map<
"cp-1252">;
29 using fallback_char_type = fallback_encoder_type::char_type;
31 [[nodiscard]]
constexpr std::endian guess_endian(
void const *ptr,
size_t size, std::endian endian)
const noexcept
33 return std::endian::native;
36 template<
typename It,
typename EndIt>
39 hilet[code_point, valid] = fallback_encoder_type{}.read(it, last);
40 return {code_point,
false};
43 template<
typename It,
typename EndIt>
49 if (not to_bool(cu & 0x80)) [[likely]] {
51 return {char_cast<char32_t>(cu),
true};
53 }
else if (it == last or (cu & 0xc0) == 0x80) [[unlikely]] {
57 return read_fallback(it, last);
60 hilet length = narrow_cast<uint8_t>(std::countl_one(char_cast<uint8_t>(cu)));
64 auto cp = char_cast<char32_t>(cu & (0x7f >> length));
70 if ((cu & 0xc0) != 0x80) [[unlikely]] {
74 return read_fallback(it, last);
78 auto todo = length - 2;
83 return {0xfffd,
false};
90 if ((cu & 0xc0) != 0x80) [[unlikely]] {
93 return {0xfffd,
false};
99 valid &= cp < 0x11'0000;
101 valid &= cp < 0xd800 or cp >= 0xe000;
103 valid &= length == narrow_cast<uint8_t>((cp > 0x7f) + (cp > 0x7ff) + (cp > 0xffff) + 1);
104 if (not valid) [[unlikely]] {
105 return {0xfffd,
false};
114 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
116 return {narrow_cast<uint8_t>((code_point > 0x7f) + (code_point > 0x7ff) + (code_point > 0xffff) + 1),
true};
119 template<
typename It>
120 constexpr void write(
char32_t code_point, It& dst)
const noexcept
123 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
125 hilet length = truncate<uint8_t>((code_point > 0x7f) + (code_point > 0x7ff) + (code_point > 0xffff));
126 if (
auto i = length) {
128 dst[i] = truncate<char8_t>((code_point & 0x3f) | 0x80);
132 code_point |= 0x780 >> length;
134 dst[0] = truncate<char8_t>(code_point);
135 dst += length + 1_uz;
138#if defined(HI_HAS_SSE2)
139 template<
typename It>
140 hi_force_inline __m128i read_ascii_chunk16(It it)
const noexcept
142 return _mm_loadu_si128(
reinterpret_cast<__m128i
const *
>(
std::addressof(*it)));
145 template<
typename It>
146 hi_force_inline
void write_ascii_chunk16(__m128i chunk, It dst)
const noexcept
148 _mm_storeu_si128(
reinterpret_cast<__m128i *
>(
std::addressof(*dst)), chunk);
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238