diff --git a/AK/Utf16View.cpp b/AK/Utf16View.cpp index 03fe01d0d9f..287b006bd3c 100644 --- a/AK/Utf16View.cpp +++ b/AK/Utf16View.cpp @@ -165,6 +165,14 @@ size_t Utf16View::code_unit_offset_of(size_t code_point_offset) const 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 { VERIFY(!Checked::addition_would_overflow(code_unit_offset, code_unit_length)); diff --git a/AK/Utf16View.h b/AK/Utf16View.h index f6906714c48..3fb954b9528 100644 --- a/AK/Utf16View.h +++ b/AK/Utf16View.h @@ -93,6 +93,7 @@ public: 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(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) const { return substring_view(code_unit_offset, length_in_code_units() - code_unit_offset); }