mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
AK: Add a way to get the number of valid bytes in a Utf8View
This commit is contained in:
committed by
Andreas Kling
parent
07c765e258
commit
a4e0b585fe
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user