1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/unicode/numsys.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,205 @@ 1.4 +/* 1.5 +******************************************************************************* 1.6 +* Copyright (C) 2010-2013, International Business Machines Corporation and 1.7 +* others. All Rights Reserved. 1.8 +******************************************************************************* 1.9 +* 1.10 +* 1.11 +* File NUMSYS.H 1.12 +* 1.13 +* Modification History:* 1.14 +* Date Name Description 1.15 +* 1.16 +******************************************************************************** 1.17 +*/ 1.18 + 1.19 +#ifndef NUMSYS 1.20 +#define NUMSYS 1.21 + 1.22 +#include "unicode/utypes.h" 1.23 + 1.24 +/** 1.25 + * \def NUMSYS_NAME_CAPACITY 1.26 + * Size of a numbering system name. 1.27 + * @internal 1.28 + */ 1.29 +#define NUMSYS_NAME_CAPACITY 8 1.30 + 1.31 + 1.32 +/** 1.33 + * \file 1.34 + * \brief C++ API: NumberingSystem object 1.35 + */ 1.36 + 1.37 +#if !UCONFIG_NO_FORMATTING 1.38 + 1.39 + 1.40 +#include "unicode/format.h" 1.41 +#include "unicode/uobject.h" 1.42 + 1.43 +U_NAMESPACE_BEGIN 1.44 + 1.45 +/** 1.46 + * Defines numbering systems. A numbering system describes the scheme by which 1.47 + * numbers are to be presented to the end user. In its simplest form, a numbering 1.48 + * system describes the set of digit characters that are to be used to display 1.49 + * numbers, such as Western digits, Thai digits, Arabic-Indic digits, etc., in a 1.50 + * positional numbering system with a specified radix (typically 10). 1.51 + * More complicated numbering systems are algorithmic in nature, and require use 1.52 + * of an RBNF formatter ( rule based number formatter ), in order to calculate 1.53 + * the characters to be displayed for a given number. Examples of algorithmic 1.54 + * numbering systems include Roman numerals, Chinese numerals, and Hebrew numerals. 1.55 + * Formatting rules for many commonly used numbering systems are included in 1.56 + * the ICU package, based on the numbering system rules defined in CLDR. 1.57 + * Alternate numbering systems can be specified to a locale by using the 1.58 + * numbers locale keyword. 1.59 + */ 1.60 + 1.61 +class U_I18N_API NumberingSystem : public UObject { 1.62 +public: 1.63 + 1.64 + /** 1.65 + * Default Constructor. 1.66 + * 1.67 + * @stable ICU 4.2 1.68 + */ 1.69 + NumberingSystem(); 1.70 + 1.71 + /** 1.72 + * Copy constructor. 1.73 + * @stable ICU 4.2 1.74 + */ 1.75 + NumberingSystem(const NumberingSystem& other); 1.76 + 1.77 + /** 1.78 + * Destructor. 1.79 + * @stable ICU 4.2 1.80 + */ 1.81 + virtual ~NumberingSystem(); 1.82 + 1.83 + /** 1.84 + * Create the default numbering system associated with the specified locale. 1.85 + * @param inLocale The given locale. 1.86 + * @param status ICU status 1.87 + * @stable ICU 4.2 1.88 + */ 1.89 + static NumberingSystem* U_EXPORT2 createInstance(const Locale & inLocale, UErrorCode& status); 1.90 + 1.91 + /** 1.92 + * Create the default numbering system associated with the default locale. 1.93 + * @stable ICU 4.2 1.94 + */ 1.95 + static NumberingSystem* U_EXPORT2 createInstance(UErrorCode& status); 1.96 + 1.97 + /** 1.98 + * Create a numbering system using the specified radix, type, and description. 1.99 + * @param radix The radix (base) for this numbering system. 1.100 + * @param isAlgorithmic TRUE if the numbering system is algorithmic rather than numeric. 1.101 + * @param description The string representing the set of digits used in a numeric system, or the name of the RBNF 1.102 + * ruleset to be used in an algorithmic system. 1.103 + * @param status ICU status 1.104 + * @stable ICU 4.2 1.105 + */ 1.106 + static NumberingSystem* U_EXPORT2 createInstance(int32_t radix, UBool isAlgorithmic, const UnicodeString& description, UErrorCode& status ); 1.107 + 1.108 + /** 1.109 + * Return a StringEnumeration over all the names of numbering systems known to ICU. 1.110 + * @stable ICU 4.2 1.111 + */ 1.112 + 1.113 + static StringEnumeration * U_EXPORT2 getAvailableNames(UErrorCode& status); 1.114 + 1.115 + /** 1.116 + * Create a numbering system from one of the predefined numbering systems specified 1.117 + * by CLDR and known to ICU, such as "latn", "arabext", or "hanidec"; the full list 1.118 + * is returned by unumsys_openAvailableNames. Note that some of the names listed at 1.119 + * http://unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml - e.g. 1.120 + * default, native, traditional, finance - do not identify specific numbering systems, 1.121 + * but rather key values that may only be used as part of a locale, which in turn 1.122 + * defines how they are mapped to a specific numbering system such as "latn" or "hant". 1.123 + * @param name The name of the numbering system. 1.124 + * @param status ICU status 1.125 + * @stable ICU 4.2 1.126 + */ 1.127 + static NumberingSystem* U_EXPORT2 createInstanceByName(const char* name, UErrorCode& status); 1.128 + 1.129 + 1.130 + /** 1.131 + * Returns the radix of this numbering system. Simple positional numbering systems 1.132 + * typically have radix 10, but might have a radix of e.g. 16 for hexadecimal. The 1.133 + * radix is less well-defined for non-positional algorithmic systems. 1.134 + * @stable ICU 4.2 1.135 + */ 1.136 + int32_t getRadix() const; 1.137 + 1.138 + /** 1.139 + * Returns the name of this numbering system if it was created using one of the predefined names 1.140 + * known to ICU. Otherwise, returns NULL. 1.141 + * @stable ICU 4.6 1.142 + */ 1.143 + const char * getName() const; 1.144 + 1.145 + /** 1.146 + * Returns the description string of this numbering system. For simple 1.147 + * positional systems this is the ordered string of digits (with length matching 1.148 + * the radix), e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D" 1.149 + * for "hanidec"; it would be "0123456789ABCDEF" for hexadecimal. For 1.150 + * algorithmic systems this is the name of the RBNF ruleset used for formatting, 1.151 + * e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for 1.152 + * "grek". 1.153 + * @stable ICU 4.2 1.154 + */ 1.155 + virtual UnicodeString getDescription() const; 1.156 + 1.157 + 1.158 + 1.159 + /** 1.160 + * Returns TRUE if the given numbering system is algorithmic 1.161 + * 1.162 + * @return TRUE if the numbering system is algorithmic. 1.163 + * Otherwise, return FALSE. 1.164 + * @stable ICU 4.2 1.165 + */ 1.166 + UBool isAlgorithmic() const; 1.167 + 1.168 + /** 1.169 + * ICU "poor man's RTTI", returns a UClassID for this class. 1.170 + * 1.171 + * @stable ICU 4.2 1.172 + * 1.173 + */ 1.174 + static UClassID U_EXPORT2 getStaticClassID(void); 1.175 + 1.176 + /** 1.177 + * ICU "poor man's RTTI", returns a UClassID for the actual class. 1.178 + * 1.179 + * @stable ICU 4.2 1.180 + */ 1.181 + virtual UClassID getDynamicClassID() const; 1.182 + 1.183 + 1.184 +private: 1.185 + UnicodeString desc; 1.186 + int32_t radix; 1.187 + UBool algorithmic; 1.188 + char name[NUMSYS_NAME_CAPACITY+1]; 1.189 + 1.190 + void setRadix(int32_t radix); 1.191 + 1.192 + void setAlgorithmic(UBool algorithmic); 1.193 + 1.194 + void setDesc(UnicodeString desc); 1.195 + 1.196 + void setName(const char* name); 1.197 + 1.198 + static UBool isValidDigitString(const UnicodeString &str); 1.199 + 1.200 + UBool hasContiguousDecimalDigits() const; 1.201 +}; 1.202 + 1.203 +U_NAMESPACE_END 1.204 + 1.205 +#endif /* #if !UCONFIG_NO_FORMATTING */ 1.206 + 1.207 +#endif // _NUMSYS 1.208 +//eof