Coverage Report

Created: 2025-06-24 06:43

/src/icu/source/i18n/unicode/numsys.h
Line
Count
Source (jump to first uncovered line)
1
// © 2016 and later: Unicode, Inc. and others.
2
// License & terms of use: http://www.unicode.org/copyright.html
3
/*
4
*******************************************************************************
5
* Copyright (C) 2010-2014, International Business Machines Corporation and
6
* others. All Rights Reserved.
7
*******************************************************************************
8
*
9
*
10
* File NUMSYS.H
11
*
12
* Modification History:*
13
*   Date        Name        Description
14
*
15
********************************************************************************
16
*/
17
18
#ifndef NUMSYS
19
#define NUMSYS
20
21
#include "unicode/utypes.h"
22
23
#if U_SHOW_CPLUSPLUS_API
24
25
/**
26
 * \file
27
 * \brief C++ API: NumberingSystem object
28
 */
29
30
#if !UCONFIG_NO_FORMATTING
31
32
#include "unicode/format.h"
33
#include "unicode/uobject.h"
34
35
U_NAMESPACE_BEGIN
36
37
// can't be #ifndef U_HIDE_INTERNAL_API; needed for char[] field size
38
/**
39
 * Size of a numbering system name.
40
 * @internal
41
 */
42
constexpr const size_t kInternalNumSysNameCapacity = 8;
43
44
/**
45
 * Defines numbering systems. A numbering system describes the scheme by which 
46
 * numbers are to be presented to the end user.  In its simplest form, a numbering
47
 * system describes the set of digit characters that are to be used to display
48
 * numbers, such as Western digits, Thai digits, Arabic-Indic digits, etc., in a
49
 * positional numbering system with a specified radix (typically 10).
50
 * More complicated numbering systems are algorithmic in nature, and require use
51
 * of an RBNF formatter ( rule based number formatter ), in order to calculate
52
 * the characters to be displayed for a given number.  Examples of algorithmic
53
 * numbering systems include Roman numerals, Chinese numerals, and Hebrew numerals.
54
 * Formatting rules for many commonly used numbering systems are included in
55
 * the ICU package, based on the numbering system rules defined in CLDR.
56
 * Alternate numbering systems can be specified to a locale by using the
57
 * numbers locale keyword.
58
 */
