1// Copyright (C) 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/**
24 * \def NUMSYS_NAME_CAPACITY
25 * Size of a numbering system name.
26 * @internal
27 */
28#define NUMSYS_NAME_CAPACITY 8
29
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
42U_NAMESPACE_BEGIN
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     * @stable ICU 4.2
110     */
111
112     static StringEnumeration * U_EXPORT2 getAvailableNames(UErrorCode& status);
113
114    /**
115     * Create a numbering system from one of the predefined numbering systems specified
116     * by CLDR and known to ICU, such as "latn", "arabext", or "hanidec"; the full list
117     * is returned by unumsys_openAvailableNames. Note that some of the names listed at
118     * http://unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml - e.g.
119     * default, native, traditional, finance - do not identify specific numbering systems,
120     * but rather key values that may only be used as part of a locale, which in turn
121     * defines how they are mapped to a specific numbering system such as "latn" or "hant".
122     * @param name   The name of the numbering system.
123     * @param status ICU status
124     * @stable ICU 4.2
125     */
126    static NumberingSystem* U_EXPORT2 createInstanceByName(const char* name, UErrorCode& status);
127
128
129    /**
130     * Returns the radix of this numbering system. Simple positional numbering systems
131     * typically have radix 10, but might have a radix of e.g. 16 for hexadecimal. The
132     * radix is less well-defined for non-positional algorithmic systems.
133     * @stable ICU 4.2
134     */
135    int32_t getRadix() const;
136
137    /**
138     * Returns the name of this numbering system if it was created using one of the predefined names
139     * known to ICU.  Otherwise, returns NULL.
140     * The predefined names are identical to the numbering system names as defined by
141     * the BCP47 definition in Unicode CLDR.
142     * See also, http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml
143     * @stable ICU 4.6
144     */
145    const char * getName() const;
146
147    /**
148     * Returns the description string of this numbering system. For simple
149     * positional systems this is the ordered string of digits (with length matching
150     * the radix), e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D"
151     * for "hanidec"; it would be "0123456789ABCDEF" for hexadecimal. For
152     * algorithmic systems this is the name of the RBNF ruleset used for formatting,
153     * e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for
154     * "grek".
155     * @stable ICU 4.2
156     */
157    virtual UnicodeString getDescription() const;
158
159
160
161    /**
162     * Returns TRUE if the given numbering system is algorithmic
163     *
164     * @return         TRUE if the numbering system is algorithmic.
165     *                 Otherwise, return FALSE.
166     * @stable ICU 4.2
167     */
168    UBool isAlgorithmic() const;
169
170    /**
171     * ICU "poor man's RTTI", returns a UClassID for this class.
172     *
173     * @stable ICU 4.2
174     *
175    */
176    static UClassID U_EXPORT2 getStaticClassID(void);
177
178    /**
179     * ICU "poor man's RTTI", returns a UClassID for the actual class.
180     *
181     * @stable ICU 4.2
182     */
183    virtual UClassID getDynamicClassID() const;
184
185
186private:
187    UnicodeString   desc;
188    int32_t         radix;
189    UBool           algorithmic;
190    char            name[NUMSYS_NAME_CAPACITY+1];
191
192    void setRadix(int32_t radix);
193
194    void setAlgorithmic(UBool algorithmic);
195
196    void setDesc(UnicodeString desc);
197
198    void setName(const char* name);
199
200    static UBool isValidDigitString(const UnicodeString &str);
201
202    UBool hasContiguousDecimalDigits() const;
203};
204
205U_NAMESPACE_END
206
207#endif /* #if !UCONFIG_NO_FORMATTING */
208
209#endif // _NUMSYS
210//eof
211