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
35U_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 */
42constexpr 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
60class U_I18N_API NumberingSystem : public UObject {
61public:
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 * Destructor.
78 * @stable ICU 4.2
79 */
80 virtual ~NumberingSystem();
81
82 /**
83 * Create the default numbering system associated with the specified locale.
84 * @param inLocale The given locale.
85 * @param status ICU status
86 * @stable ICU 4.2
87 */
88 static NumberingSystem* U_EXPORT2 createInstance(const Locale & inLocale, UErrorCode& status);
89
90 /**
91 * Create the default numbering system associated with the default locale.
92 * @stable ICU 4.2
93 */
94 static NumberingSystem* U_EXPORT2 createInstance(UErrorCode& status);
95
96 /**
97 * Create a numbering system using the specified radix, type, and description.
98 * @param radix The radix (base) for this numbering system.
99 * @param isAlgorithmic TRUE if the numbering system is algorithmic rather than numeric.
100 * @param description The string representing the set of digits used in a numeric system, or the name of the RBNF
101 * ruleset to be used in an algorithmic system.
102 * @param status ICU status
103 * @stable ICU 4.2
104 */
105 static NumberingSystem* U_EXPORT2 createInstance(int32_t radix, UBool isAlgorithmic, const UnicodeString& description, UErrorCode& status );
106
107 /**
108 * Return a StringEnumeration over all the names of numbering systems known to ICU.
109 * The numbering system names will be in alphabetical (invariant) order.
110 *
111 * The returned StringEnumeration is owned by the caller, who must delete it when
112 * finished with it.
113 *
114 * @stable ICU 4.2
115 */
116 static StringEnumeration * U_EXPORT2 getAvailableNames(UErrorCode& status);
117
118 /**
119 * Create a numbering system from one of the predefined numbering systems specified
120 * by CLDR and known to ICU, such as "latn", "arabext", or "hanidec"; the full list
121 * is returned by unumsys_openAvailableNames. Note that some of the names listed at
122 * http://unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml - e.g.
123 * default, native, traditional, finance - do not identify specific numbering systems,
124 * but rather key values that may only be used as part of a locale, which in turn
125 * defines how they are mapped to a specific numbering system such as "latn" or "hant".
126 *
127 * @param name The name of the numbering system.
128 * @param status ICU status; set to U_UNSUPPORTED_ERROR if numbering system not found.
129 * @return The NumberingSystem instance, or nullptr if not found.
130 * @stable ICU 4.2
131 */
132 static NumberingSystem* U_EXPORT2 createInstanceByName(const char* name, UErrorCode& status);
133
134
135 /**
136 * Returns the radix of this numbering system. Simple positional numbering systems
137 * typically have radix 10, but might have a radix of e.g. 16 for hexadecimal. The
138 * radix is less well-defined for non-positional algorithmic systems.
139 * @stable ICU 4.2
140 */
141 int32_t getRadix() const;
142
143 /**
144 * Returns the name of this numbering system if it was created using one of the predefined names
145 * known to ICU. Otherwise, returns NULL.
146 * The predefined names are identical to the numbering system names as defined by
147 * the BCP47 definition in Unicode CLDR.
148 * See also, http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml
149 * @stable ICU 4.6
150 */
151 const char * getName() const;
152
153 /**
154 * Returns the description string of this numbering system. For simple
155 * positional systems this is the ordered string of digits (with length matching
156 * the radix), e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D"
157 * for "hanidec"; it would be "0123456789ABCDEF" for hexadecimal. For
158 * algorithmic systems this is the name of the RBNF ruleset used for formatting,
159 * e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for
160 * "grek".
161 * @stable ICU 4.2
162 */
163 virtual UnicodeString getDescription() const;
164
165
166
167 /**
168 * Returns TRUE if the given numbering system is algorithmic
169 *
170 * @return TRUE if the numbering system is algorithmic.
171 * Otherwise, return FALSE.
172 * @stable ICU 4.2
173 */
174 UBool isAlgorithmic() const;
175
176 /**
177 * ICU "poor man's RTTI", returns a UClassID for this class.
178 *
179 * @stable ICU 4.2
180 *
181 */
182 static UClassID U_EXPORT2 getStaticClassID(void);
183
184 /**
185 * ICU "poor man's RTTI", returns a UClassID for the actual class.
186 *
187 * @stable ICU 4.2
188 */
189 virtual UClassID getDynamicClassID() const;
190
191
192private:
193 UnicodeString desc;
194 int32_t radix;
195 UBool algorithmic;
196 char name[kInternalNumSysNameCapacity+1];
197
198 void setRadix(int32_t radix);
199
200 void setAlgorithmic(UBool algorithmic);
201
202 void setDesc(const UnicodeString &desc);
203
204 void setName(const char* name);
205
206 static UBool isValidDigitString(const UnicodeString &str);
207
208 UBool hasContiguousDecimalDigits() const;
209};
210
211U_NAMESPACE_END
212
213#endif /* #if !UCONFIG_NO_FORMATTING */
214
215#endif /* U_SHOW_CPLUSPLUS_API */
216
217#endif // _NUMSYS
218//eof
219