mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:47:34 +00:00
AK: Add Utf8View::iterator_at_byte_offset_without_validation()
Unlike iterator_at_byte_offset(), this function assumes the provided byte offset is a valid offset into the UTF-8 character stream. This avoids walking the stream from the start.
This commit is contained in:
parent
45e22dafb3
commit
e7ba03ddd1
2 changed files with 7 additions and 0 deletions
|
@ -24,6 +24,11 @@ Utf8CodePointIterator Utf8View::iterator_at_byte_offset(size_t byte_offset) cons
|
||||||
return end();
|
return end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utf8CodePointIterator Utf8View::iterator_at_byte_offset_without_validation(size_t byte_offset) const
|
||||||
|
{
|
||||||
|
return Utf8CodePointIterator { reinterpret_cast<u8 const*>(m_string.characters_without_null_termination()) + byte_offset, m_string.length() - byte_offset };
|
||||||
|
}
|
||||||
|
|
||||||
size_t Utf8View::byte_offset_of(Utf8CodePointIterator const& it) const
|
size_t Utf8View::byte_offset_of(Utf8CodePointIterator const& it) const
|
||||||
{
|
{
|
||||||
VERIFY(it.m_ptr >= begin_ptr());
|
VERIFY(it.m_ptr >= begin_ptr());
|
||||||
|
|
|
@ -80,6 +80,8 @@ public:
|
||||||
Utf8CodePointIterator end() const { return { end_ptr(), 0 }; }
|
Utf8CodePointIterator end() const { return { end_ptr(), 0 }; }
|
||||||
Utf8CodePointIterator iterator_at_byte_offset(size_t) const;
|
Utf8CodePointIterator iterator_at_byte_offset(size_t) const;
|
||||||
|
|
||||||
|
Utf8CodePointIterator iterator_at_byte_offset_without_validation(size_t) const;
|
||||||
|
|
||||||
unsigned char const* bytes() const { return begin_ptr(); }
|
unsigned char const* bytes() const { return begin_ptr(); }
|
||||||
size_t byte_length() const { return m_string.length(); }
|
size_t byte_length() const { return m_string.length(); }
|
||||||
size_t byte_offset_of(Utf8CodePointIterator const&) const;
|
size_t byte_offset_of(Utf8CodePointIterator const&) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue