numsys.h 6.6 KB

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