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