xref: /aosp_15_r20/external/icu/libicu/cts_headers/unicode/uregion.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) 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 UREGION_H
11*0e209d39SAndroid Build Coastguard Worker #define UREGION_H
12*0e209d39SAndroid Build Coastguard Worker 
13*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
14*0e209d39SAndroid Build Coastguard Worker #include "unicode/uenum.h"
15*0e209d39SAndroid Build Coastguard Worker 
16*0e209d39SAndroid Build Coastguard Worker /**
17*0e209d39SAndroid Build Coastguard Worker  * \file
18*0e209d39SAndroid Build Coastguard Worker  * \brief C API: URegion (territory containment and mapping)
19*0e209d39SAndroid Build Coastguard Worker  *
20*0e209d39SAndroid Build Coastguard Worker  * URegion objects represent data associated with a particular Unicode Region Code, also known as a
21*0e209d39SAndroid Build Coastguard Worker  * Unicode Region Subtag, which is defined based upon the BCP 47 standard. These include:
22*0e209d39SAndroid Build Coastguard Worker  * * Two-letter codes defined by ISO 3166-1, with special LDML treatment of certain private-use or
23*0e209d39SAndroid Build Coastguard Worker  *   reserved codes;
24*0e209d39SAndroid Build Coastguard Worker  * * A subset of 3-digit numeric codes defined by UN M.49.
25*0e209d39SAndroid Build Coastguard Worker  * URegion objects can also provide mappings to and from additional codes. There are different types
26*0e209d39SAndroid Build Coastguard Worker  * of regions that are important to distinguish:
27*0e209d39SAndroid Build Coastguard Worker  * <p>
28*0e209d39SAndroid Build Coastguard Worker  * Macroregion - A code for a "macro geographical (continental) region, geographical sub-region, or
29*0e209d39SAndroid Build Coastguard Worker  * selected economic and other grouping" as defined in UN M.49. These are typically 3-digit codes,
30*0e209d39SAndroid Build Coastguard Worker  * but contain some 2-letter codes for LDML extensions, such as "QO" for Outlying Oceania.
31*0e209d39SAndroid Build Coastguard Worker  * Macroregions are represented in ICU by one of three region types: WORLD (code 001),
32*0e209d39SAndroid Build Coastguard Worker  * CONTINENTS (regions contained directly by WORLD), and SUBCONTINENTS (regions contained directly
33*0e209d39SAndroid Build Coastguard Worker  * by a continent ).
34*0e209d39SAndroid Build Coastguard Worker  * <p>
35*0e209d39SAndroid Build Coastguard Worker  * TERRITORY - A Region that is not a Macroregion. These are typically codes for countries, but also
36*0e209d39SAndroid Build Coastguard Worker  * include areas that are not separate countries, such as the code "AQ" for Antarctica or the code
37*0e209d39SAndroid Build Coastguard Worker  * "HK" for Hong Kong (SAR China). Overseas dependencies of countries may or may not have separate
38*0e209d39SAndroid Build Coastguard Worker  * codes. The codes are typically 2-letter codes aligned with ISO 3166, but BCP47 allows for the use
39*0e209d39SAndroid Build Coastguard Worker  * of 3-digit codes in the future.
40*0e209d39SAndroid Build Coastguard Worker  * <p>
41*0e209d39SAndroid Build Coastguard Worker  * UNKNOWN - The code ZZ is defined by Unicode LDML for use in indicating that region is unknown,
42*0e209d39SAndroid Build Coastguard Worker  * or that the value supplied as a region was invalid.
43*0e209d39SAndroid Build Coastguard Worker  * <p>
44*0e209d39SAndroid Build Coastguard Worker  * DEPRECATED - Region codes that have been defined in the past but are no longer in modern usage,
45*0e209d39SAndroid Build Coastguard Worker  * usually due to a country splitting into multiple territories or changing its name.
46*0e209d39SAndroid Build Coastguard Worker  * <p>
47*0e209d39SAndroid Build Coastguard Worker  * GROUPING - A widely understood grouping of territories that has a well defined membership such
48*0e209d39SAndroid Build Coastguard Worker  * that a region code has been assigned for it.  Some of these are UN M.49 codes that don't fall into
49*0e209d39SAndroid Build Coastguard Worker  * the world/continent/sub-continent hierarchy, while others are just well-known groupings that have
50*0e209d39SAndroid Build Coastguard Worker  * their own region code. Region "EU" (European Union) is one such region code that is a grouping.
51*0e209d39SAndroid Build Coastguard Worker  * Groupings will never be returned by the uregion_getContainingRegion, since a different type of region
52*0e209d39SAndroid Build Coastguard Worker  * (WORLD, CONTINENT, or SUBCONTINENT) will always be the containing region instead.
53*0e209d39SAndroid Build Coastguard Worker  *
54*0e209d39SAndroid Build Coastguard Worker  * URegion objects are const/immutable, owned and maintained by ICU itself, so there are not functions
55*0e209d39SAndroid Build Coastguard Worker  * to open or close them.
56*0e209d39SAndroid Build Coastguard Worker  */
57*0e209d39SAndroid Build Coastguard Worker 
58*0e209d39SAndroid Build Coastguard Worker /**
59*0e209d39SAndroid Build Coastguard Worker  * URegionType is an enumeration defining the different types of regions.  Current possible
60*0e209d39SAndroid Build Coastguard Worker  * values are URGN_WORLD, URGN_CONTINENT, URGN_SUBCONTINENT, URGN_TERRITORY, URGN_GROUPING,
61*0e209d39SAndroid Build Coastguard Worker  * URGN_DEPRECATED, and URGN_UNKNOWN.
62*0e209d39SAndroid Build Coastguard Worker  *
63*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 51
64*0e209d39SAndroid Build Coastguard Worker  */
65*0e209d39SAndroid Build Coastguard Worker typedef enum URegionType {
66*0e209d39SAndroid Build Coastguard Worker     /**
67*0e209d39SAndroid Build Coastguard Worker      * Type representing the unknown region.
68*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 51
69*0e209d39SAndroid Build Coastguard Worker      */
70*0e209d39SAndroid Build Coastguard Worker     URGN_UNKNOWN,
71*0e209d39SAndroid Build Coastguard Worker 
72*0e209d39SAndroid Build Coastguard Worker     /**
73*0e209d39SAndroid Build Coastguard Worker      * Type representing a territory.
74*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 51
75*0e209d39SAndroid Build Coastguard Worker      */
76*0e209d39SAndroid Build Coastguard Worker     URGN_TERRITORY,
77*0e209d39SAndroid Build Coastguard Worker 
78*0e209d39SAndroid Build Coastguard Worker     /**
79*0e209d39SAndroid Build Coastguard Worker      * Type representing the whole world.
80*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 51
81*0e209d39SAndroid Build Coastguard Worker      */
82*0e209d39SAndroid Build Coastguard Worker     URGN_WORLD,
83*0e209d39SAndroid Build Coastguard Worker 
84*0e209d39SAndroid Build Coastguard Worker     /**
85*0e209d39SAndroid Build Coastguard Worker      * Type representing a continent.
86*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 51
87*0e209d39SAndroid Build Coastguard Worker      */
88*0e209d39SAndroid Build Coastguard Worker     URGN_CONTINENT,
89*0e209d39SAndroid Build Coastguard Worker 
90*0e209d39SAndroid Build Coastguard Worker     /**
91*0e209d39SAndroid Build Coastguard Worker      * Type representing a sub-continent.
92*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 51
93*0e209d39SAndroid Build Coastguard Worker      */
94*0e209d39SAndroid Build Coastguard Worker     URGN_SUBCONTINENT,
95*0e209d39SAndroid Build Coastguard Worker 
96*0e209d39SAndroid Build Coastguard Worker     /**
97*0e209d39SAndroid Build Coastguard Worker      * Type representing a grouping of territories that is not to be used in
98*0e209d39SAndroid Build Coastguard Worker      * the normal WORLD/CONTINENT/SUBCONTINENT/TERRITORY containment tree.
99*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 51
100*0e209d39SAndroid Build Coastguard Worker      */
101*0e209d39SAndroid Build Coastguard Worker     URGN_GROUPING,
102*0e209d39SAndroid Build Coastguard Worker 
103*0e209d39SAndroid Build Coastguard Worker     /**
104*0e209d39SAndroid Build Coastguard Worker      * Type representing a region whose code has been deprecated, usually
105*0e209d39SAndroid Build Coastguard Worker      * due to a country splitting into multiple territories or changing its name.
106*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 51
107*0e209d39SAndroid Build Coastguard Worker      */
108*0e209d39SAndroid Build Coastguard Worker     URGN_DEPRECATED,
109*0e209d39SAndroid Build Coastguard Worker 
110*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
111*0e209d39SAndroid Build Coastguard Worker     /**
112*0e209d39SAndroid Build Coastguard Worker      * One more than the highest normal URegionType value.
113*0e209d39SAndroid Build Coastguard Worker      * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
114*0e209d39SAndroid Build Coastguard Worker      */
115*0e209d39SAndroid Build Coastguard Worker     URGN_LIMIT
116*0e209d39SAndroid Build Coastguard Worker #endif  /* U_HIDE_DEPRECATED_API */
117*0e209d39SAndroid Build Coastguard Worker } URegionType;
118*0e209d39SAndroid Build Coastguard Worker 
119*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING
120*0e209d39SAndroid Build Coastguard Worker 
121*0e209d39SAndroid Build Coastguard Worker /**
122*0e209d39SAndroid Build Coastguard Worker  * Opaque URegion object for use in C programs.
123*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 52
124*0e209d39SAndroid Build Coastguard Worker  */
125*0e209d39SAndroid Build Coastguard Worker struct URegion;
126*0e209d39SAndroid Build Coastguard Worker typedef struct URegion URegion; /**< @stable ICU 52 */
127*0e209d39SAndroid Build Coastguard Worker 
128*0e209d39SAndroid Build Coastguard Worker /**
129*0e209d39SAndroid Build Coastguard Worker  * Returns a pointer to a URegion for the specified region code: A 2-letter or 3-letter ISO 3166
130*0e209d39SAndroid Build Coastguard Worker  * code, UN M.49 numeric code (superset of ISO 3166 numeric codes), or other valid Unicode Region
131*0e209d39SAndroid Build Coastguard Worker  * Code as defined by the LDML specification. The code will be canonicalized internally. If the
132*0e209d39SAndroid Build Coastguard Worker  * region code is NULL or not recognized, the appropriate error code will be set
133*0e209d39SAndroid Build Coastguard Worker  * (U_ILLEGAL_ARGUMENT_ERROR).
134*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 52
135*0e209d39SAndroid Build Coastguard Worker  */
136*0e209d39SAndroid Build Coastguard Worker U_CAPI const URegion* U_EXPORT2
137*0e209d39SAndroid Build Coastguard Worker uregion_getRegionFromCode(const char *regionCode, UErrorCode *status);
138*0e209d39SAndroid Build Coastguard Worker 
139*0e209d39SAndroid Build Coastguard Worker /**
140*0e209d39SAndroid Build Coastguard Worker  * Returns a pointer to a URegion for the specified numeric region code. If the numeric region
141*0e209d39SAndroid Build Coastguard Worker  * code is not recognized, the appropriate error code will be set (U_ILLEGAL_ARGUMENT_ERROR).
142*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 52
143*0e209d39SAndroid Build Coastguard Worker  */
144*0e209d39SAndroid Build Coastguard Worker U_CAPI const URegion* U_EXPORT2
145*0e209d39SAndroid Build Coastguard Worker uregion_getRegionFromNumericCode (int32_t code, UErrorCode *status);
146*0e209d39SAndroid Build Coastguard Worker 
147*0e209d39SAndroid Build Coastguard Worker /**
148*0e209d39SAndroid Build Coastguard Worker  * Returns an enumeration over the canonical codes of all known regions that match the given type.
149*0e209d39SAndroid Build Coastguard Worker  * The enumeration must be closed with with uenum_close().
150*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 52
151*0e209d39SAndroid Build Coastguard Worker  */
152*0e209d39SAndroid Build Coastguard Worker U_CAPI UEnumeration* U_EXPORT2
153*0e209d39SAndroid Build Coastguard Worker uregion_getAvailable(URegionType type, UErrorCode *status);
154*0e209d39SAndroid Build Coastguard Worker 
155*0e209d39SAndroid Build Coastguard Worker /**
156*0e209d39SAndroid Build Coastguard Worker  * Returns true if the specified uregion is equal to the specified otherRegion.
157*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 52
158*0e209d39SAndroid Build Coastguard Worker  */
159*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
160*0e209d39SAndroid Build Coastguard Worker uregion_areEqual(const URegion* uregion, const URegion* otherRegion);
161*0e209d39SAndroid Build Coastguard Worker 
162*0e209d39SAndroid Build Coastguard Worker /**
163*0e209d39SAndroid Build Coastguard Worker  * Returns a pointer to the URegion that contains the specified uregion. Returns NULL if the
164*0e209d39SAndroid Build Coastguard Worker  * specified uregion is code "001" (World) or "ZZ" (Unknown region). For example, calling
165*0e209d39SAndroid Build Coastguard Worker  * this method with region "IT" (Italy) returns the URegion for "039" (Southern Europe).
166*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 52
167*0e209d39SAndroid Build Coastguard Worker  */
168*0e209d39SAndroid Build Coastguard Worker U_CAPI const URegion* U_EXPORT2
169*0e209d39SAndroid Build Coastguard Worker uregion_getContainingRegion(const URegion* uregion);
170*0e209d39SAndroid Build Coastguard Worker 
171*0e209d39SAndroid Build Coastguard Worker /**
172*0e209d39SAndroid Build Coastguard Worker  * Return a pointer to the URegion that geographically contains this uregion and matches the
173*0e209d39SAndroid Build Coastguard Worker  * specified type, moving multiple steps up the containment chain if necessary. Returns NULL if no
174*0e209d39SAndroid Build Coastguard Worker  * containing region can be found that matches the specified type. Will return NULL if URegionType
175*0e209d39SAndroid Build Coastguard Worker  * is URGN_GROUPING, URGN_DEPRECATED, or URGN_UNKNOWN which are not appropriate for this API.
176*0e209d39SAndroid Build Coastguard Worker  * For example, calling this method with uregion "IT" (Italy) for type URGN_CONTINENT returns the
177*0e209d39SAndroid Build Coastguard Worker  * URegion "150" (Europe).
178*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 52
179*0e209d39SAndroid Build Coastguard Worker  */
180*0e209d39SAndroid Build Coastguard Worker U_CAPI const URegion* U_EXPORT2
181*0e209d39SAndroid Build Coastguard Worker uregion_getContainingRegionOfType(const URegion* uregion, URegionType type);
182*0e209d39SAndroid Build Coastguard Worker 
183*0e209d39SAndroid Build Coastguard Worker /**
184*0e209d39SAndroid Build Coastguard Worker  * Return an enumeration over the canonical codes of all the regions that are immediate children
185*0e209d39SAndroid Build Coastguard Worker  * of the specified uregion in the region hierarchy. These returned regions could be either macro
186*0e209d39SAndroid Build Coastguard Worker  * regions, territories, or a mixture of the two, depending on the containment data as defined in
187*0e209d39SAndroid Build Coastguard Worker  * CLDR. This API returns NULL if this uregion doesn't have any sub-regions. For example, calling
188*0e209d39SAndroid Build Coastguard Worker  * this function for uregion "150" (Europe) returns an enumeration containing the various
189*0e209d39SAndroid Build Coastguard Worker  * sub-regions of Europe: "039" (Southern Europe), "151" (Eastern Europe), "154" (Northern Europe),
190*0e209d39SAndroid Build Coastguard Worker  * and "155" (Western Europe). The enumeration must be closed with with uenum_close().
191*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 52
192*0e209d39SAndroid Build Coastguard Worker  */
193*0e209d39SAndroid Build Coastguard Worker U_CAPI UEnumeration* U_EXPORT2
194*0e209d39SAndroid Build Coastguard Worker uregion_getContainedRegions(const URegion* uregion, UErrorCode *status);
195*0e209d39SAndroid Build Coastguard Worker 
196*0e209d39SAndroid Build Coastguard Worker /**
197*0e209d39SAndroid Build Coastguard Worker  * Returns an enumeration over the canonical codes of all the regions that are children of the
198*0e209d39SAndroid Build Coastguard Worker  * specified uregion anywhere in the region hierarchy and match the given type. This API may return
199*0e209d39SAndroid Build Coastguard Worker  * an empty enumeration if this uregion doesn't have any sub-regions that match the given type.
200*0e209d39SAndroid Build Coastguard Worker  * For example, calling this method with region "150" (Europe) and type URGN_TERRITORY" returns an
201*0e209d39SAndroid Build Coastguard Worker  * enumeration containing all the territories in Europe: "FR" (France), "IT" (Italy), "DE" (Germany),
202*0e209d39SAndroid Build Coastguard Worker  * etc. The enumeration must be closed with with uenum_close().
203*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 52
204*0e209d39SAndroid Build Coastguard Worker  */
205*0e209d39SAndroid Build Coastguard Worker U_CAPI UEnumeration* U_EXPORT2
206*0e209d39SAndroid Build Coastguard Worker uregion_getContainedRegionsOfType(const URegion* uregion, URegionType type, UErrorCode *status);
207*0e209d39SAndroid Build Coastguard Worker 
208*0e209d39SAndroid Build Coastguard Worker /**
209*0e209d39SAndroid Build Coastguard Worker  * Returns true if the specified uregion contains the specified otherRegion anywhere in the region
210*0e209d39SAndroid Build Coastguard Worker  * hierarchy.
211*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 52
212*0e209d39SAndroid Build Coastguard Worker  */
213*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
214*0e209d39SAndroid Build Coastguard Worker uregion_contains(const URegion* uregion, const URegion* otherRegion);
215*0e209d39SAndroid Build Coastguard Worker 
216*0e209d39SAndroid Build Coastguard Worker /**
217*0e209d39SAndroid Build Coastguard Worker  * If the specified uregion is deprecated, returns an enumeration over the canonical codes of the
218*0e209d39SAndroid Build Coastguard Worker  * regions that are the preferred replacement regions for the specified uregion. If the specified
219*0e209d39SAndroid Build Coastguard Worker  * uregion is not deprecated, returns NULL. For example, calling this method with uregion
220*0e209d39SAndroid Build Coastguard Worker  * "SU" (Soviet Union) returns a list of the regions containing "RU" (Russia), "AM" (Armenia),
221*0e209d39SAndroid Build Coastguard Worker  * "AZ" (Azerbaijan), etc... The enumeration must be closed with with uenum_close().
222*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 52
223*0e209d39SAndroid Build Coastguard Worker  */
224*0e209d39SAndroid Build Coastguard Worker U_CAPI UEnumeration* U_EXPORT2
225*0e209d39SAndroid Build Coastguard Worker uregion_getPreferredValues(const URegion* uregion, UErrorCode *status);
226*0e209d39SAndroid Build Coastguard Worker 
227*0e209d39SAndroid Build Coastguard Worker /**
228*0e209d39SAndroid Build Coastguard Worker  * Returns the specified uregion's canonical code.
229*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 52
230*0e209d39SAndroid Build Coastguard Worker  */
231*0e209d39SAndroid Build Coastguard Worker U_CAPI const char* U_EXPORT2
232*0e209d39SAndroid Build Coastguard Worker uregion_getRegionCode(const URegion* uregion);
233*0e209d39SAndroid Build Coastguard Worker 
234*0e209d39SAndroid Build Coastguard Worker /**
235*0e209d39SAndroid Build Coastguard Worker  * Returns the specified uregion's numeric code, or a negative value if there is no numeric code
236*0e209d39SAndroid Build Coastguard Worker  * for the specified uregion.
237*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 52
238*0e209d39SAndroid Build Coastguard Worker  */
239*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
240*0e209d39SAndroid Build Coastguard Worker uregion_getNumericCode(const URegion* uregion);
241*0e209d39SAndroid Build Coastguard Worker 
242*0e209d39SAndroid Build Coastguard Worker /**
243*0e209d39SAndroid Build Coastguard Worker  * Returns the URegionType of the specified uregion.
244*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 52
245*0e209d39SAndroid Build Coastguard Worker  */
246*0e209d39SAndroid Build Coastguard Worker U_CAPI URegionType U_EXPORT2
247*0e209d39SAndroid Build Coastguard Worker uregion_getType(const URegion* uregion);
248*0e209d39SAndroid Build Coastguard Worker 
249*0e209d39SAndroid Build Coastguard Worker 
250*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_FORMATTING */
251*0e209d39SAndroid Build Coastguard Worker 
252*0e209d39SAndroid Build Coastguard Worker #endif
253