xref: /aosp_15_r20/external/icu/libicu/cts_headers/unicode/ulocale.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2023 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 #ifndef ULOCALE_H
5*0e209d39SAndroid Build Coastguard Worker #define ULOCALE_H
6*0e209d39SAndroid Build Coastguard Worker 
7*0e209d39SAndroid Build Coastguard Worker #include "unicode/localpointer.h"
8*0e209d39SAndroid Build Coastguard Worker #include "unicode/uenum.h"
9*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
10*0e209d39SAndroid Build Coastguard Worker 
11*0e209d39SAndroid Build Coastguard Worker /**
12*0e209d39SAndroid Build Coastguard Worker  * \file
13*0e209d39SAndroid Build Coastguard Worker  * \brief C API: Locale ID functionality similar to C++ class Locale
14*0e209d39SAndroid Build Coastguard Worker  */
15*0e209d39SAndroid Build Coastguard Worker 
16*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DRAFT_API
17*0e209d39SAndroid Build Coastguard Worker /**
18*0e209d39SAndroid Build Coastguard Worker  * Opaque C service object type for the locale API
19*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
20*0e209d39SAndroid Build Coastguard Worker  */
21*0e209d39SAndroid Build Coastguard Worker struct ULocale;
22*0e209d39SAndroid Build Coastguard Worker 
23*0e209d39SAndroid Build Coastguard Worker /**
24*0e209d39SAndroid Build Coastguard Worker  * C typedef for struct ULocale.
25*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
26*0e209d39SAndroid Build Coastguard Worker  */
27*0e209d39SAndroid Build Coastguard Worker typedef struct ULocale ULocale;
28*0e209d39SAndroid Build Coastguard Worker 
29*0e209d39SAndroid Build Coastguard Worker /**
30*0e209d39SAndroid Build Coastguard Worker  * Constructs an ULocale from the locale ID.
31*0e209d39SAndroid Build Coastguard Worker  * The created ULocale should be destroyed by calling
32*0e209d39SAndroid Build Coastguard Worker  * ulocale_close();
33*0e209d39SAndroid Build Coastguard Worker  * @param localeID the locale, a const char * pointer (need not be terminated when
34*0e209d39SAndroid Build Coastguard Worker  *               the length is non-negative)
35*0e209d39SAndroid Build Coastguard Worker  * @param length the length of the locale; if negative, then the locale need to be
36*0e209d39SAndroid Build Coastguard Worker  *               null terminated.
37*0e209d39SAndroid Build Coastguard Worker  * @param err the error code
38*0e209d39SAndroid Build Coastguard Worker  * @return the locale.
39*0e209d39SAndroid Build Coastguard Worker  *
40*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
41*0e209d39SAndroid Build Coastguard Worker  */
42*0e209d39SAndroid Build Coastguard Worker U_CAPI ULocale* U_EXPORT2
43*0e209d39SAndroid Build Coastguard Worker ulocale_openForLocaleID(const char* localeID, int32_t length, UErrorCode* err);
44*0e209d39SAndroid Build Coastguard Worker 
45*0e209d39SAndroid Build Coastguard Worker /**
46*0e209d39SAndroid Build Coastguard Worker  * Constructs an ULocale from the provided IETF BCP 47 language tag.
47*0e209d39SAndroid Build Coastguard Worker  * The created ULocale should be destroyed by calling
48*0e209d39SAndroid Build Coastguard Worker  * ulocale_close();
49*0e209d39SAndroid Build Coastguard Worker  * @param tag the language tag, defined as IETF BCP 47 language tag, const
50*0e209d39SAndroid Build Coastguard Worker  *            char* pointer (need not be terminated when the length is non-negative)
51*0e209d39SAndroid Build Coastguard Worker  * @param length the length of the tag; if negative, then the tag need to be
52*0e209d39SAndroid Build Coastguard Worker  *               null terminated.
53*0e209d39SAndroid Build Coastguard Worker  * @param err the error code
54*0e209d39SAndroid Build Coastguard Worker  * @return the locale.
55*0e209d39SAndroid Build Coastguard Worker  *
56*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
57*0e209d39SAndroid Build Coastguard Worker  */
58*0e209d39SAndroid Build Coastguard Worker U_CAPI ULocale* U_EXPORT2
59*0e209d39SAndroid Build Coastguard Worker ulocale_openForLanguageTag(const char* tag, int32_t length, UErrorCode* err);
60*0e209d39SAndroid Build Coastguard Worker 
61*0e209d39SAndroid Build Coastguard Worker /**
62*0e209d39SAndroid Build Coastguard Worker  * Close the locale and destroy it's internal states.
63*0e209d39SAndroid Build Coastguard Worker  *
64*0e209d39SAndroid Build Coastguard Worker  * @param locale the locale
65*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
66*0e209d39SAndroid Build Coastguard Worker  */
67*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
68*0e209d39SAndroid Build Coastguard Worker ulocale_close(ULocale* locale);
69*0e209d39SAndroid Build Coastguard Worker 
70*0e209d39SAndroid Build Coastguard Worker /**
71*0e209d39SAndroid Build Coastguard Worker  * Returns the locale's ISO-639 language code.
72*0e209d39SAndroid Build Coastguard Worker  *
73*0e209d39SAndroid Build Coastguard Worker  * @param locale the locale
74*0e209d39SAndroid Build Coastguard Worker  * @return      the language code of the locale.
75*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
76*0e209d39SAndroid Build Coastguard Worker  */
77*0e209d39SAndroid Build Coastguard Worker U_CAPI const char* U_EXPORT2
78*0e209d39SAndroid Build Coastguard Worker ulocale_getLanguage(const ULocale* locale);
79*0e209d39SAndroid Build Coastguard Worker 
80*0e209d39SAndroid Build Coastguard Worker /**
81*0e209d39SAndroid Build Coastguard Worker  * Returns the locale's ISO-15924 abbreviation script code.
82*0e209d39SAndroid Build Coastguard Worker  *
83*0e209d39SAndroid Build Coastguard Worker  * @param locale the locale
84*0e209d39SAndroid Build Coastguard Worker  * @return      A pointer to the script.
85*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
86*0e209d39SAndroid Build Coastguard Worker  */
87*0e209d39SAndroid Build Coastguard Worker U_CAPI const char* U_EXPORT2
88*0e209d39SAndroid Build Coastguard Worker ulocale_getScript(const ULocale* locale);
89*0e209d39SAndroid Build Coastguard Worker 
90*0e209d39SAndroid Build Coastguard Worker /**
91*0e209d39SAndroid Build Coastguard Worker  * Returns the locale's ISO-3166 region code.
92*0e209d39SAndroid Build Coastguard Worker  *
93*0e209d39SAndroid Build Coastguard Worker  * @param locale the locale
94*0e209d39SAndroid Build Coastguard Worker  * @return      A pointer to the region.
95*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
96*0e209d39SAndroid Build Coastguard Worker  */
97*0e209d39SAndroid Build Coastguard Worker U_CAPI const char* U_EXPORT2
98*0e209d39SAndroid Build Coastguard Worker ulocale_getRegion(const ULocale* locale);
99*0e209d39SAndroid Build Coastguard Worker 
100*0e209d39SAndroid Build Coastguard Worker /**
101*0e209d39SAndroid Build Coastguard Worker  * Returns the locale's variant code.
102*0e209d39SAndroid Build Coastguard Worker  *
103*0e209d39SAndroid Build Coastguard Worker  * @param locale the locale
104*0e209d39SAndroid Build Coastguard Worker  * @return      A pointer to the variant.
105*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
106*0e209d39SAndroid Build Coastguard Worker  */
107*0e209d39SAndroid Build Coastguard Worker U_CAPI const char* U_EXPORT2
108*0e209d39SAndroid Build Coastguard Worker ulocale_getVariant(const ULocale* locale);
109*0e209d39SAndroid Build Coastguard Worker 
110*0e209d39SAndroid Build Coastguard Worker /**
111*0e209d39SAndroid Build Coastguard Worker  * Returns the programmatic name of the entire locale, with the language,
112*0e209d39SAndroid Build Coastguard Worker  * country and variant separated by underbars. If a field is missing, up
113*0e209d39SAndroid Build Coastguard Worker  * to two leading underbars will occur. Example: "en", "de_DE", "en_US_WIN",
114*0e209d39SAndroid Build Coastguard Worker  * "de__POSIX", "fr__MAC", "__MAC", "_MT", "_FR_EURO"
115*0e209d39SAndroid Build Coastguard Worker  *
116*0e209d39SAndroid Build Coastguard Worker  * @param locale the locale
117*0e209d39SAndroid Build Coastguard Worker  * @return      A pointer to "name".
118*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
119*0e209d39SAndroid Build Coastguard Worker  */
120*0e209d39SAndroid Build Coastguard Worker U_CAPI const char* U_EXPORT2
121*0e209d39SAndroid Build Coastguard Worker ulocale_getLocaleID(const ULocale* locale);
122*0e209d39SAndroid Build Coastguard Worker 
123*0e209d39SAndroid Build Coastguard Worker /**
124*0e209d39SAndroid Build Coastguard Worker  * Returns the programmatic name of the entire locale as ulocale_getLocaleID()
125*0e209d39SAndroid Build Coastguard Worker  * would return, but without keywords.
126*0e209d39SAndroid Build Coastguard Worker  *
127*0e209d39SAndroid Build Coastguard Worker  * @param locale the locale
128*0e209d39SAndroid Build Coastguard Worker  * @return      A pointer to "base name".
129*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
130*0e209d39SAndroid Build Coastguard Worker  */
131*0e209d39SAndroid Build Coastguard Worker U_CAPI const char* U_EXPORT2
132*0e209d39SAndroid Build Coastguard Worker ulocale_getBaseName(const ULocale* locale);
133*0e209d39SAndroid Build Coastguard Worker 
134*0e209d39SAndroid Build Coastguard Worker /**
135*0e209d39SAndroid Build Coastguard Worker  * Gets the bogus state. Locale object can be bogus if it doesn't exist
136*0e209d39SAndroid Build Coastguard Worker  *
137*0e209d39SAndroid Build Coastguard Worker  * @param locale the locale
138*0e209d39SAndroid Build Coastguard Worker  * @return false if it is a real locale, true if it is a bogus locale
139*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
140*0e209d39SAndroid Build Coastguard Worker  */
141*0e209d39SAndroid Build Coastguard Worker U_CAPI bool U_EXPORT2
142*0e209d39SAndroid Build Coastguard Worker ulocale_isBogus(const ULocale* locale);
143*0e209d39SAndroid Build Coastguard Worker 
144*0e209d39SAndroid Build Coastguard Worker /**
145*0e209d39SAndroid Build Coastguard Worker  * Gets the list of keywords for the specified locale.
146*0e209d39SAndroid Build Coastguard Worker  *
147*0e209d39SAndroid Build Coastguard Worker  * @param locale the locale
148*0e209d39SAndroid Build Coastguard Worker  * @param err the error code
149*0e209d39SAndroid Build Coastguard Worker  * @return pointer to UEnumeration, or nullptr if there are no keywords.
150*0e209d39SAndroid Build Coastguard Worker  * Client must call uenum_close() to dispose the returned value.
151*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
152*0e209d39SAndroid Build Coastguard Worker  */
153*0e209d39SAndroid Build Coastguard Worker U_CAPI UEnumeration* U_EXPORT2
154*0e209d39SAndroid Build Coastguard Worker ulocale_getKeywords(const ULocale* locale, UErrorCode *err);
155*0e209d39SAndroid Build Coastguard Worker 
156*0e209d39SAndroid Build Coastguard Worker /**
157*0e209d39SAndroid Build Coastguard Worker  * Gets the list of unicode keywords for the specified locale.
158*0e209d39SAndroid Build Coastguard Worker  *
159*0e209d39SAndroid Build Coastguard Worker  * @param locale the locale
160*0e209d39SAndroid Build Coastguard Worker  * @param err the error code
161*0e209d39SAndroid Build Coastguard Worker  * @return pointer to UEnumeration, or nullptr if there are no keywords.
162*0e209d39SAndroid Build Coastguard Worker  * Client must call uenum_close() to dispose the returned value.
163*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
164*0e209d39SAndroid Build Coastguard Worker  */
165*0e209d39SAndroid Build Coastguard Worker U_CAPI UEnumeration* U_EXPORT2
166*0e209d39SAndroid Build Coastguard Worker ulocale_getUnicodeKeywords(const ULocale* locale, UErrorCode *err);
167*0e209d39SAndroid Build Coastguard Worker 
168*0e209d39SAndroid Build Coastguard Worker /**
169*0e209d39SAndroid Build Coastguard Worker  * Gets the value for a keyword.
170*0e209d39SAndroid Build Coastguard Worker  *
171*0e209d39SAndroid Build Coastguard Worker  * This uses legacy keyword=value pairs, like "collation=phonebook".
172*0e209d39SAndroid Build Coastguard Worker  *
173*0e209d39SAndroid Build Coastguard Worker  * @param locale the locale
174*0e209d39SAndroid Build Coastguard Worker  * @param keyword the keyword, a const char * pointer (need not be
175*0e209d39SAndroid Build Coastguard Worker  *                terminated when the length is non-negative)
176*0e209d39SAndroid Build Coastguard Worker  * @param keywordLength the length of the keyword; if negative, then the
177*0e209d39SAndroid Build Coastguard Worker  *                      keyword need to be null terminated.
178*0e209d39SAndroid Build Coastguard Worker  * @param valueBuffer The buffer to receive the value.
179*0e209d39SAndroid Build Coastguard Worker  * @param valueBufferCapacity The capacity of receiving valueBuffer.
180*0e209d39SAndroid Build Coastguard Worker  * @param err the error code
181*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
182*0e209d39SAndroid Build Coastguard Worker  */
183*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
184*0e209d39SAndroid Build Coastguard Worker ulocale_getKeywordValue(
185*0e209d39SAndroid Build Coastguard Worker     const ULocale* locale, const char* keyword, int32_t keywordLength,
186*0e209d39SAndroid Build Coastguard Worker     char* valueBuffer, int32_t valueBufferCapacity, UErrorCode *err);
187*0e209d39SAndroid Build Coastguard Worker 
188*0e209d39SAndroid Build Coastguard Worker /**
189*0e209d39SAndroid Build Coastguard Worker  * Gets the Unicode value for a Unicode keyword.
190*0e209d39SAndroid Build Coastguard Worker  *
191*0e209d39SAndroid Build Coastguard Worker  * This uses Unicode key-value pairs, like "co-phonebk".
192*0e209d39SAndroid Build Coastguard Worker  *
193*0e209d39SAndroid Build Coastguard Worker  * @param locale the locale
194*0e209d39SAndroid Build Coastguard Worker  * @param keyword the Unicode keyword, a const char * pointer (need not be
195*0e209d39SAndroid Build Coastguard Worker  *                terminated when the length is non-negative)
196*0e209d39SAndroid Build Coastguard Worker  * @param keywordLength the length of the Unicode keyword; if negative,
197*0e209d39SAndroid Build Coastguard Worker  *                      then the keyword need to be null terminated.
198*0e209d39SAndroid Build Coastguard Worker  * @param valueBuffer The buffer to receive the Unicode value.
199*0e209d39SAndroid Build Coastguard Worker  * @param valueBufferCapacity The capacity of receiving valueBuffer.
200*0e209d39SAndroid Build Coastguard Worker  * @param err the error code
201*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
202*0e209d39SAndroid Build Coastguard Worker  */
203*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
204*0e209d39SAndroid Build Coastguard Worker ulocale_getUnicodeKeywordValue(
205*0e209d39SAndroid Build Coastguard Worker     const ULocale* locale, const char* keyword, int32_t keywordLength,
206*0e209d39SAndroid Build Coastguard Worker     char* valueBuffer, int32_t valueBufferCapacity, UErrorCode *err);
207*0e209d39SAndroid Build Coastguard Worker 
208*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
209*0e209d39SAndroid Build Coastguard Worker 
210*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
211*0e209d39SAndroid Build Coastguard Worker 
212*0e209d39SAndroid Build Coastguard Worker /**
213*0e209d39SAndroid Build Coastguard Worker  * \class LocalULocalePointer
214*0e209d39SAndroid Build Coastguard Worker  * "Smart pointer" class, closes a ULocale via ulocale_close().
215*0e209d39SAndroid Build Coastguard Worker  * For most methods see the LocalPointerBase base class.
216*0e209d39SAndroid Build Coastguard Worker  *
217*0e209d39SAndroid Build Coastguard Worker  * @see LocalPointerBase
218*0e209d39SAndroid Build Coastguard Worker  * @see LocalPointer
219*0e209d39SAndroid Build Coastguard Worker  * @draft ICU 74
220*0e209d39SAndroid Build Coastguard Worker  */
221*0e209d39SAndroid Build Coastguard Worker U_DEFINE_LOCAL_OPEN_POINTER(LocalULocalePointer, ULocale, ulocale_close);
222*0e209d39SAndroid Build Coastguard Worker 
223*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
224*0e209d39SAndroid Build Coastguard Worker 
225*0e209d39SAndroid Build Coastguard Worker #endif  /* U_SHOW_CPLUSPLUS_API */
226*0e209d39SAndroid Build Coastguard Worker 
227*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_DRAFT_API */
228*0e209d39SAndroid Build Coastguard Worker 
229*0e209d39SAndroid Build Coastguard Worker #endif /*_ULOCALE */
230