summaryrefslogtreecommitdiff
path: root/AK/Utf16View.cpp
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2022-01-31 18:13:32 +0200
committerIdan Horowitz <idan.horowitz@gmail.com>2022-01-31 21:05:04 +0200
commit44e8c05c675ea18b4583246ee0c572342cc19062 (patch)
treeb8fd478b05c2fe39157635763cd3b9289eef1525 /AK/Utf16View.cpp
parent2d50c08f34a827acbccb84abaf81ce8a9a4005bb (diff)
downloadserenity-44e8c05c675ea18b4583246ee0c572342cc19062.zip
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.
Diffstat (limited to 'AK/Utf16View.cpp')
-rw-r--r--AK/Utf16View.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/AK/Utf16View.cpp b/AK/Utf16View.cpp
index 03fe01d0d9..287b006bd3 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<size_t>::addition_would_overflow(code_unit_offset, code_unit_length));