mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-24 00:49:46 +00:00
AK: Compute Utf16View::code_point_offset_of correctly
There were a couple of issues here, including the following computation
could actually overflow to NumericLimits<size_t>::max():
code_unit_offset -= it.length_in_code_units();
This commit is contained in:
parent
f595e47c1f
commit
ad7ac679fd
Notes:
github-actions[bot]
2025-07-22 15:18:55 +00:00
Author: https://github.com/trflynn89
Commit: ad7ac679fd
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5564
Reviewed-by: https://github.com/gmta ✅
3 changed files with 26 additions and 5 deletions
|
|
@ -402,6 +402,26 @@ TEST_CASE(code_unit_offset_of)
|
|||
EXPECT_EQ(view.code_unit_offset_of(11), 13uz);
|
||||
}
|
||||
|
||||
TEST_CASE(code_point_offset_of)
|
||||
{
|
||||
Utf16View view { u"😂 foo 😀 bar"sv };
|
||||
|
||||
EXPECT_EQ(view.code_point_offset_of(0), 0uz);
|
||||
EXPECT_EQ(view.code_point_offset_of(1), 0uz);
|
||||
EXPECT_EQ(view.code_point_offset_of(2), 1uz);
|
||||
EXPECT_EQ(view.code_point_offset_of(3), 2uz);
|
||||
EXPECT_EQ(view.code_point_offset_of(4), 3uz);
|
||||
EXPECT_EQ(view.code_point_offset_of(5), 4uz);
|
||||
EXPECT_EQ(view.code_point_offset_of(6), 5uz);
|
||||
EXPECT_EQ(view.code_point_offset_of(7), 6uz);
|
||||
EXPECT_EQ(view.code_point_offset_of(8), 6uz);
|
||||
EXPECT_EQ(view.code_point_offset_of(9), 7uz);
|
||||
EXPECT_EQ(view.code_point_offset_of(10), 8uz);
|
||||
EXPECT_EQ(view.code_point_offset_of(11), 9uz);
|
||||
EXPECT_EQ(view.code_point_offset_of(12), 10uz);
|
||||
EXPECT_EQ(view.code_point_offset_of(13), 11uz);
|
||||
}
|
||||
|
||||
TEST_CASE(replace)
|
||||
{
|
||||
auto result = u""sv.replace({}, {}, ReplaceMode::FirstOnly);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue