summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibLocale/NumberFormat.h
blob: 62bec6d48a54d43fbbbaa32ed6798f33046cb2d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright (c) 2021-2023, Tim Flynn <trflynn89@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Error.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
#include <LibLocale/Forward.h>
#include <LibLocale/PluralRules.h>

namespace Locale {

struct NumberGroupings {
    u8 minimum_grouping_digits { 0 };
    u8 primary_grouping_size { 0 };
    u8 secondary_grouping_size { 0 };
};

enum class StandardNumberFormatType : u8 {
    Decimal,
    Currency,
    Accounting,
    Percent,
    Scientific,
};

enum class CompactNumberFormatType : u8 {
    DecimalLong,
    DecimalShort,
    CurrencyUnit,
    CurrencyShort,
};

struct NumberFormat {
    u8 magnitude { 0 };
    u8 exponent { 0 };
    PluralCategory plurality { PluralCategory::Other };
    StringView zero_format {};
    StringView positive_format {};
    StringView negative_format {};
    Vector<StringView> identifiers {};
};

enum class NumericSymbol : u8 {
    ApproximatelySign,
    Decimal,
    Exponential,
    Group,
    Infinity,
    MinusSign,
    NaN,
    PercentSign,
    PlusSign,
    RangeSeparator,
    TimeSeparator,
};

ErrorOr<Optional<StringView>> get_number_system_symbol(StringView locale, StringView system, NumericSymbol symbol);
ErrorOr<Optional<NumberGroupings>> get_number_system_groupings(StringView locale, StringView system);

Optional<ReadonlySpan<u32>> get_digits_for_number_system(StringView system);
ErrorOr<String> replace_digits_for_number_system(StringView system, StringView number);

ErrorOr<Optional<NumberFormat>> get_standard_number_system_format(StringView locale, StringView system, StandardNumberFormatType type);
ErrorOr<Vector<NumberFormat>> get_compact_number_system_formats(StringView locale, StringView system, CompactNumberFormatType type);
ErrorOr<Vector<NumberFormat>> get_unit_formats(StringView locale, StringView unit, Style style);

ErrorOr<Optional<String>> augment_currency_format_pattern(StringView currency_display, StringView base_pattern);
ErrorOr<Optional<String>> augment_range_pattern(StringView range_separator, StringView lower, StringView upper);

}