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