Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | ******************************************************************************* |
michael@0 | 3 | * Copyright (C) 2010-2013, International Business Machines Corporation and |
michael@0 | 4 | * others. All Rights Reserved. |
michael@0 | 5 | ******************************************************************************* |
michael@0 | 6 | * |
michael@0 | 7 | * |
michael@0 | 8 | * File NUMSYS.H |
michael@0 | 9 | * |
michael@0 | 10 | * Modification History:* |
michael@0 | 11 | * Date Name Description |
michael@0 | 12 | * |
michael@0 | 13 | ******************************************************************************** |
michael@0 | 14 | */ |
michael@0 | 15 | |
michael@0 | 16 | #ifndef NUMSYS |
michael@0 | 17 | #define NUMSYS |
michael@0 | 18 | |
michael@0 | 19 | #include "unicode/utypes.h" |
michael@0 | 20 | |
michael@0 | 21 | /** |
michael@0 | 22 | * \def NUMSYS_NAME_CAPACITY |
michael@0 | 23 | * Size of a numbering system name. |
michael@0 | 24 | * @internal |
michael@0 | 25 | */ |
michael@0 | 26 | #define NUMSYS_NAME_CAPACITY 8 |
michael@0 | 27 | |
michael@0 | 28 | |
michael@0 | 29 | /** |
michael@0 | 30 | * \file |
michael@0 | 31 | * \brief C++ API: NumberingSystem object |
michael@0 | 32 | */ |
michael@0 | 33 | |
michael@0 | 34 | #if !UCONFIG_NO_FORMATTING |
michael@0 | 35 | |
michael@0 | 36 | |
michael@0 | 37 | #include "unicode/format.h" |
michael@0 | 38 | #include "unicode/uobject.h" |
michael@0 | 39 | |
michael@0 | 40 | U_NAMESPACE_BEGIN |
michael@0 | 41 | |
michael@0 | 42 | /** |
michael@0 | 43 | * Defines numbering systems. A numbering system describes the scheme by which |
michael@0 | 44 | * numbers are to be presented to the end user. In its simplest form, a numbering |
michael@0 | 45 | * system describes the set of digit characters that are to be used to display |
michael@0 | 46 | * numbers, such as Western digits, Thai digits, Arabic-Indic digits, etc., in a |
michael@0 | 47 | * positional numbering system with a specified radix (typically 10). |
michael@0 | 48 | * More complicated numbering systems are algorithmic in nature, and require use |
michael@0 | 49 | * of an RBNF formatter ( rule based number formatter ), in order to calculate |
michael@0 | 50 | * the characters to be displayed for a given number. Examples of algorithmic |
michael@0 | 51 | * numbering systems include Roman numerals, Chinese numerals, and Hebrew numerals. |
michael@0 | 52 | * Formatting rules for many commonly used numbering systems are included in |
michael@0 | 53 | * the ICU package, based on the numbering system rules defined in CLDR. |
michael@0 | 54 | * Alternate numbering systems can be specified to a locale by using the |
michael@0 | 55 | * numbers locale keyword. |
michael@0 | 56 | */ |
michael@0 | 57 | |
michael@0 | 58 | class U_I18N_API NumberingSystem : public UObject { |
michael@0 | 59 | public: |
michael@0 | 60 | |
michael@0 | 61 | /** |
michael@0 | 62 | * Default Constructor. |
michael@0 | 63 | * |
michael@0 | 64 | * @stable ICU 4.2 |
michael@0 | 65 | */ |
michael@0 | 66 | NumberingSystem(); |
michael@0 | 67 | |
michael@0 | 68 | /** |
michael@0 | 69 | * Copy constructor. |
michael@0 | 70 | * @stable ICU 4.2 |
michael@0 | 71 | */ |
michael@0 | 72 | NumberingSystem(const NumberingSystem& other); |
michael@0 | 73 | |
michael@0 | 74 | /** |
michael@0 | 75 | * Destructor. |
michael@0 | 76 | * @stable ICU 4.2 |
michael@0 | 77 | */ |
michael@0 | 78 | virtual ~NumberingSystem(); |
michael@0 | 79 | |
michael@0 | 80 | /** |
michael@0 | 81 | * Create the default numbering system associated with the specified locale. |
michael@0 | 82 | * @param inLocale The given locale. |
michael@0 | 83 | * @param status ICU status |
michael@0 | 84 | * @stable ICU 4.2 |
michael@0 | 85 | */ |
michael@0 | 86 | static NumberingSystem* U_EXPORT2 createInstance(const Locale & inLocale, UErrorCode& status); |
michael@0 | 87 | |
michael@0 | 88 | /** |
michael@0 | 89 | * Create the default numbering system associated with the default locale. |
michael@0 | 90 | * @stable ICU 4.2 |
michael@0 | 91 | */ |
michael@0 | 92 | static NumberingSystem* U_EXPORT2 createInstance(UErrorCode& status); |
michael@0 | 93 | |
michael@0 | 94 | /** |
michael@0 | 95 | * Create a numbering system using the specified radix, type, and description. |
michael@0 | 96 | * @param radix The radix (base) for this numbering system. |
michael@0 | 97 | * @param isAlgorithmic TRUE if the numbering system is algorithmic rather than numeric. |
michael@0 | 98 | * @param description The string representing the set of digits used in a numeric system, or the name of the RBNF |
michael@0 | 99 | * ruleset to be used in an algorithmic system. |
michael@0 | 100 | * @param status ICU status |
michael@0 | 101 | * @stable ICU 4.2 |
michael@0 | 102 | */ |
michael@0 | 103 | static NumberingSystem* U_EXPORT2 createInstance(int32_t radix, UBool isAlgorithmic, const UnicodeString& description, UErrorCode& status ); |
michael@0 | 104 | |
michael@0 | 105 | /** |
michael@0 | 106 | * Return a StringEnumeration over all the names of numbering systems known to ICU. |
michael@0 | 107 | * @stable ICU 4.2 |
michael@0 | 108 | */ |
michael@0 | 109 | |
michael@0 | 110 | static StringEnumeration * U_EXPORT2 getAvailableNames(UErrorCode& status); |
michael@0 | 111 | |
michael@0 | 112 | /** |
michael@0 | 113 | * Create a numbering system from one of the predefined numbering systems specified |
michael@0 | 114 | * by CLDR and known to ICU, such as "latn", "arabext", or "hanidec"; the full list |
michael@0 | 115 | * is returned by unumsys_openAvailableNames. Note that some of the names listed at |
michael@0 | 116 | * http://unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml - e.g. |
michael@0 | 117 | * default, native, traditional, finance - do not identify specific numbering systems, |
michael@0 | 118 | * but rather key values that may only be used as part of a locale, which in turn |
michael@0 | 119 | * defines how they are mapped to a specific numbering system such as "latn" or "hant". |
michael@0 | 120 | * @param name The name of the numbering system. |
michael@0 | 121 | * @param status ICU status |
michael@0 | 122 | * @stable ICU 4.2 |
michael@0 | 123 | */ |
michael@0 | 124 | static NumberingSystem* U_EXPORT2 createInstanceByName(const char* name, UErrorCode& status); |
michael@0 | 125 | |
michael@0 | 126 | |
michael@0 | 127 | /** |
michael@0 | 128 | * Returns the radix of this numbering system. Simple positional numbering systems |
michael@0 | 129 | * typically have radix 10, but might have a radix of e.g. 16 for hexadecimal. The |
michael@0 | 130 | * radix is less well-defined for non-positional algorithmic systems. |
michael@0 | 131 | * @stable ICU 4.2 |
michael@0 | 132 | */ |
michael@0 | 133 | int32_t getRadix() const; |
michael@0 | 134 | |
michael@0 | 135 | /** |
michael@0 | 136 | * Returns the name of this numbering system if it was created using one of the predefined names |
michael@0 | 137 | * known to ICU. Otherwise, returns NULL. |
michael@0 | 138 | * @stable ICU 4.6 |
michael@0 | 139 | */ |
michael@0 | 140 | const char * getName() const; |
michael@0 | 141 | |
michael@0 | 142 | /** |
michael@0 | 143 | * Returns the description string of this numbering system. For simple |
michael@0 | 144 | * positional systems this is the ordered string of digits (with length matching |
michael@0 | 145 | * the radix), e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D" |
michael@0 | 146 | * for "hanidec"; it would be "0123456789ABCDEF" for hexadecimal. For |
michael@0 | 147 | * algorithmic systems this is the name of the RBNF ruleset used for formatting, |
michael@0 | 148 | * e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for |
michael@0 | 149 | * "grek". |
michael@0 | 150 | * @stable ICU 4.2 |
michael@0 | 151 | */ |
michael@0 | 152 | virtual UnicodeString getDescription() const; |
michael@0 | 153 | |
michael@0 | 154 | |
michael@0 | 155 | |
michael@0 | 156 | /** |
michael@0 | 157 | * Returns TRUE if the given numbering system is algorithmic |
michael@0 | 158 | * |
michael@0 | 159 | * @return TRUE if the numbering system is algorithmic. |
michael@0 | 160 | * Otherwise, return FALSE. |
michael@0 | 161 | * @stable ICU 4.2 |
michael@0 | 162 | */ |
michael@0 | 163 | UBool isAlgorithmic() const; |
michael@0 | 164 | |
michael@0 | 165 | /** |
michael@0 | 166 | * ICU "poor man's RTTI", returns a UClassID for this class. |
michael@0 | 167 | * |
michael@0 | 168 | * @stable ICU 4.2 |
michael@0 | 169 | * |
michael@0 | 170 | */ |
michael@0 | 171 | static UClassID U_EXPORT2 getStaticClassID(void); |
michael@0 | 172 | |
michael@0 | 173 | /** |
michael@0 | 174 | * ICU "poor man's RTTI", returns a UClassID for the actual class. |
michael@0 | 175 | * |
michael@0 | 176 | * @stable ICU 4.2 |
michael@0 | 177 | */ |
michael@0 | 178 | virtual UClassID getDynamicClassID() const; |
michael@0 | 179 | |
michael@0 | 180 | |
michael@0 | 181 | private: |
michael@0 | 182 | UnicodeString desc; |
michael@0 | 183 | int32_t radix; |
michael@0 | 184 | UBool algorithmic; |
michael@0 | 185 | char name[NUMSYS_NAME_CAPACITY+1]; |
michael@0 | 186 | |
michael@0 | 187 | void setRadix(int32_t radix); |
michael@0 | 188 | |
michael@0 | 189 | void setAlgorithmic(UBool algorithmic); |
michael@0 | 190 | |
michael@0 | 191 | void setDesc(UnicodeString desc); |
michael@0 | 192 | |
michael@0 | 193 | void setName(const char* name); |
michael@0 | 194 | |
michael@0 | 195 | static UBool isValidDigitString(const UnicodeString &str); |
michael@0 | 196 | |
michael@0 | 197 | UBool hasContiguousDecimalDigits() const; |
michael@0 | 198 | }; |
michael@0 | 199 | |
michael@0 | 200 | U_NAMESPACE_END |
michael@0 | 201 | |
michael@0 | 202 | #endif /* #if !UCONFIG_NO_FORMATTING */ |
michael@0 | 203 | |
michael@0 | 204 | #endif // _NUMSYS |
michael@0 | 205 | //eof |