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