LibJS+LibUnicode: Do not generate the PluralCategory enum

The PluralCategory enum is currently generated for plural rules. Instead
of generating it, this moves the enum to the public LibUnicode header.
While it was nice to auto-discover these values, they are well defined
by TR-35, and we will need their values from within the number format
code generator (which can't rely on the plural rules generator having
run yet). Further, number format will require additional values in the
enum that plural rules doesn't know about.
This commit is contained in:
Timothy Flynn 2022-07-08 07:52:54 -04:00 committed by Linus Groh
parent 9369610bf4
commit cc5c707649
Notes: sideshowbarker 2024-07-17 09:36:17 +09:00
5 changed files with 50 additions and 48 deletions

View file

@ -207,7 +207,6 @@ struct UnicodeLocaleData {
UniqueStringStorage<StringIndexType> unique_strings;
HashMap<String, Locale> locales;
Vector<String> categories;
};
static Relation parse_relation(StringView relation)
@ -342,9 +341,6 @@ static ErrorOr<void> parse_plural_rules(String core_supplemental_path, StringVie
auto category = key.substring_view(rule_prefix.length());
parse_condition(category, condition.as_string(), locale->rules_for_form(form));
if (!locale_data.categories.contains_slow(category))
locale_data.categories.append(category);
});
});
});
@ -385,7 +381,7 @@ static ErrorOr<void> parse_all_locales(String core_path, String locale_names_pat
return {};
}
static ErrorOr<void> generate_unicode_locale_header(Core::Stream::BufferedFile& file, UnicodeLocaleData& locale_data)
static ErrorOr<void> generate_unicode_locale_header(Core::Stream::BufferedFile& file, UnicodeLocaleData&)
{
StringBuilder builder;
SourceGenerator generator { builder };
@ -398,8 +394,6 @@ static ErrorOr<void> generate_unicode_locale_header(Core::Stream::BufferedFile&
namespace Unicode {
)~~~");
generate_enum(generator, format_identifier, "PluralCategory"sv, {}, locale_data.categories);
generator.append(R"~~~(
}
)~~~");
@ -418,8 +412,6 @@ static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::Buffer
generator.append(R"~~~(
#include <AK/Array.h>
#include <AK/BinarySearch.h>
#include <AK/StringView.h>
#include <LibUnicode/Locale.h>
#include <LibUnicode/PluralRules.h>
#include <LibUnicode/UnicodeLocale.h>
@ -437,17 +429,6 @@ static PluralCategory default_category(PluralOperands)
)~~~");
auto append_string_conversions = [&](StringView enum_title, StringView enum_snake, auto const& values) {
HashValueMap<String> hashes;
hashes.ensure_capacity(values.size());
for (auto const& value : values)
hashes.set(value.hash(), format_identifier(enum_title, value));
generate_value_from_string(generator, "{}_from_string"sv, enum_title, enum_snake, move(hashes));
generate_value_to_string(generator, "{}_to_string"sv, enum_title, enum_snake, format_identifier, values);
};
auto append_rules = [&](auto form, auto const& locale, auto const& rules) {
if (rules.is_empty())
return;
@ -518,8 +499,6 @@ static constexpr Array<PluralCategory, @size@> @name@ { { PluralCategory::Other)
generator.append("} };");
};
append_string_conversions("PluralCategory"sv, "plural_category"sv, locale_data.categories);
for (auto [locale, rules] : locale_data.locales) {
append_rules("cardinal"sv, locale, rules.cardinal_rules);
append_rules("ordinal"sv, locale, rules.ordinal_rules);