Browse Source

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.
Timothy Flynn 3 years ago
parent
commit
ada4bab405
1 changed files with 5 additions and 5 deletions
  1. 5 5
      Userland/Libraries/LibUnicode/Locale.cpp

+ 5 - 5
Userland/Libraries/LibUnicode/Locale.cpp

@@ -13,6 +13,7 @@
 #include <LibUnicode/Locale.h>
 #include <LibUnicode/Locale.h>
 
 
 #if ENABLE_UNICODE_DATA
 #if ENABLE_UNICODE_DATA
+#    include <LibUnicode/UnicodeData.h>
 #    include <LibUnicode/UnicodeLocale.h>
 #    include <LibUnicode/UnicodeLocale.h>
 #    include <LibUnicode/UnicodeNumberFormat.h>
 #    include <LibUnicode/UnicodeNumberFormat.h>
 #endif
 #endif
@@ -998,6 +999,7 @@ Optional<NumberFormat> select_currency_unit_pattern(StringView locale, StringVie
 // https://www.unicode.org/reports/tr35/tr35-numbers.html#Currencies
 // https://www.unicode.org/reports/tr35/tr35-numbers.html#Currencies
 String create_currency_format_pattern(StringView currency_display, StringView base_pattern)
 String create_currency_format_pattern(StringView currency_display, StringView base_pattern)
 {
 {
+#if ENABLE_UNICODE_DATA
     constexpr auto number_key = "{number}"sv;
     constexpr auto number_key = "{number}"sv;
     constexpr auto currency_key = "{currency}"sv;
     constexpr auto currency_key = "{currency}"sv;
     constexpr auto spacing = "\u00A0"sv; // No-Break Space (NBSP)
     constexpr auto spacing = "\u00A0"sv; // No-Break Space (NBSP)
@@ -1008,9 +1010,6 @@ String create_currency_format_pattern(StringView currency_display, StringView ba
     auto currency_index = base_pattern.find(currency_key);
     auto currency_index = base_pattern.find(currency_key);
     VERIFY(currency_index.has_value());
     VERIFY(currency_index.has_value());
 
 
-    static auto symbol_category = general_category_from_string("Symbol"sv);
-    VERIFY(symbol_category.has_value()); // This shouldn't be reached if Unicode generation is disabled.
-
     Utf8View utf8_currency_display { currency_display };
     Utf8View utf8_currency_display { currency_display };
     Optional<String> currency_display_with_spacing;
     Optional<String> currency_display_with_spacing;
 
 
@@ -1018,7 +1017,7 @@ String create_currency_format_pattern(StringView currency_display, StringView ba
         if (!base_pattern.substring_view(0, *currency_index).ends_with(spacing)) {
         if (!base_pattern.substring_view(0, *currency_index).ends_with(spacing)) {
             u32 first_currency_code_point = *utf8_currency_display.begin();
             u32 first_currency_code_point = *utf8_currency_display.begin();
 
 
-            if (!code_point_has_general_category(first_currency_code_point, *symbol_category))
+            if (!code_point_has_general_category(first_currency_code_point, GeneralCategory::Symbol))
                 currency_display_with_spacing = String::formatted("{}{}", spacing, currency_display);
                 currency_display_with_spacing = String::formatted("{}{}", spacing, currency_display);
         }
         }
     } else {
     } else {
@@ -1027,13 +1026,14 @@ String create_currency_format_pattern(StringView currency_display, StringView ba
             for (auto it = utf8_currency_display.begin(); it != utf8_currency_display.end(); ++it)
             for (auto it = utf8_currency_display.begin(); it != utf8_currency_display.end(); ++it)
                 last_currency_code_point = *it;
                 last_currency_code_point = *it;
 
 
-            if (!code_point_has_general_category(last_currency_code_point, *symbol_category))
+            if (!code_point_has_general_category(last_currency_code_point, GeneralCategory::Symbol))
                 currency_display_with_spacing = String::formatted("{}{}", currency_display, spacing);
                 currency_display_with_spacing = String::formatted("{}{}", currency_display, spacing);
         }
         }
     }
     }
 
 
     if (currency_display_with_spacing.has_value())
     if (currency_display_with_spacing.has_value())
         return base_pattern.replace(currency_key, *currency_display_with_spacing);
         return base_pattern.replace(currency_key, *currency_display_with_spacing);
+#endif
 
 
     return base_pattern.replace(currency_key, currency_display);
     return base_pattern.replace(currency_key, currency_display);
 }
 }