unumsys.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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) 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. * @param status A pointer to a UErrorCode to receive any errors.
  96. * @return A pointer to a UEnumeration that must be closed with uenum_close(),
  97. * or NULL if an error occurred.
  98. * @stable ICU 52
  99. */
  100. U_STABLE UEnumeration * U_EXPORT2
  101. unumsys_openAvailableNames(UErrorCode *status);
  102. /**
  103. * Returns the name of the specified UNumberingSystem object (if it is one of the
  104. * predefined names known to ICU).
  105. * @param unumsys The UNumberingSystem whose name is desired.
  106. * @return A pointer to the name of the specified UNumberingSystem object, or
  107. * NULL if the name is not one of the ICU predefined names. The pointer
  108. * is only valid for the lifetime of the UNumberingSystem object.
  109. * @stable ICU 52
  110. */
  111. U_STABLE const char * U_EXPORT2
  112. unumsys_getName(const UNumberingSystem *unumsys);
  113. /**
  114. * Returns whether the given UNumberingSystem object is for an algorithmic (not purely
  115. * positional) system.
  116. * @param unumsys The UNumberingSystem whose algorithmic status is desired.
  117. * @return TRUE if the specified UNumberingSystem object is for an algorithmic
  118. * system.
  119. * @stable ICU 52
  120. */
  121. U_STABLE UBool U_EXPORT2
  122. unumsys_isAlgorithmic(const UNumberingSystem *unumsys);
  123. /**
  124. * Returns the radix of the specified UNumberingSystem object. Simple positional
  125. * numbering systems typically have radix 10, but might have a radix of e.g. 16 for
  126. * hexadecimal. The radix is less well-defined for non-positional algorithmic systems.
  127. * @param unumsys The UNumberingSystem whose radix is desired.
  128. * @return The radix of the specified UNumberingSystem object.
  129. * @stable ICU 52
  130. */
  131. U_STABLE int32_t U_EXPORT2
  132. unumsys_getRadix(const UNumberingSystem *unumsys);
  133. /**
  134. * Get the description string of the specified UNumberingSystem object. For simple
  135. * positional systems this is the ordered string of digits (with length matching
  136. * the radix), e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D"
  137. * for "hanidec"; it would be "0123456789ABCDEF" for hexadecimal. For
  138. * algorithmic systems this is the name of the RBNF ruleset used for formatting,
  139. * e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for
  140. * "grek".
  141. * @param unumsys The UNumberingSystem whose description string is desired.
  142. * @param result A pointer to a buffer to receive the description string.
  143. * @param resultLength The maximum size of result.
  144. * @param status A pointer to a UErrorCode to receive any errors.
  145. * @return The total buffer size needed; if greater than resultLength, the
  146. * output was truncated.
  147. * @stable ICU 52
  148. */
  149. U_STABLE int32_t U_EXPORT2
  150. unumsys_getDescription(const UNumberingSystem *unumsys, UChar *result,
  151. int32_t resultLength, UErrorCode *status);
  152. #endif /* #if !UCONFIG_NO_FORMATTING */
  153. #endif