michael@0: /* michael@0: ******************************************************************************* michael@0: * Copyright (C) 2010-2013, International Business Machines Corporation and michael@0: * others. All Rights Reserved. michael@0: ******************************************************************************* michael@0: * michael@0: * michael@0: * File NUMSYS.H michael@0: * michael@0: * Modification History:* michael@0: * Date Name Description michael@0: * michael@0: ******************************************************************************** michael@0: */ michael@0: michael@0: #ifndef NUMSYS michael@0: #define NUMSYS michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: /** michael@0: * \def NUMSYS_NAME_CAPACITY michael@0: * Size of a numbering system name. michael@0: * @internal michael@0: */ michael@0: #define NUMSYS_NAME_CAPACITY 8 michael@0: michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: NumberingSystem object michael@0: */ michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: michael@0: #include "unicode/format.h" michael@0: #include "unicode/uobject.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: /** michael@0: * Defines numbering systems. A numbering system describes the scheme by which michael@0: * numbers are to be presented to the end user. In its simplest form, a numbering michael@0: * system describes the set of digit characters that are to be used to display michael@0: * numbers, such as Western digits, Thai digits, Arabic-Indic digits, etc., in a michael@0: * positional numbering system with a specified radix (typically 10). michael@0: * More complicated numbering systems are algorithmic in nature, and require use michael@0: * of an RBNF formatter ( rule based number formatter ), in order to calculate michael@0: * the characters to be displayed for a given number. Examples of algorithmic michael@0: * numbering systems include Roman numerals, Chinese numerals, and Hebrew numerals. michael@0: * Formatting rules for many commonly used numbering systems are included in michael@0: * the ICU package, based on the numbering system rules defined in CLDR. michael@0: * Alternate numbering systems can be specified to a locale by using the michael@0: * numbers locale keyword. michael@0: */ michael@0: michael@0: class U_I18N_API NumberingSystem : public UObject { michael@0: public: michael@0: michael@0: /** michael@0: * Default Constructor. michael@0: * michael@0: * @stable ICU 4.2 michael@0: */ michael@0: NumberingSystem(); michael@0: michael@0: /** michael@0: * Copy constructor. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: NumberingSystem(const NumberingSystem& other); michael@0: michael@0: /** michael@0: * Destructor. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: virtual ~NumberingSystem(); michael@0: michael@0: /** michael@0: * Create the default numbering system associated with the specified locale. michael@0: * @param inLocale The given locale. michael@0: * @param status ICU status michael@0: * @stable ICU 4.2 michael@0: */ michael@0: static NumberingSystem* U_EXPORT2 createInstance(const Locale & inLocale, UErrorCode& status); michael@0: michael@0: /** michael@0: * Create the default numbering system associated with the default locale. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: static NumberingSystem* U_EXPORT2 createInstance(UErrorCode& status); michael@0: michael@0: /** michael@0: * Create a numbering system using the specified radix, type, and description. michael@0: * @param radix The radix (base) for this numbering system. michael@0: * @param isAlgorithmic TRUE if the numbering system is algorithmic rather than numeric. michael@0: * @param description The string representing the set of digits used in a numeric system, or the name of the RBNF michael@0: * ruleset to be used in an algorithmic system. michael@0: * @param status ICU status michael@0: * @stable ICU 4.2 michael@0: */ michael@0: static NumberingSystem* U_EXPORT2 createInstance(int32_t radix, UBool isAlgorithmic, const UnicodeString& description, UErrorCode& status ); michael@0: michael@0: /** michael@0: * Return a StringEnumeration over all the names of numbering systems known to ICU. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: michael@0: static StringEnumeration * U_EXPORT2 getAvailableNames(UErrorCode& status); michael@0: michael@0: /** michael@0: * Create a numbering system from one of the predefined numbering systems specified michael@0: * by CLDR and known to ICU, such as "latn", "arabext", or "hanidec"; the full list michael@0: * is returned by unumsys_openAvailableNames. Note that some of the names listed at michael@0: * http://unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml - e.g. michael@0: * default, native, traditional, finance - do not identify specific numbering systems, michael@0: * but rather key values that may only be used as part of a locale, which in turn michael@0: * defines how they are mapped to a specific numbering system such as "latn" or "hant". michael@0: * @param name The name of the numbering system. michael@0: * @param status ICU status michael@0: * @stable ICU 4.2 michael@0: */ michael@0: static NumberingSystem* U_EXPORT2 createInstanceByName(const char* name, UErrorCode& status); michael@0: michael@0: michael@0: /** michael@0: * Returns the radix of this numbering system. Simple positional numbering systems michael@0: * typically have radix 10, but might have a radix of e.g. 16 for hexadecimal. The michael@0: * radix is less well-defined for non-positional algorithmic systems. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: int32_t getRadix() const; michael@0: michael@0: /** michael@0: * Returns the name of this numbering system if it was created using one of the predefined names michael@0: * known to ICU. Otherwise, returns NULL. michael@0: * @stable ICU 4.6 michael@0: */ michael@0: const char * getName() const; michael@0: michael@0: /** michael@0: * Returns the description string of this numbering system. For simple michael@0: * positional systems this is the ordered string of digits (with length matching michael@0: * the radix), e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D" michael@0: * for "hanidec"; it would be "0123456789ABCDEF" for hexadecimal. For michael@0: * algorithmic systems this is the name of the RBNF ruleset used for formatting, michael@0: * e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for michael@0: * "grek". michael@0: * @stable ICU 4.2 michael@0: */ michael@0: virtual UnicodeString getDescription() const; michael@0: michael@0: michael@0: michael@0: /** michael@0: * Returns TRUE if the given numbering system is algorithmic michael@0: * michael@0: * @return TRUE if the numbering system is algorithmic. michael@0: * Otherwise, return FALSE. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: UBool isAlgorithmic() const; michael@0: michael@0: /** michael@0: * ICU "poor man's RTTI", returns a UClassID for this class. michael@0: * michael@0: * @stable ICU 4.2 michael@0: * michael@0: */ michael@0: static UClassID U_EXPORT2 getStaticClassID(void); michael@0: michael@0: /** michael@0: * ICU "poor man's RTTI", returns a UClassID for the actual class. michael@0: * michael@0: * @stable ICU 4.2 michael@0: */ michael@0: virtual UClassID getDynamicClassID() const; michael@0: michael@0: michael@0: private: michael@0: UnicodeString desc; michael@0: int32_t radix; michael@0: UBool algorithmic; michael@0: char name[NUMSYS_NAME_CAPACITY+1]; michael@0: michael@0: void setRadix(int32_t radix); michael@0: michael@0: void setAlgorithmic(UBool algorithmic); michael@0: michael@0: void setDesc(UnicodeString desc); michael@0: michael@0: void setName(const char* name); michael@0: michael@0: static UBool isValidDigitString(const UnicodeString &str); michael@0: michael@0: UBool hasContiguousDecimalDigits() const; michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: michael@0: #endif // _NUMSYS michael@0: //eof