mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-26 04:35:41 +03:00
AK: Add a Utf16View::code_unit_offset_of(Utf16CodePointIterator) helper
This helper can be used to used to retrieve the code unit offset of an active Utf16CodePointIterator efficiently.
This commit is contained in:
parent
2d50c08f34
commit
44e8c05c67
Notes:
sideshowbarker
2024-07-18 02:47:59 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/44e8c05c675 Pull-request: https://github.com/SerenityOS/serenity/pull/12229 Reviewed-by: https://github.com/trflynn89 ✅
@ -165,6 +165,14 @@ size_t Utf16View::code_unit_offset_of(size_t code_point_offset) const
|
|||||||
return code_unit_offset;
|
return code_unit_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t Utf16View::code_unit_offset_of(Utf16CodePointIterator const& it) const
|
||||||
|
{
|
||||||
|
VERIFY(it.m_ptr >= begin_ptr());
|
||||||
|
VERIFY(it.m_ptr <= end_ptr());
|
||||||
|
|
||||||
|
return it.m_ptr - begin_ptr();
|
||||||
|
}
|
||||||
|
|
||||||
Utf16View Utf16View::substring_view(size_t code_unit_offset, size_t code_unit_length) const
|
Utf16View Utf16View::substring_view(size_t code_unit_offset, size_t code_unit_length) const
|
||||||
{
|
{
|
||||||
VERIFY(!Checked<size_t>::addition_would_overflow(code_unit_offset, code_unit_length));
|
VERIFY(!Checked<size_t>::addition_would_overflow(code_unit_offset, code_unit_length));
|
||||||
|
@ -93,6 +93,7 @@ public:
|
|||||||
|
|
||||||
size_t code_point_offset_of(size_t code_unit_offset) const;
|
size_t code_point_offset_of(size_t code_unit_offset) const;
|
||||||
size_t code_unit_offset_of(size_t code_point_offset) const;
|
size_t code_unit_offset_of(size_t code_point_offset) const;
|
||||||
|
size_t code_unit_offset_of(Utf16CodePointIterator const&) const;
|
||||||
|
|
||||||
Utf16View substring_view(size_t code_unit_offset, size_t code_unit_length) const;
|
Utf16View substring_view(size_t code_unit_offset, size_t code_unit_length) const;
|
||||||
Utf16View substring_view(size_t code_unit_offset) const { return substring_view(code_unit_offset, length_in_code_units() - code_unit_offset); }
|
Utf16View substring_view(size_t code_unit_offset) const { return substring_view(code_unit_offset, length_in_code_units() - code_unit_offset); }
|
||||||
|
Loading…
Reference in New Issue
Block a user