59
60
class U_I18N_API NumberingSystem : public UObject {
61
public:
62
63
    /**
64
     * Default Constructor.
65
     *
66
     * @stable ICU 4.2
67
     */
68
    NumberingSystem();
69
70
    /**
71
     * Copy constructor.
72
     * @stable ICU 4.2
73
     */
74
    NumberingSystem(const NumberingSystem& other);
75
76
    /**
77
     * Copy assignment.
78
     * @stable ICU 4.2
79
     */
80
0
    NumberingSystem& operator=(const NumberingSystem& other) = default;
81
82
    /**
83
     * Destructor.
84
     * @stable ICU 4.2
85
     */
86
    virtual ~NumberingSystem();
87
88
    /**
89
     * Create the default numbering system associated with the specified locale.
90
     * @param inLocale The given locale.
91
     * @param status ICU status
92
     * @stable ICU 4.2
93
     */
94
    static NumberingSystem* U_EXPORT2 createInstance(const Locale & inLocale, UErrorCode& status);
95
96
    /**
97
     * Create the default numbering system associated with the default locale.
98
     * @stable ICU 4.2
99
     */
100
    static NumberingSystem* U_EXPORT2 createInstance(UErrorCode& status);
101
102
    /**
103
     * Create a numbering system using the specified radix, type, and description. 
104
     * @param radix         The radix (base) for this numbering system.
105
     * @param isAlgorithmic true if the numbering system is algorithmic rather than numeric.
106
     * @param description   The string representing the set of digits used in a numeric system, or the name of the RBNF
107
     *                      ruleset to be used in an algorithmic system.
108
     * @param status ICU status
109
     * @stable ICU 4.2
110
     */
111
    static NumberingSystem* U_EXPORT2 createInstance(int32_t radix, UBool isAlgorithmic, const UnicodeString& description, UErrorCode& status );
112
113
    /**
114
     * Return a StringEnumeration over all the names of numbering systems known to ICU.
115
     * The numbering system names will be in alphabetical (invariant) order.
116
     *
117
     * The returned StringEnumeration is owned by the caller, who must delete it when
118
     * finished with it.
119
     *
120
     * @stable ICU 4.2
121
     */
122
     static StringEnumeration * U_EXPORT2 getAvailableNames(UErrorCode& status);
123
124
    /**
125
     * Create a numbering system from one of the predefined numbering systems specified
126
     * by CLDR and known to ICU, such as "latn", "arabext", or "hanidec"; the full list
127
     * is returned by unumsys_openAvailableNames. Note that some of the names listed at
128
     * http://unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml - e.g.
129
     * default, native, traditional, finance - do not identify specific numbering systems,
130
     * but rather key values that may only be used as part of a locale, which in turn
131
     * defines how they are mapped to a specific numbering system such as "latn" or "hant".
132
     *
133
     * @param name   The name of the numbering system.
134
     * @param status ICU status; set to U_UNSUPPORTED_ERROR if numbering system not found.
135
     * @return The NumberingSystem instance, or nullptr if not found.
136
     * @stable ICU 4.2
137
     */
138
    static NumberingSystem* U_EXPORT2 createInstanceByName(const char* name, UErrorCode& status);
139
140
141
    /**
142
     * Returns the radix of this numbering system. Simple positional numbering systems
143
     * typically have radix 10, but might have a radix of e.g. 16 for hexadecimal. The
144
     * radix is less well-defined for non-positional algorithmic systems.
145
     * @stable ICU 4.2
146
     */
147
    int32_t getRadix() const;
148
149
    /**
150
     * Returns the name of this numbering system if it was created using one of the predefined names
151
     * known to ICU.  Otherwise, returns NULL.
152
     * The predefined names are identical to the numbering system names as defined by
153
     * the BCP47 definition in Unicode CLDR.
154
     * See also, http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml
155
     * @stable ICU 4.6
156
     */
157
    const char * getName() const;
158
159
    /**
160
     * Returns the description string of this numbering system. For simple
161
     * positional systems this is the ordered string of digits (with length matching
162
     * the radix), e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D"
163
     * for "hanidec"; it would be "0123456789ABCDEF" for hexadecimal. For
164
     * algorithmic systems this is the name of the RBNF ruleset used for formatting,
165
     * e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for
166
     * "grek".
167
     * @stable ICU 4.2
168
     */
169
    virtual UnicodeString getDescription() const;
170
171
172
173
    /**
174
     * Returns true if the given numbering system is algorithmic
175
     *
176
     * @return         true if the numbering system is algorithmic.
177
     *                 Otherwise, return false.
178
     * @stable ICU 4.2
179
     */
180
    UBool isAlgorithmic() const;
181
182
    /**
183
     * ICU "poor man's RTTI", returns a UClassID for this class.
184
     *
185
     * @stable ICU 4.2
186
     *
187
    */
188
    static UClassID U_EXPORT2 getStaticClassID(void);
189
190
    /**
191
     * ICU "poor man's RTTI", returns a UClassID for the actual class.
192
     *
193
     * @stable ICU 4.2
194
     */
195
    virtual UClassID getDynamicClassID() const;
196
197
198
private:
199
    UnicodeString   desc;
200
    int32_t         radix;
201
    UBool           algorithmic;
202
    char            name[kInternalNumSysNameCapacity+1];
203
204
    void setRadix(int32_t radix);
205
206
    void setAlgorithmic(UBool algorithmic);
207
208
    void setDesc(const UnicodeString &desc);
209
210
    void setName(const char* name);
211
212
    static UBool isValidDigitString(const UnicodeString &str);
213
214
    UBool hasContiguousDecimalDigits() const;
215
};
216
217
U_NAMESPACE_END
218
219
#endif /* #if !UCONFIG_NO_FORMATTING */
220
221
#endif /* U_SHOW_CPLUSPLUS_API */
222
223
#endif // _NUMSYS
224
//eof