25 using char_type = char16_t;
27 [[nodiscard]] std::endian guess_endian(
void const *ptr,
size_t size, std::endian endian)
const noexcept
30 auto *ptr_ =
static_cast<uint8_t
const *
>(ptr);
34 return std::endian::native;
37 if (ptr_[0] == 0xfe and ptr_[1] == 0xff) {
38 return std::endian::big;
39 }
else if (ptr_[0] == 0xff and ptr_[1] == 0xfe) {
40 return std::endian::little;
45 for (
auto i = 0; i != size; ++i) {
46 count[i % 2] = ptr_[i] == 0 ? count[i % 2] + 1 : 0;
47 if (count[i % 2] >= 8) {
48 return i % 2 == 0 ? std::endian::big : std::endian::little;
56 template<
typename It,
typename EndIt>
61 if (
auto cu = *it++; cu < 0xd800) {
62 return {char_cast<char32_t>(cu),
true};
64 }
else if (cu < 0xdc00) {
67 return {0xfffd,
false};
70 auto cp = char_cast<char32_t>(cu & 0x03ff);
72 if (cu >= 0xdc00 and cu < 0xe000) {
81 return {0xfffd,
false};
85 }
else if (cu < 0xe000) {
87 return {0xfffd,
false};
97 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
98 return {truncate<uint8_t>((code_point >= 0x01'0000) + 1),
true};
101 template<
typename It>
102 constexpr void write(
char32_t code_point, It& dst)
const noexcept
105 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
107 if (
hilet tmp = truncate<int32_t>(code_point) - 0x1'0000; tmp >= 0) {
108 *dst++ = char_cast<char16_t>((tmp >> 10) + 0xd800);
109 *dst++ = char_cast<char16_t>((tmp & 0x3ff) + 0xdc00);
112 *dst++ = char_cast<char16_t>(code_point);
116#if defined(HI_HAS_SSE2)
117 template<
typename It>
118 hi_force_inline __m128i read_ascii_chunk16(It it)
const noexcept
131 hilet sign_lo = _mm_srai_epi16(lo, 15);
132 hilet sign_hi = _mm_srai_epi16(
hi, 15);
133 hilet sign = _mm_packs_epi16(sign_lo, sign_hi);
138 hilet chunk = _mm_packus_epi16(lo,
hi);
143 return _mm_or_si128(chunk, sign);
146 template<
typename It>
147 hi_force_inline
void write_ascii_chunk16(__m128i chunk, It dst)
const noexcept
149 hilet zero = _mm_setzero_si128();
150 hilet lo = _mm_unpacklo_epi8(chunk, zero);
151 hilet hi = _mm_unpackhi_epi8(chunk, zero);
153 _mm_storeu_si128(
reinterpret_cast<__m128i *
>(
std::addressof(*dst)), lo);
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238
#define hi_assert_not_null(x,...)
Assert if an expression is not nullptr.
Definition assert.hpp:223
#define hi_axiom_not_null(expression,...)
Assert if an expression is not nullptr.
Definition assert.hpp:257