@@ -121,41 +121,13 @@ class Utf8View {
121
121
return m_length;
122
122
}
123
123
124
- constexpr bool validate (AllowSurrogates surrogates = AllowSurrogates::Yes) const
124
+ bool validate (AllowSurrogates allow_surrogates = AllowSurrogates::Yes) const
125
125
{
126
126
size_t valid_bytes = 0 ;
127
- return validate (valid_bytes, surrogates );
127
+ return validate (valid_bytes, allow_surrogates );
128
128
}
129
129
130
- constexpr bool validate (size_t & valid_bytes, AllowSurrogates surrogates = AllowSurrogates::Yes) const
131
- {
132
- valid_bytes = 0 ;
133
-
134
- for (auto it = m_string.begin (); it != m_string.end (); ++it) {
135
- auto [byte_length, code_point, is_valid] = decode_leading_byte (static_cast <u8 >(*it));
136
- if (!is_valid)
137
- return false ;
138
-
139
- for (size_t i = 1 ; i < byte_length; ++i) {
140
- if (++it == m_string.end ())
141
- return false ;
142
-
143
- auto [code_point_bits, is_valid] = decode_continuation_byte (static_cast <u8 >(*it));
144
- if (!is_valid)
145
- return false ;
146
-
147
- code_point <<= 6 ;
148
- code_point |= code_point_bits;
149
- }
150
-
151
- if (!is_valid_code_point (code_point, byte_length, surrogates))
152
- return false ;
153
-
154
- valid_bytes += byte_length;
155
- }
156
-
157
- return true ;
158
- }
130
+ bool validate (size_t & valid_bytes, AllowSurrogates allow_surrogates = AllowSurrogates::Yes) const ;
159
131
160
132
private:
161
133
friend class Utf8CodePointIterator ;
@@ -198,36 +170,6 @@ class Utf8View {
198
170
return { .is_valid = false };
199
171
}
200
172
201
- struct ContinuationByte {
202
- u32 code_point_bits { 0 };
203
- bool is_valid { false };
204
- };
205
-
206
- static constexpr ContinuationByte decode_continuation_byte (u8 byte)
207
- {
208
- constexpr u8 continuation_byte_encoding_bits = 0b1000'0000 ;
209
- constexpr u8 continuation_byte_encoding_mask = 0b1100'0000 ;
210
-
211
- if ((byte & continuation_byte_encoding_mask) == continuation_byte_encoding_bits) {
212
- byte &= ~continuation_byte_encoding_mask;
213
- return { byte, true };
214
- }
215
-
216
- return { .is_valid = false };
217
- }
218
-
219
- static constexpr bool is_valid_code_point (u32 code_point, size_t byte_length, AllowSurrogates surrogates = AllowSurrogates::Yes)
220
- {
221
- if (surrogates == AllowSurrogates::No && byte_length == 3 && code_point >= 0xD800 && code_point <= 0xDFFF )
222
- return false ;
223
- for (auto const & data : utf8_encoded_byte_data) {
224
- if (code_point >= data.first_code_point && code_point <= data.last_code_point )
225
- return byte_length == data.byte_length ;
226
- }
227
-
228
- return false ;
229
- }
230
-
231
173
StringView m_string;
232
174
mutable size_t m_length { 0 };
233
175
mutable bool m_have_length { false };
0 commit comments