numsys.h 7.2 KB

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