26 using char_type = char32_t;
28 [[nodiscard]] std::endian guess_endian(
void const *ptr,
size_t size, std::endian endian)
const noexcept
31 auto *ptr_ =
static_cast<uint8_t
const *
>(ptr);
35 return std::endian::native;
38 if (ptr_[0] == 0x00 and ptr_[1] == 0x00 and ptr_[2] == 0xfe and ptr_[3] == 0xff) {
39 return std::endian::big;
40 }
else if (ptr_[0] == 0xff and ptr_[1] == 0xfe and ptr_[2] == 0x00 and ptr_[3] == 0x00) {
41 return std::endian::little;
46 for (
auto i = 0; i != size; ++i) {
47 count[i % 4] = ptr_[i] == 0 ? count[i % 4] + 1 : 0;
49 if (i % 4 == 0 and count[0] >= 8) {
50 return std::endian::big;
51 }
else if (i % 4 == 3 and count[3] >= 8) {
52 return std::endian::little;
60 template<
typename It,
typename EndIt>
65 if (
auto cu = *it++; cu < 0xd800) {
68 }
else if (cu < 0xe000) {
70 return {0xfffd,
false};
72 }
else if (cu < 0x11'0000) {
77 return {0xfffd,
false};
84 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
85 return {uint8_t{1},
true};
89 constexpr void write(
char32_t code_point, It& dst)
const noexcept
92 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
97#if defined(HI_HAS_SSE2)
99 hi_force_inline __m128i read_ascii_chunk16(It it)
const noexcept
110 hilet lo = _mm_packs_epi32(c0, c1);
111 hilet hi = _mm_packs_epi32(c2, c3);
119 hilet sign_lo = _mm_srai_epi16(lo, 15);
120 hilet sign_hi = _mm_srai_epi16(
hi, 15);
121 hilet sign = _mm_packs_epi16(sign_lo, sign_hi);
126 hilet chunk = _mm_packus_epi16(lo,
hi);
131 return _mm_or_si128(chunk, sign);
134 template<
typename It>
135 hi_force_inline
void write_ascii_chunk16(__m128i chunk, It dst)
const noexcept
138 hilet lo = _mm_unpacklo_epi8(chunk,
zero);
146 _mm_storeu_si128(
reinterpret_cast<__m128i *
>(
std::addressof(*dst)), c0);
148 _mm_storeu_si128(
reinterpret_cast<__m128i *
>(
std::addressof(*dst)), c1);
150 _mm_storeu_si128(
reinterpret_cast<__m128i *
>(
std::addressof(*dst)), c2);
152 _mm_storeu_si128(
reinterpret_cast<__m128i *
>(
std::addressof(*dst)), c3);
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#define hi_assert_not_null(x,...)
Assert if an expression is not nullptr.
Definition assert.hpp:238
#define hi_axiom_not_null(expression,...)
Assert if an expression is not nullptr.
Definition assert.hpp:272