mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 13:19:05 +00:00
AK: Add Utf8View::code_point_offset_of()
This commit is contained in:
parent
cea9012b5b
commit
6f926e6977
Notes:
github-actions[bot]
2025-06-13 13:10:13 +00:00
Author: https://github.com/gmta
Commit: 6f926e6977
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5067
Reviewed-by: https://github.com/tcl3
Reviewed-by: https://github.com/trflynn89
3 changed files with 27 additions and 0 deletions
|
@ -30,6 +30,18 @@ Utf8CodePointIterator Utf8View::iterator_at_byte_offset_without_validation(size_
|
|||
return Utf8CodePointIterator { reinterpret_cast<u8 const*>(m_string.characters_without_null_termination()) + byte_offset, m_string.length() - byte_offset };
|
||||
}
|
||||
|
||||
size_t Utf8View::code_point_offset_of(size_t byte_offset) const
|
||||
{
|
||||
VERIFY(byte_offset < byte_length());
|
||||
size_t code_point_offset = 0;
|
||||
for (auto it = begin(); !it.done(); ++it) {
|
||||
if (it.m_ptr > begin_ptr() + byte_offset)
|
||||
break;
|
||||
++code_point_offset;
|
||||
}
|
||||
return code_point_offset - 1;
|
||||
}
|
||||
|
||||
size_t Utf8View::byte_offset_of(size_t code_point_offset) const
|
||||
{
|
||||
size_t byte_offset = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue