Coverage Report

Created: 2026-02-14 08:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibJS/Runtime/Intl/PluralRules.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2022-2023, Tim Flynn <trflynn89@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/String.h>
10
#include <AK/StringView.h>
11
#include <LibJS/Runtime/Completion.h>
12
#include <LibJS/Runtime/Intl/NumberFormat.h>
13
#include <LibJS/Runtime/Object.h>
14
#include <LibLocale/PluralRules.h>
15
16
namespace JS::Intl {
17
18
class PluralRules final : public NumberFormatBase {
19
    JS_OBJECT(PluralRules, NumberFormatBase);
20
    JS_DECLARE_ALLOCATOR(PluralRules);
21
22
public:
23
    virtual ~PluralRules() override = default;
24
25
0
    ::Locale::PluralForm type() const { return m_type; }
26
0
    StringView type_string() const { return ::Locale::plural_form_to_string(m_type); }
27
0
    void set_type(StringView type) { m_type = ::Locale::plural_form_from_string(type); }
28
29
private:
30
    explicit PluralRules(Object& prototype);
31
32
    ::Locale::PluralForm m_type { ::Locale::PluralForm::Cardinal }; // [[Type]]
33
};
34
35
struct ResolvedPlurality {
36
    ::Locale::PluralCategory plural_category; // [[PluralCategory]]
37
    String formatted_string;                  // [[FormattedString]]
38
};
39
40
::Locale::PluralOperands get_operands(StringView string);
41
::Locale::PluralCategory plural_rule_select(StringView locale, ::Locale::PluralForm type, Value number, ::Locale::PluralOperands operands);
42
ResolvedPlurality resolve_plural(PluralRules const&, Value number);
43
ResolvedPlurality resolve_plural(NumberFormatBase const& number_format, ::Locale::PluralForm type, Value number);
44
::Locale::PluralCategory plural_rule_select_range(StringView locale, ::Locale::PluralForm, ::Locale::PluralCategory start, ::Locale::PluralCategory end);
45
ThrowCompletionOr<::Locale::PluralCategory> resolve_plural_range(VM&, PluralRules const&, Value start, Value end);
46
47
}