1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2010-2014, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 *******************************************************************************
12 * Modification History:*
13 * Date Name Description
15 ********************************************************************************
21 #include "unicode/utypes.h"
25 * \brief C++ API: NumberingSystem object
28 #if !UCONFIG_NO_FORMATTING
30 #include "unicode/format.h"
31 #include "unicode/uobject.h"
33 #if U_SHOW_CPLUSPLUS_API
36 // can't be #ifndef U_HIDE_INTERNAL_API; needed for char[] field size
38 * Size of a numbering system name.
41 constexpr const size_t kInternalNumSysNameCapacity
= 8;
44 * Defines numbering systems. A numbering system describes the scheme by which
45 * numbers are to be presented to the end user. In its simplest form, a numbering
46 * system describes the set of digit characters that are to be used to display
47 * numbers, such as Western digits, Thai digits, Arabic-Indic digits, etc., in a
48 * positional numbering system with a specified radix (typically 10).
49 * More complicated numbering systems are algorithmic in nature, and require use
50 * of an RBNF formatter ( rule based number formatter ), in order to calculate
51 * the characters to be displayed for a given number. Examples of algorithmic
52 * numbering systems include Roman numerals, Chinese numerals, and Hebrew numerals.
53 * Formatting rules for many commonly used numbering systems are included in
54 * the ICU package, based on the numbering system rules defined in CLDR.
55 * Alternate numbering systems can be specified to a locale by using the
56 * numbers locale keyword.
59 class U_I18N_API NumberingSystem
: public UObject
{
63 * Default Constructor.
73 NumberingSystem(const NumberingSystem
& other
);
79 virtual ~NumberingSystem();
82 * Create the default numbering system associated with the specified locale.
83 * @param inLocale The given locale.
84 * @param status ICU status
87 static NumberingSystem
* U_EXPORT2
createInstance(const Locale
& inLocale
, UErrorCode
& status
);
90 * Create the default numbering system associated with the default locale.
93 static NumberingSystem
* U_EXPORT2
createInstance(UErrorCode
& status
);
96 * Create a numbering system using the specified radix, type, and description.
97 * @param radix The radix (base) for this numbering system.
98 * @param isAlgorithmic TRUE if the numbering system is algorithmic rather than numeric.
99 * @param description The string representing the set of digits used in a numeric system, or the name of the RBNF
100 * ruleset to be used in an algorithmic system.
101 * @param status ICU status
104 static NumberingSystem
* U_EXPORT2
createInstance(int32_t radix
, UBool isAlgorithmic
, const UnicodeString
& description
, UErrorCode
& status
);
107 * Return a StringEnumeration over all the names of numbering systems known to ICU.
108 * The numbering system names will be in alphabetical (invariant) order.
110 * The returned StringEnumeration is owned by the caller, who must delete it when
115 static StringEnumeration
* U_EXPORT2
getAvailableNames(UErrorCode
& status
);
118 * Create a numbering system from one of the predefined numbering systems specified
119 * by CLDR and known to ICU, such as "latn", "arabext", or "hanidec"; the full list
120 * is returned by unumsys_openAvailableNames. Note that some of the names listed at
121 * http://unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml - e.g.
122 * default, native, traditional, finance - do not identify specific numbering systems,
123 * but rather key values that may only be used as part of a locale, which in turn
124 * defines how they are mapped to a specific numbering system such as "latn" or "hant".
126 * @param name The name of the numbering system.
127 * @param status ICU status; set to U_UNSUPPORTED_ERROR if numbering system not found.
128 * @return The NumberingSystem instance, or nullptr if not found.
131 static NumberingSystem
* U_EXPORT2
createInstanceByName(const char* name
, UErrorCode
& status
);
135 * Returns the radix of this numbering system. Simple positional numbering systems
136 * typically have radix 10, but might have a radix of e.g. 16 for hexadecimal. The
137 * radix is less well-defined for non-positional algorithmic systems.
140 int32_t getRadix() const;
143 * Returns the name of this numbering system if it was created using one of the predefined names
144 * known to ICU. Otherwise, returns NULL.
145 * The predefined names are identical to the numbering system names as defined by
146 * the BCP47 definition in Unicode CLDR.
147 * See also, http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml
150 const char * getName() const;
153 * Returns the description string of this numbering system. For simple
154 * positional systems this is the ordered string of digits (with length matching
155 * the radix), e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D"
156 * for "hanidec"; it would be "0123456789ABCDEF" for hexadecimal. For
157 * algorithmic systems this is the name of the RBNF ruleset used for formatting,
158 * e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for
162 virtual UnicodeString
getDescription() const;
167 * Returns TRUE if the given numbering system is algorithmic
169 * @return TRUE if the numbering system is algorithmic.
170 * Otherwise, return FALSE.
173 UBool
isAlgorithmic() const;
176 * ICU "poor man's RTTI", returns a UClassID for this class.
181 static UClassID U_EXPORT2
getStaticClassID(void);
184 * ICU "poor man's RTTI", returns a UClassID for the actual class.
188 virtual UClassID
getDynamicClassID() const;
195 char name
[kInternalNumSysNameCapacity
+1];
197 void setRadix(int32_t radix
);
199 void setAlgorithmic(UBool algorithmic
);
201 void setDesc(const UnicodeString
&desc
);
203 void setName(const char* name
);
205 static UBool
isValidDigitString(const UnicodeString
&str
);
207 UBool
hasContiguousDecimalDigits() const;
211 #endif // U_SHOW_CPLUSPLUS_API
213 #endif /* #if !UCONFIG_NO_FORMATTING */