10 template<
typename TString,
typename TOnCodepo
intFunc>
14 using CodePointInt = int;
15 auto to_byte = [](
char c)->std::byte {
return static_cast<std::byte
>(
c); };
17 constexpr
auto mask0 = std::byte{0b10000000}; constexpr
auto bit0 = std::byte{0b00000000};
18 constexpr
auto mask1 = std::byte{0b11000000}; constexpr
auto bit1 = std::byte{0b10000000};
19 constexpr
auto mask2 = std::byte{0b11100000}; constexpr
auto bit2 = std::byte{0b11000000};
20 constexpr
auto mask3 = std::byte{0b11110000}; constexpr
auto bit3 = std::byte{0b11100000};
21 constexpr
auto mask4 = std::byte{0b11111000}; constexpr
auto bit4 = std::byte{0b11110000};
23 unsigned int bits = 0;
24 std::vector<std::byte>
buffer;
28 const auto b = to_byte(
c);
31 if( (mask0 &
b) == bit0)
33 on_codepoint(std::to_integer<CodePointInt>(
b));
38 if((mask4 &
b) == bit4)
42 else if((mask3 &
b) == bit3)
46 else if((mask2 &
b) == bit2)
50 else if((mask1 &
b) == bit1)
57 DIE(
"Implementation error?");
64 if((mask1 &
b) != bit1)
77 ( std::to_integer<CodePointInt>(
buffer[0] & ~mask2) << 6) |
78 ( std::to_integer<CodePointInt>(
buffer[1] & ~mask1) << 0)
84 ( std::to_integer<CodePointInt>(
buffer[0] & ~mask3) << 12) |
85 ( std::to_integer<CodePointInt>(
buffer[1] & ~mask1) << 6 ) |
86 ( std::to_integer<CodePointInt>(
buffer[2] & ~mask1) << 0 )
92 ( std::to_integer<CodePointInt>(
buffer[0] & ~mask4) << 18) |
93 ( std::to_integer<CodePointInt>(
buffer[1] & ~mask1) << 12) |
94 ( std::to_integer<CodePointInt>(
buffer[2] & ~mask1) << 6 ) |
95 ( std::to_integer<CodePointInt>(
buffer[3] & ~mask1) << 0 )
bool calc_utf8_to_codepoints(const TString &string, TOnCodepointFunc on_codepoint)