Skip to content

Commit ada4bab

Browse files
trflynn89linusg
authored andcommitted
LibUnicode: Remove GeneralCategory::Symbol string lookup
When I originally wrote this method, I had it in LibJS, where we can't refer to the GeneralCategory enumeration directly. This is a big TODO, anyone outside of LibUnicode can't assume the generated enumerations exist and must get these values by string lookup. But this function ended up living in LibUnicode, who can reference the enumeration.
1 parent dbe70e7 commit ada4bab

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Userland/Libraries/LibUnicode/Locale.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <LibUnicode/Locale.h>
1414

1515
#if ENABLE_UNICODE_DATA
16+
# include <LibUnicode/UnicodeData.h>
1617
# include <LibUnicode/UnicodeLocale.h>
1718
# include <LibUnicode/UnicodeNumberFormat.h>
1819
#endif
@@ -998,6 +999,7 @@ Optional<NumberFormat> select_currency_unit_pattern(StringView locale, StringVie
998999
// https://www.unicode.org/reports/tr35/tr35-numbers.html#Currencies
9991000
String create_currency_format_pattern(StringView currency_display, StringView base_pattern)
10001001
{
1002+
#if ENABLE_UNICODE_DATA
10011003
constexpr auto number_key = "{number}"sv;
10021004
constexpr auto currency_key = "{currency}"sv;
10031005
constexpr auto spacing = "\u00A0"sv; // No-Break Space (NBSP)
@@ -1008,17 +1010,14 @@ String create_currency_format_pattern(StringView currency_display, StringView ba
10081010
auto currency_index = base_pattern.find(currency_key);
10091011
VERIFY(currency_index.has_value());
10101012

1011-
static auto symbol_category = general_category_from_string("Symbol"sv);
1012-
VERIFY(symbol_category.has_value()); // This shouldn't be reached if Unicode generation is disabled.
1013-
10141013
Utf8View utf8_currency_display { currency_display };
10151014
Optional<String> currency_display_with_spacing;
10161015

10171016
if (*number_index < *currency_index) {
10181017
if (!base_pattern.substring_view(0, *currency_index).ends_with(spacing)) {
10191018
u32 first_currency_code_point = *utf8_currency_display.begin();
10201019

1021-
if (!code_point_has_general_category(first_currency_code_point, *symbol_category))
1020+
if (!code_point_has_general_category(first_currency_code_point, GeneralCategory::Symbol))
10221021
currency_display_with_spacing = String::formatted("{}{}", spacing, currency_display);
10231022
}
10241023
} else {
@@ -1027,13 +1026,14 @@ String create_currency_format_pattern(StringView currency_display, StringView ba
10271026
for (auto it = utf8_currency_display.begin(); it != utf8_currency_display.end(); ++it)
10281027
last_currency_code_point = *it;
10291028

1030-
if (!code_point_has_general_category(last_currency_code_point, *symbol_category))
1029+
if (!code_point_has_general_category(last_currency_code_point, GeneralCategory::Symbol))
10311030
currency_display_with_spacing = String::formatted("{}{}", currency_display, spacing);
10321031
}
10331032
}
10341033

10351034
if (currency_display_with_spacing.has_value())
10361035
return base_pattern.replace(currency_key, *currency_display_with_spacing);
1036+
#endif
10371037

10381038
return base_pattern.replace(currency_key, currency_display);
10391039
}

0 commit comments

Comments
 (0)