From 670bd066a5873774936ef4c06434fb101edcd2b1 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 7 Jul 2022 09:58:36 -0400 Subject: [PATCH] LibJS: Replace JS::Intl::PluralRules::Type with Unicode::PluralForm The JS::Intl enum was added when implementing the PluralRules constructor. Now that LibUnicode has a plural rules implementation, replace the JS::Intl enum with the analagous Unicode enum. --- .../LibJS/Runtime/Intl/PluralRules.cpp | 23 ------------------- .../LibJS/Runtime/Intl/PluralRules.h | 14 ++++------- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/PluralRules.cpp b/Userland/Libraries/LibJS/Runtime/Intl/PluralRules.cpp index 0b6eec3ba3..fae56e7453 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/PluralRules.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/PluralRules.cpp @@ -14,27 +14,4 @@ PluralRules::PluralRules(Object& prototype) { } -void PluralRules::set_type(StringView type) -{ - if (type == "cardinal"sv) { - m_type = Type::Cardinal; - } else if (type == "ordinal"sv) { - m_type = Type::Ordinal; - } else { - VERIFY_NOT_REACHED(); - } -} - -StringView PluralRules::type_string() const -{ - switch (m_type) { - case Type::Cardinal: - return "cardinal"sv; - case Type::Ordinal: - return "ordinal"sv; - default: - VERIFY_NOT_REACHED(); - } -} - } diff --git a/Userland/Libraries/LibJS/Runtime/Intl/PluralRules.h b/Userland/Libraries/LibJS/Runtime/Intl/PluralRules.h index b1e6c6a291..643bb459d8 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/PluralRules.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/PluralRules.h @@ -10,6 +10,7 @@ #include #include #include +#include namespace JS::Intl { @@ -17,20 +18,15 @@ class PluralRules final : public NumberFormatBase { JS_OBJECT(PluralRules, NumberFormatBase); public: - enum class Type { - Cardinal, - Ordinal, - }; - PluralRules(Object& prototype); virtual ~PluralRules() override = default; - Type type() const { return m_type; } - StringView type_string() const; - void set_type(StringView type); + Unicode::PluralForm type() const { return m_type; } + StringView type_string() const { return Unicode::plural_form_to_string(m_type); } + void set_type(StringView type) { m_type = Unicode::plural_form_from_string(type); } private: - Type m_type { Type::Cardinal }; // [[Type]] + Unicode::PluralForm m_type { Unicode::PluralForm::Cardinal }; // [[Type]] }; }