unumsys.h 7.0 KB

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