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