mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-17 00:23:00 +00:00
The NumberFormat spec casually indicates the need for a PluralRules object without explicity saying so, with text such as: "which may depend on x in languages having different plural forms." Other implementations actually do create a PluralRules object to resolve those cases with ResolvePlural. However, ResolvePlural doesn't need much from PluralRules to operate, so this can be abstracted out for use in NumberFormat without the need to allocate a PluralRules instance.
37 lines
1.3 KiB
C++
37 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/String.h>
|
|
#include <AK/StringView.h>
|
|
#include <LibJS/Runtime/Intl/NumberFormat.h>
|
|
#include <LibJS/Runtime/Object.h>
|
|
#include <LibUnicode/PluralRules.h>
|
|
|
|
namespace JS::Intl {
|
|
|
|
class PluralRules final : public NumberFormatBase {
|
|
JS_OBJECT(PluralRules, NumberFormatBase);
|
|
|
|
public:
|
|
PluralRules(Object& prototype);
|
|
virtual ~PluralRules() override = default;
|
|
|
|
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:
|
|
Unicode::PluralForm m_type { Unicode::PluralForm::Cardinal }; // [[Type]]
|
|
};
|
|
|
|
Unicode::PluralOperands get_operands(String const& string);
|
|
Unicode::PluralCategory plural_rule_select(StringView locale, Unicode::PluralForm type, Value number, Unicode::PluralOperands operands);
|
|
Unicode::PluralCategory resolve_plural(GlobalObject& global_object, PluralRules const& plural_rules, Value number);
|
|
Unicode::PluralCategory resolve_plural(GlobalObject& global_object, NumberFormatBase const& number_format, Unicode::PluralForm type, Value number);
|
|
|
|
}
|