1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:08:11 +00:00

LibUnicode: Handle all space code points when creating currency patterns

Previously, we were checking if the code point immediately before/after
the {currency} key was U+00A0 (non-breaking space). Instead, to handle
other spacing code points, we must check if the surrounding code point
has the separator general category.
This commit is contained in:
Timothy Flynn 2021-11-13 10:03:17 -05:00 committed by Linus Groh
parent ada4bab405
commit 0c9711efba

View file

@ -1013,18 +1013,30 @@ String create_currency_format_pattern(StringView currency_display, StringView ba
Utf8View utf8_currency_display { currency_display };
Optional<String> currency_display_with_spacing;
auto last_code_point = [](StringView string) {
Utf8View utf8_string { string };
u32 code_point = 0;
for (auto it = utf8_string.begin(); it != utf8_string.end(); ++it)
code_point = *it;
return code_point;
};
if (*number_index < *currency_index) {
if (!base_pattern.substring_view(0, *currency_index).ends_with(spacing)) {
u32 last_pattern_code_point = last_code_point(base_pattern.substring_view(0, *currency_index));
if (!code_point_has_general_category(last_pattern_code_point, GeneralCategory::Separator)) {
u32 first_currency_code_point = *utf8_currency_display.begin();
if (!code_point_has_general_category(first_currency_code_point, GeneralCategory::Symbol))
currency_display_with_spacing = String::formatted("{}{}", spacing, currency_display);
}
} else {
if (!base_pattern.substring_view(0, *number_index).ends_with(spacing)) {
u32 last_currency_code_point = 0;
for (auto it = utf8_currency_display.begin(); it != utf8_currency_display.end(); ++it)
last_currency_code_point = *it;
u32 last_pattern_code_point = last_code_point(base_pattern.substring_view(0, *number_index));
if (!code_point_has_general_category(last_pattern_code_point, GeneralCategory::Separator)) {
u32 last_currency_code_point = last_code_point(currency_display);
if (!code_point_has_general_category(last_currency_code_point, GeneralCategory::Symbol))
currency_display_with_spacing = String::formatted("{}{}", currency_display, spacing);