Produce JS-visible string results as UTF-16 at their source, including numeric formatting, BigInt and BigFraction formatting, URI encoding, console formatting, parser errors, regular expression errors, Intl and Temporal records, LibUnicode locale boundaries, and LibWeb bindings. Handle fractional radix formatting through the UTF-16 builder view.
42 lines
1.3 KiB
C++
42 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2022-2025, Tim Flynn <trflynn89@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/StringView.h>
|
|
#include <AK/Utf16String.h>
|
|
#include <AK/Utf16View.h>
|
|
#include <LibJS/Runtime/Completion.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);
|
|
GC_DECLARE_ALLOCATOR(PluralRules);
|
|
|
|
public:
|
|
virtual ~PluralRules() override = default;
|
|
|
|
virtual ReadonlySpan<Utf16View> relevant_extension_keys() const override;
|
|
virtual ReadonlySpan<ResolutionOptionDescriptor> resolution_option_descriptors(VM&) const override;
|
|
|
|
Unicode::PluralForm type() const { return m_type; }
|
|
Utf16String type_string() const { return Unicode::plural_form_to_string(m_type); }
|
|
void set_type(Utf16View type) { m_type = Unicode::plural_form_from_string(type); }
|
|
|
|
private:
|
|
explicit PluralRules(Object& prototype);
|
|
|
|
Unicode::PluralForm m_type { Unicode::PluralForm::Cardinal }; // [[Type]]
|
|
};
|
|
|
|
Unicode::PluralCategory resolve_plural(PluralRules const&, MathematicalValue const& number);
|
|
ThrowCompletionOr<Unicode::PluralCategory> resolve_plural_range(VM&, PluralRules const&, MathematicalValue const& start, MathematicalValue const& end);
|
|
|
|
}
|