unumsys.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. *****************************************************************************************
  5. * Copyright (C) 2013-2014, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. *****************************************************************************************
  8. */
  9. #ifndef UNUMSYS_H
  10. #define UNUMSYS_H
  11. #include "unicode/utypes.h"
  12. #if !UCONFIG_NO_FORMATTING
  13. #include "unicode/uenum.h"
  14. #include "unicode/localpointer.h"
  15. /**
  16. * \file
  17. * \brief C API: UNumberingSystem, information about numbering systems
  18. *
  19. * Defines numbering systems. A numbering system describes the scheme by which
  20. * numbers are to be presented to the end user. In its simplest form, a numbering
  21. * system describes the set of digit characters that are to be used to display
  22. * numbers, such as Western digits, Thai digits, Arabic-Indic digits, etc., in a
  23. * positional numbering system with a specified radix (typically 10).
  24. * More complicated numbering systems are algorithmic in nature, and require use
  25. * of an RBNF formatter (rule based number formatter), in order to calculate
  26. * the characters to be displayed for a given number. Examples of algorithmic
  27. * numbering systems include Roman numerals, Chinese numerals, and Hebrew numerals.
  28. * Formatting rules for many commonly used numbering systems are included in
  29. * the ICU package, based on the numbering system rules defined in CLDR.
  30. * Alternate numbering systems can be specified to a locale by using the
  31. * numbers locale keyword.
  32. */
  33. /**
  34. * Opaque UNumberingSystem object for use in C programs.
  35. * @stable ICU 52
  36. */
  37. struct UNumberingSystem;
  38. typedef struct UNumberingSystem UNumberingSystem; /**< C typedef for struct UNumberingSystem. @stable ICU 52 */
  39. /**
  40. * Opens a UNumberingSystem object using the default numbering system for the specified
  41. * locale.
  42. * @param locale The locale for which the default numbering system should be opened.
  43. * @param status A pointer to a UErrorCode to receive any errors. For example, this
  44. * may be U_UNSUPPORTED_ERROR for a locale such as "en@numbers=xyz" that
  45. * specifies a numbering system unknown to ICU.
  46. * @return A UNumberingSystem for the specified locale, or NULL if an error
  47. * occurred.
  48. * @stable ICU 52
  49. */
  50. U_STABLE UNumberingSystem * U_EXPORT2
  51. unumsys_open(const char *locale, UErrorCode *status);
  52. /**
  53. * Opens a UNumberingSystem object using the name of one of the predefined numbering
  54. * systems specified by CLDR and known to ICU, such as "latn", "arabext", or "hanidec";
  55. * the full list is returned by unumsys_openAvailableNames. Note that some of the names
  56. * listed at http://unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml - e.g.
  57. * default, native, traditional, finance - do not identify specific numbering systems,
  58. * but rather key values that may only be used as part of a locale, which in turn
  59. * defines how they are mapped to a specific numbering system such as "latn" or "hant".
  60. *
  61. * @param name The name of the numbering system for which a UNumberingSystem object
  62. * should be opened.
  63. * @param status A pointer to a UErrorCode to receive any errors. For example, this
  64. * may be U_UNSUPPORTED_ERROR for a numbering system such as "xyz" that
  65. * is unknown to ICU.
  66. * @return A UNumberingSystem for the specified name, or NULL if an error
  67. * occurred.
  68. * @stable ICU 52
  69. */
  70. U_STABLE UNumberingSystem * U_EXPORT2
  71. unumsys_openByName(const char *name, UErrorCode *status);
  72. /**
  73. * Close a UNumberingSystem object. Once closed it may no longer be used.
  74. * @param unumsys The UNumberingSystem object to close.
  75. * @stable ICU 52
  76. */
  77. U_STABLE void U_EXPORT2
  78. unumsys_close(UNumberingSystem *unumsys);
  79. #if U_SHOW_CPLUSPLUS_API
  80. U_NAMESPACE_BEGIN
  81. /**
  82. * \class LocalUNumberingSystemPointer
  83. * "Smart pointer" class, closes a UNumberingSystem via unumsys_close().
  84. * For most methods see the LocalPointerBase base class.
  85. * @see LocalPointerBase
  86. * @see LocalPointer
  87. * @stable ICU 52
  88. */
  89. U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberingSystemPointer, UNumberingSystem, unumsys_close);
  90. U_NAMESPACE_END
  91. #endif
  92. /**
  93. * Returns an enumeration over the names of all of the predefined numbering systems known
  94. * to ICU.
  95. * The numbering system names will be in alphabetical (invariant) order.
  96. * @param status A pointer to a UErrorCode to receive any errors.
  97. * @return A pointer to a UEnumeration that must be closed with uenum_close(),
  98. * or NULL if an error occurred.
  99. * @stable ICU 52
  100. */
  101. U_STABLE UEnumeration * U_EXPORT2
  102. unumsys_openAvailableNames(UErrorCode *status);
  103. /**
  104. * Returns the name of the specified UNumberingSystem object (if it is one of the
  105. * predefined names known to ICU).
  106. * @param unumsys The UNumberingSystem whose name is desired.
  107. * @return A pointer to the name of the specified UNumberingSystem object, or
  108. * NULL if the name is not one of the ICU predefined names. The pointer
  109. * is only valid for the lifetime of the UNumberingSystem object.
  110. * @stable ICU 52
  111. */
  112. U_STABLE const char * U_EXPORT2
  113. unumsys_getName(const UNumberingSystem *unumsys);
  114. /**
  115. * Returns whether the given UNumberingSystem object is for an algorithmic (not purely
  116. * positional) system.
  117. * @param unumsys The UNumberingSystem whose algorithmic status is desired.
  118. * @return TRUE if the specified UNumberingSystem object is for an algorithmic
  119. * system.
  120. * @stable ICU 52
  121. */
  122. U_STABLE UBool U_EXPORT2
  123. unumsys_isAlgorithmic(const UNumberingSystem *unumsys);
  124. /**
  125. * Returns the radix of the specified UNumberingSystem object. Simple positional
  126. * numbering systems typically have radix 10, but might have a radix of e.g. 16 for
  127. * hexadecimal. The radix is less well-defined for non-positional algorithmic systems.
  128. * @param unumsys The UNumberingSystem whose radix is desired.
  129. * @return The radix of the specified UNumberingSystem object.
  130. * @stable ICU 52
  131. */
  132. U_STABLE int32_t U_EXPORT2
  133. unumsys_getRadix(const UNumberingSystem *unumsys);
  134. /**
  135. * Get the description string of the specified UNumberingSystem object. For simple
  136. * positional systems this is the ordered string of digits (with length matching
  137. * the radix), e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D"
  138. * for "hanidec"; it would be "0123456789ABCDEF" for hexadecimal. For
  139. * algorithmic systems this is the name of the RBNF ruleset used for formatting,
  140. * e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for
  141. * "grek".
  142. * @param unumsys The UNumberingSystem whose description string is desired.
  143. * @param result A pointer to a buffer to receive the description string.
  144. * @param resultLength The maximum size of result.
  145. * @param status A pointer to a UErrorCode to receive any errors.
  146. * @return The total buffer size needed; if greater than resultLength, the
  147. * output was truncated.
  148. * @stable ICU 52
  149. */
  150. U_STABLE int32_t U_EXPORT2
  151. unumsys_getDescription(const UNumberingSystem *unumsys, UChar *result,
  152. int32_t resultLength, UErrorCode *status);
  153. #endif /* #if !UCONFIG_NO_FORMATTING */
  154. #endif