mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
AK: Fix bounds assertions in Utf16View::iterator_offset
This commit is contained in:
parent
67723ef83c
commit
d9502505c2
|
|
@ -366,14 +366,14 @@ public:
|
|||
if (has_ascii_storage()) {
|
||||
VERIFY(it.has_ascii_storage());
|
||||
VERIFY(it.m_iterator.ascii >= m_string.ascii);
|
||||
VERIFY(it.m_iterator.ascii <= m_string.ascii);
|
||||
VERIFY(it.m_iterator.ascii <= m_string.ascii + length_in_code_units());
|
||||
|
||||
return it.m_iterator.ascii - m_string.ascii;
|
||||
}
|
||||
|
||||
VERIFY(!it.has_ascii_storage());
|
||||
VERIFY(it.m_iterator.utf16 >= m_string.utf16);
|
||||
VERIFY(it.m_iterator.utf16 <= m_string.utf16);
|
||||
VERIFY(it.m_iterator.utf16 <= m_string.utf16 + length_in_code_units());
|
||||
|
||||
return it.m_iterator.utf16 - m_string.utf16;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -495,6 +495,19 @@ TEST_CASE(code_point_offset_of)
|
|||
EXPECT_EQ(view.code_point_offset_of(13), 11uz);
|
||||
}
|
||||
|
||||
TEST_CASE(iterator_offset)
|
||||
{
|
||||
Utf16View view { u"😂 foo 😀 bar"sv };
|
||||
size_t expected_offset = 0;
|
||||
|
||||
for (auto it = view.begin(); it != view.end(); ++it) {
|
||||
EXPECT_EQ(view.iterator_offset(it), expected_offset);
|
||||
expected_offset += it.length_in_code_units();
|
||||
}
|
||||
|
||||
EXPECT_EQ(view.iterator_offset(view.end()), view.length_in_code_units());
|
||||
}
|
||||
|
||||
TEST_CASE(replace)
|
||||
{
|
||||
auto result = u""sv.replace({}, {}, ReplaceMode::FirstOnly);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user