mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:17:45 +00:00
AK: Add a way to get the number of valid bytes in a Utf8View
This commit is contained in:
parent
07c765e258
commit
a4e0b585fe
3 changed files with 24 additions and 9 deletions
|
@ -111,8 +111,9 @@ static inline bool decode_first_byte(
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Utf8View::validate() const
|
||||
bool Utf8View::validate(size_t& valid_bytes) const
|
||||
{
|
||||
valid_bytes = 0;
|
||||
for (auto ptr = begin_ptr(); ptr < end_ptr(); ptr++) {
|
||||
int codepoint_length_in_bytes;
|
||||
u32 value;
|
||||
|
@ -127,6 +128,8 @@ bool Utf8View::validate() const
|
|||
if (*ptr >> 6 != 2)
|
||||
return false;
|
||||
}
|
||||
|
||||
valid_bytes += codepoint_length_in_bytes;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue