numsys.h 6.7 KB

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