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.
This commit is contained in:
Timothy Flynn 2022-07-07 09:58:36 -04:00 committed by Linus Groh
parent 2982aa0373
commit 670bd066a5
2 changed files with 5 additions and 32 deletions

View file

@ -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();
}
}
}

View file

@ -10,6 +10,7 @@
#include <AK/StringView.h>
#include <LibJS/Runtime/Intl/NumberFormat.h>
#include <LibJS/Runtime/Object.h>
#include <LibUnicode/PluralRules.h>
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]]
};
}