AK: Replace converting to and from UTF-16 with simdutf

The one behavior difference is that we will now actually fail on invalid
code units with Utf16View::to_utf8(AllowInvalidCodeUnits::No). It was
arguably a bug that this wasn't already the case.
This commit is contained in:
Timothy Flynn 2024-07-16 16:05:46 -04:00 committed by Andreas Kling
commit 0c14a9417a
Notes: sideshowbarker 2024-07-18 23:45:58 +09:00
4 changed files with 81 additions and 23 deletions

View file

@ -63,7 +63,7 @@ TEST_CASE(encode_utf8)
auto encoded = Array { (u16)0xd83d };
Utf16View view { encoded };
EXPECT_EQ(MUST(view.to_utf8(Utf16View::AllowInvalidCodeUnits::Yes)), "\xed\xa0\xbd"sv);
EXPECT_EQ(MUST(view.to_utf8(Utf16View::AllowInvalidCodeUnits::No)), "\ufffd"sv);
EXPECT(view.to_utf8(Utf16View::AllowInvalidCodeUnits::No).is_error());
}
}
@ -307,7 +307,7 @@ TEST_CASE(substring_view)
EXPECT(view.length_in_code_units() == 1);
EXPECT_EQ(MUST(view.to_utf8(Utf16View::AllowInvalidCodeUnits::Yes)), "\xed\xa0\xbd"sv);
EXPECT_EQ(MUST(view.to_utf8(Utf16View::AllowInvalidCodeUnits::No)), "\ufffd"sv);
EXPECT(view.to_utf8(Utf16View::AllowInvalidCodeUnits::No).is_error());
}
}