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