1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 19:17:35 +00:00

LibUnicode+LibJS+LibWeb: Propagate OOM from Unicode case transformations

This commit is contained in:
Timothy Flynn 2023-01-08 10:15:05 -05:00 committed by Linus Groh
parent 48474b0de6
commit 1ff29afc45
5 changed files with 91 additions and 91 deletions

View file

@ -221,7 +221,7 @@ u32 __attribute__((weak)) to_unicode_uppercase(u32 code_point)
return to_ascii_uppercase(code_point);
}
DeprecatedString to_unicode_lowercase_full(StringView string, [[maybe_unused]] Optional<StringView> locale)
ErrorOr<DeprecatedString> to_unicode_lowercase_full(StringView string, [[maybe_unused]] Optional<StringView> locale)
{
#if ENABLE_UNICODE_DATA
Utf8View view { string };
@ -236,12 +236,12 @@ DeprecatedString to_unicode_lowercase_full(StringView string, [[maybe_unused]] O
auto const* special_casing = find_matching_special_case(code_point, view, locale, index, byte_length);
if (!special_casing) {
builder.append_code_point(to_unicode_lowercase(code_point));
TRY(builder.try_append_code_point(to_unicode_lowercase(code_point)));
continue;
}
for (size_t i = 0; i < special_casing->lowercase_mapping_size; ++i)
builder.append_code_point(special_casing->lowercase_mapping[i]);
TRY(builder.try_append_code_point(special_casing->lowercase_mapping[i]));
}
return builder.build();
@ -250,7 +250,7 @@ DeprecatedString to_unicode_lowercase_full(StringView string, [[maybe_unused]] O
#endif
}
DeprecatedString to_unicode_uppercase_full(StringView string, [[maybe_unused]] Optional<StringView> locale)
ErrorOr<DeprecatedString> to_unicode_uppercase_full(StringView string, [[maybe_unused]] Optional<StringView> locale)
{
#if ENABLE_UNICODE_DATA
Utf8View view { string };
@ -265,12 +265,12 @@ DeprecatedString to_unicode_uppercase_full(StringView string, [[maybe_unused]] O
auto const* special_casing = find_matching_special_case(code_point, view, locale, index, byte_length);
if (!special_casing) {
builder.append_code_point(to_unicode_uppercase(code_point));
TRY(builder.try_append_code_point(to_unicode_uppercase(code_point)));
continue;
}
for (size_t i = 0; i < special_casing->uppercase_mapping_size; ++i)
builder.append_code_point(special_casing->uppercase_mapping[i]);
TRY(builder.try_append_code_point(special_casing->uppercase_mapping[i]));
}
return builder.build();

View file

@ -39,8 +39,8 @@ Span<SpecialCasing const* const> special_case_mapping(u32 code_point);
u32 to_unicode_lowercase(u32 code_point);
u32 to_unicode_uppercase(u32 code_point);
DeprecatedString to_unicode_lowercase_full(StringView, Optional<StringView> locale = {});
DeprecatedString to_unicode_uppercase_full(StringView, Optional<StringView> locale = {});
ErrorOr<DeprecatedString> to_unicode_lowercase_full(StringView, Optional<StringView> locale = {});
ErrorOr<DeprecatedString> to_unicode_uppercase_full(StringView, Optional<StringView> locale = {});
Optional<GeneralCategory> general_category_from_string(StringView);
bool code_point_has_general_category(u32 code_point, GeneralCategory general_category);