1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:47:44 +00:00

AK+Everywhere: Make UTF-8 and UTF-32 to UTF-16 converters fallible

These could fail to allocate the underlying storage needed to store the
UTF-16 data. Propagate these errors.
This commit is contained in:
Timothy Flynn 2023-01-06 13:19:34 -05:00 committed by Linus Groh
parent d8044c5358
commit 1edb96376b
13 changed files with 46 additions and 35 deletions

View file

@ -14,7 +14,7 @@
TEST_CASE(decode_ascii)
{
auto string = AK::utf8_to_utf16("Hello World!11"sv);
auto string = MUST(AK::utf8_to_utf16("Hello World!11"sv));
Utf16View view { string };
size_t valid_code_units = 0;
@ -33,7 +33,7 @@ TEST_CASE(decode_ascii)
TEST_CASE(decode_utf8)
{
auto string = AK::utf8_to_utf16("Привет, мир! 😀 γειά σου κόσμος こんにちは世界"sv);
auto string = MUST(AK::utf8_to_utf16("Привет, мир! 😀 γειά σου κόσμος こんにちは世界"sv));
Utf16View view { string };
size_t valid_code_units = 0;
@ -54,7 +54,7 @@ TEST_CASE(encode_utf8)
{
{
DeprecatedString utf8_string("Привет, мир! 😀 γειά σου κόσμος こんにちは世界");
auto string = AK::utf8_to_utf16(utf8_string);
auto string = MUST(AK::utf8_to_utf16(utf8_string));
Utf16View view { string };
EXPECT_EQ(view.to_utf8(Utf16View::AllowInvalidCodeUnits::Yes), utf8_string);
EXPECT_EQ(view.to_utf8(Utf16View::AllowInvalidCodeUnits::No), utf8_string);
@ -91,7 +91,7 @@ TEST_CASE(decode_utf16)
TEST_CASE(iterate_utf16)
{
auto string = AK::utf8_to_utf16("Привет 😀"sv);
auto string = MUST(AK::utf8_to_utf16("Привет 😀"sv));
Utf16View view { string };
auto iterator = view.begin();
@ -263,7 +263,7 @@ TEST_CASE(decode_invalid_utf16)
TEST_CASE(substring_view)
{
auto string = AK::utf8_to_utf16("Привет 😀"sv);
auto string = MUST(AK::utf8_to_utf16("Привет 😀"sv));
{
Utf16View view { string };
view = view.substring_view(7, 2);