1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:07:46 +00:00

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
5 changed files with 50 additions and 48 deletions

View file

@ -18,6 +18,15 @@ enum class PluralForm {
Ordinal,
};
enum class PluralCategory : u8 {
Other,
Zero,
One,
Two,
Few,
Many,
};
// https://unicode.org/reports/tr35/tr35-numbers.html#Plural_Operand_Meanings
struct PluralOperands {
static constexpr StringView symbol_to_variable_name(char symbol)
@ -57,8 +66,44 @@ struct PluralOperands {
PluralForm plural_form_from_string(StringView plural_form);
StringView plural_form_to_string(PluralForm plural_form);
Optional<PluralCategory> plural_category_from_string(StringView category);
StringView plural_category_to_string(PluralCategory category);
// NOTE: This must be defined inline to be callable from the code generators.
constexpr PluralCategory plural_category_from_string(StringView category)
{
if (category == "other"sv)
return PluralCategory::Other;
if (category == "zero"sv)
return PluralCategory::Zero;
if (category == "one"sv)
return PluralCategory::One;
if (category == "two"sv)
return PluralCategory::Two;
if (category == "few"sv)
return PluralCategory::Few;
if (category == "many"sv)
return PluralCategory::Many;
VERIFY_NOT_REACHED();
}
// NOTE: This must be defined inline to be callable from the code generators.
constexpr StringView plural_category_to_string(PluralCategory category)
{
switch (category) {
case PluralCategory::Other:
return "other"sv;
case PluralCategory::Zero:
return "zero"sv;
case PluralCategory::One:
return "one"sv;
case PluralCategory::Two:
return "two"sv;
case PluralCategory::Few:
return "few"sv;
case PluralCategory::Many:
return "many"sv;
}
VERIFY_NOT_REACHED();
}
PluralCategory determine_plural_category(StringView locale, PluralForm form, PluralOperands operands);
Span<PluralCategory const> available_plural_categories(StringView locale, PluralForm form);