]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/unicode/numsys.h
ICU-62141.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / numsys.h
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
729e4ab9
A
3/*
4*******************************************************************************
57a6839d 5* Copyright (C) 2010-2014, International Business Machines Corporation and
729e4ab9
A
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
51004dcb
A
21#include "unicode/utypes.h"
22
729e4ab9
A
23/**
24 * \def NUMSYS_NAME_CAPACITY
25 * Size of a numbering system name.
26 * @internal
27 */
28#define NUMSYS_NAME_CAPACITY 8
29
729e4ab9
A
30
31/**
32 * \file
33 * \brief C++ API: NumberingSystem object
34 */
35
36#if !UCONFIG_NO_FORMATTING
37
38
39#include "unicode/format.h"
40#include "unicode/uobject.h"
41
f3c0d7a5 42#if U_SHOW_CPLUSPLUS_API
729e4ab9
A
43U_NAMESPACE_BEGIN
44
45/**
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
57a6839d
A
49 * numbers, such as Western digits, Thai digits, Arabic-Indic digits, etc., in a
50 * positional numbering system with a specified radix (typically 10).
729e4ab9
A
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.
59 */
60
61class U_I18N_API NumberingSystem : public UObject {
62public:
63
64 /**
65 * Default Constructor.
66 *
67 * @stable ICU 4.2
68 */
69 NumberingSystem();
70
71 /**
72 * Copy constructor.
73 * @stable ICU 4.2
74 */
75 NumberingSystem(const NumberingSystem& other);
76
77 /**
78 * Destructor.
79 * @stable ICU 4.2
80 */
81 virtual ~NumberingSystem();
82
83 /**
84 * Create the default numbering system associated with the specified locale.
85 * @param inLocale The given locale.
86 * @param status ICU status
87 * @stable ICU 4.2
88 */
89 static NumberingSystem* U_EXPORT2 createInstance(const Locale & inLocale, UErrorCode& status);
90
91 /**
92 * Create the default numbering system associated with the default locale.
93 * @stable ICU 4.2
94 */
95 static NumberingSystem* U_EXPORT2 createInstance(UErrorCode& status);
96
97 /**
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
104 * @stable ICU 4.2
105 */
106 static NumberingSystem* U_EXPORT2 createInstance(int32_t radix, UBool isAlgorithmic, const UnicodeString& description, UErrorCode& status );
107
108 /**
109 * Return a StringEnumeration over all the names of numbering systems known to ICU.
110 * @stable ICU 4.2
111 */
112
113 static StringEnumeration * U_EXPORT2 getAvailableNames(UErrorCode& status);
114
115 /**
57a6839d
A
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".
729e4ab9
A
123 * @param name The name of the numbering system.
124 * @param status ICU status
125 * @stable ICU 4.2
126 */
127 static NumberingSystem* U_EXPORT2 createInstanceByName(const char* name, UErrorCode& status);
128
129
130 /**
57a6839d
A
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.
729e4ab9
A
134 * @stable ICU 4.2
135 */
57a6839d 136 int32_t getRadix() const;
729e4ab9
A
137
138 /**
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.
57a6839d
A
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
51004dcb 144 * @stable ICU 4.6
729e4ab9 145 */
57a6839d 146 const char * getName() const;
729e4ab9
A
147
148 /**
57a6839d
A
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
155 * "grek".
729e4ab9
A
156 * @stable ICU 4.2
157 */
57a6839d 158 virtual UnicodeString getDescription() const;
729e4ab9
A
159
160
161
162 /**
163 * Returns TRUE if the given numbering system is algorithmic
164 *
165 * @return TRUE if the numbering system is algorithmic.
166 * Otherwise, return FALSE.
167 * @stable ICU 4.2
168 */
169 UBool isAlgorithmic() const;
170
171 /**
172 * ICU "poor man's RTTI", returns a UClassID for this class.
173 *
174 * @stable ICU 4.2
175 *
176 */
177 static UClassID U_EXPORT2 getStaticClassID(void);
178
179 /**
180 * ICU "poor man's RTTI", returns a UClassID for the actual class.
181 *
182 * @stable ICU 4.2
183 */
184 virtual UClassID getDynamicClassID() const;
185
186
187private:
188 UnicodeString desc;
189 int32_t radix;
190 UBool algorithmic;
191 char name[NUMSYS_NAME_CAPACITY+1];
192
193 void setRadix(int32_t radix);
194
195 void setAlgorithmic(UBool algorithmic);
196
f3c0d7a5 197 void setDesc(const UnicodeString &desc);
729e4ab9
A
198
199 void setName(const char* name);
200
201 static UBool isValidDigitString(const UnicodeString &str);
202
203 UBool hasContiguousDecimalDigits() const;
204};
205
206U_NAMESPACE_END
f3c0d7a5 207#endif // U_SHOW_CPLUSPLUS_API
729e4ab9
A
208
209#endif /* #if !UCONFIG_NO_FORMATTING */
210
211#endif // _NUMSYS
212//eof