|
2 | 2 | #include <core/memory.h> |
3 | 3 | namespace hud |
4 | 4 | { |
5 | | - // [[nodiscard]] constexpr bool cstring::is_valid_utf8(const char8 *string, usize byte_count) noexcept |
6 | | - // { |
7 | | - // u64 pos = 0; |
8 | | - // u32 code_point = 0; |
9 | | - // while (pos < byte_count) { |
10 | | - // // check of the next 16 bytes are ascii. |
11 | | - // u64 next_pos = pos + 16; |
12 | | - // if (next_pos <= byte_count) { // if it is safe to read 16 more bytes, check that they are ascii |
13 | | - // u64 v1 = hud::memory::unaligned_load64(string + pos); |
14 | | - // // std::memcpy(&v1, string + pos, sizeof(u64)); |
15 | | - // u64 v2 = hud::memory::unaligned_load64(string + pos + sizeof(u64)); |
16 | | - // // std::memcpy(&v2, string + pos + sizeof(u64), sizeof(u64)); |
17 | | - // u64 v {v1 | v2}; |
18 | | - // if ((v & 0x8080808080808080) == 0) { |
19 | | - // pos = next_pos; |
20 | | - // continue; |
21 | | - // } |
22 | | - // } |
23 | | - // unsigned char byte = string[pos]; |
24 | 5 |
|
25 | | - // while (byte < 0b10000000) { |
26 | | - // if (++pos == byte_count) { |
27 | | - // return true; |
28 | | - // } |
29 | | - // byte = string[pos]; |
30 | | - // } |
31 | | - |
32 | | - // if ((byte & 0b11100000) == 0b11000000) { |
33 | | - // next_pos = pos + 2; |
34 | | - // if (next_pos > byte_count) { |
35 | | - // return false; |
36 | | - // } |
37 | | - // if ((string[pos + 1] & 0b11000000) != 0b10000000) { |
38 | | - // return false; |
39 | | - // } |
40 | | - // // range check |
41 | | - // code_point = (byte & 0b00011111) << 6 | (string[pos + 1] & 0b00111111); |
42 | | - // if ((code_point < 0x80) || (0x7ff < code_point)) { |
43 | | - // return false; |
44 | | - // } |
45 | | - // } |
46 | | - // else if ((byte & 0b11110000) == 0b11100000) { |
47 | | - // next_pos = pos + 3; |
48 | | - // if (next_pos > byte_count) { |
49 | | - // return false; |
50 | | - // } |
51 | | - // if ((string[pos + 1] & 0b11000000) != 0b10000000) { |
52 | | - // return false; |
53 | | - // } |
54 | | - // if ((string[pos + 2] & 0b11000000) != 0b10000000) { |
55 | | - // return false; |
56 | | - // } |
57 | | - // // range check |
58 | | - // code_point = (byte & 0b00001111) << 12 | (string[pos + 1] & 0b00111111) << 6 | (string[pos + 2] & 0b00111111); |
59 | | - // if ((code_point < 0x800) || (0xffff < code_point) || (0xd7ff < code_point && code_point < 0xe000)) { |
60 | | - // return false; |
61 | | - // } |
62 | | - // } |
63 | | - // else if ((byte & 0b11111000) == 0b11110000) { // 0b11110000 |
64 | | - // next_pos = pos + 4; |
65 | | - // if (next_pos > byte_count) { |
66 | | - // return false; |
67 | | - // } |
68 | | - // if ((string[pos + 1] & 0b11000000) != 0b10000000) { |
69 | | - // return false; |
70 | | - // } |
71 | | - // if ((string[pos + 2] & 0b11000000) != 0b10000000) { |
72 | | - // return false; |
73 | | - // } |
74 | | - // if ((string[pos + 3] & 0b11000000) != 0b10000000) { |
75 | | - // return false; |
76 | | - // } |
77 | | - // // range check |
78 | | - // code_point = |
79 | | - // (byte & 0b00000111) << 18 | (string[pos + 1] & 0b00111111) << 12 | (string[pos + 2] & 0b00111111) << 6 | (string[pos + 3] & 0b00111111); |
80 | | - // if (code_point <= 0xffff || 0x10ffff < code_point) { |
81 | | - // return false; |
82 | | - // } |
83 | | - // } |
84 | | - // else { |
85 | | - // // we may have a continuation |
86 | | - // return false; |
87 | | - // } |
88 | | - // pos = next_pos; |
89 | | - // } |
90 | | - // return true; |
91 | | - // } |
92 | 6 | } // namespace hud |
0 commit comments