unumsys.h 7.3 KB

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