summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibLocale/NumberFormat.h
blob: 5e069fa309c82f7ce2a800e96f56808683c5a651 (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
/*
 * Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/DeprecatedString.h>
#include <AK/Optional.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,
};

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

Optional<Span<u32 const>> get_digits_for_number_system(StringView system);
DeprecatedString replace_digits_for_number_system(StringView system, StringView number);

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

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

}