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