17 for (
auto byte : input) {
18 decode_byte(result,
byte);
27 if (m_pending_code_units > 0) {
34 constexpr static auto default_lower_bound =
u8(0x80);
35 constexpr static auto default_upper_bound =
u8(0xBF);
37 constexpr void decode_byte(
String& output,
byte input) {
38 if (m_pending_code_units == 0) {
39 decode_first_byte(output, input);
43 auto input_u8 = di::to_integer<u8>(input);
46 decode_first_byte(output, input);
50 m_lower_bound = default_lower_bound;
51 m_upper_bound = default_upper_bound;
52 m_pending_code_point <<= 6;
53 m_pending_code_point |= di::to_integer<u32>(input &
byte(0b0011'1111));
54 if (--m_pending_code_units == 0) {
55 output_code_point(output, m_pending_code_point);
59 constexpr void decode_first_byte(
String& output,
byte input) {
62 auto input_u8 = di::to_integer<u8>(input);
64 output_code_point(output, di::to_integer<u32>(input));
66 m_pending_code_units = 1;
67 m_pending_code_point = di::to_integer<u32>(input &
byte(0x1F));
69 m_pending_code_units = 2;
70 if (input ==
byte(0xE0)) {
72 }
else if (input ==
byte(0xED)) {
75 m_pending_code_point = di::to_integer<u32>(input &
byte(0x0F));
77 m_pending_code_units = 3;
78 if (input ==
byte(0xF0)) {
80 }
else if (input ==
byte(0xF4)) {
83 m_pending_code_point = di::to_integer<u32>(input &
byte(0x07));
89 constexpr void output_code_point(
String& output,
c32 code_point) {
90 output.push_back(code_point);
96 u8 m_pending_code_units { 0 };
97 u32 m_pending_code_point { 0 };
98 u8 m_lower_bound { default_lower_bound };
99 u8 m_upper_bound { default_upper_bound };