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"
24 * \def NUMSYS_NAME_CAPACITY
25 * Size of a numbering system name.
28 #define NUMSYS_NAME_CAPACITY 8
33 * \brief C++ API: NumberingSystem object
36 #if !UCONFIG_NO_FORMATTING
39 #include "unicode/format.h"
40 #include "unicode/uobject.h"
42 #if U_SHOW_CPLUSPLUS_API
46 * Defines numbering systems. A numbering system describes the scheme by which
47 * numbers are to be presented to the end user. In its simplest form, a numbering
48 * system describes the set of digit characters that are to be used to display
49 * numbers, such as Western digits, Thai digits, Arabic-Indic digits, etc., in a
50 * positional numbering system with a specified radix (typically 10).
51 * More complicated numbering systems are algorithmic in nature, and require use
52 * of an RBNF formatter ( rule based number formatter ), in order to calculate
53 * the characters to be displayed for a given number. Examples of algorithmic
54 * numbering systems include Roman numerals, Chinese numerals, and Hebrew numerals.
55 * Formatting rules for many commonly used numbering systems are included in
56 * the ICU package, based on the numbering system rules defined in CLDR.
57 * Alternate numbering systems can be specified to a locale by using the
58 * numbers locale keyword.
61 class U_I18N_API NumberingSystem
: public UObject
{
65 * Default Constructor.
75 NumberingSystem(const NumberingSystem
& other
);
81 virtual ~NumberingSystem();
84 * Create the default numbering system associated with the specified locale.
85 * @param inLocale The given locale.
86 * @param status ICU status
89 static NumberingSystem
* U_EXPORT2
createInstance(const Locale
& inLocale
, UErrorCode
& status
);
92 * Create the default numbering system associated with the default locale.
95 static NumberingSystem
* U_EXPORT2
createInstance(UErrorCode
& status
);
98 * Create a numbering system using the specified radix, type, and description.
99 * @param radix The radix (base) for this numbering system.
100 * @param isAlgorithmic TRUE if the numbering system is algorithmic rather than numeric.
101 * @param description The string representing the set of digits used in a numeric system, or the name of the RBNF
102 * ruleset to be used in an algorithmic system.
103 * @param status ICU status
106 static NumberingSystem
* U_EXPORT2
createInstance(int32_t radix
, UBool isAlgorithmic
, const UnicodeString
& description
, UErrorCode
& status
);
109 * Return a StringEnumeration over all the names of numbering systems known to ICU.
113 static StringEnumeration
* U_EXPORT2
getAvailableNames(UErrorCode
& status
);
116 * Create a numbering system from one of the predefined numbering systems specified
117 * by CLDR and known to ICU, such as "latn", "arabext", or "hanidec"; the full list
118 * is returned by unumsys_openAvailableNames. Note that some of the names listed at
119 * http://unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml - e.g.
120 * default, native, traditional, finance - do not identify specific numbering systems,
121 * but rather key values that may only be used as part of a locale, which in turn
122 * defines how they are mapped to a specific numbering system such as "latn" or "hant".
123 * @param name The name of the numbering system.
124 * @param status ICU status
127 static NumberingSystem
* U_EXPORT2
createInstanceByName(const char* name
, UErrorCode
& status
);
131 * Returns the radix of this numbering system. Simple positional numbering systems
132 * typically have radix 10, but might have a radix of e.g. 16 for hexadecimal. The
133 * radix is less well-defined for non-positional algorithmic systems.
136 int32_t getRadix() const;
139 * Returns the name of this numbering system if it was created using one of the predefined names
140 * known to ICU. Otherwise, returns NULL.
141 * The predefined names are identical to the numbering system names as defined by
142 * the BCP47 definition in Unicode CLDR.
143 * See also, http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml
146 const char * getName() const;
149 * Returns the description string of this numbering system. For simple
150 * positional systems this is the ordered string of digits (with length matching
151 * the radix), e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D"
152 * for "hanidec"; it would be "0123456789ABCDEF" for hexadecimal. For
153 * algorithmic systems this is the name of the RBNF ruleset used for formatting,
154 * e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for
158 virtual UnicodeString
getDescription() const;
163 * Returns TRUE if the given numbering system is algorithmic
165 * @return TRUE if the numbering system is algorithmic.
166 * Otherwise, return FALSE.
169 UBool
isAlgorithmic() const;
172 * ICU "poor man's RTTI", returns a UClassID for this class.
177 static UClassID U_EXPORT2
getStaticClassID(void);
180 * ICU "poor man's RTTI", returns a UClassID for the actual class.
184 virtual UClassID
getDynamicClassID() const;
191 char name
[NUMSYS_NAME_CAPACITY
+1];
193 void setRadix(int32_t radix
);
195 void setAlgorithmic(UBool algorithmic
);
197 void setDesc(const UnicodeString
&desc
);
199 void setName(const char* name
);
201 static UBool
isValidDigitString(const UnicodeString
&str
);
203 UBool
hasContiguousDecimalDigits() const;
207 #endif // U_SHOW_CPLUSPLUS_API
209 #endif /* #if !UCONFIG_NO_FORMATTING */