1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/unicode/uregion.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,253 @@ 1.4 +/* 1.5 +***************************************************************************************** 1.6 +* Copyright (C) 2013, International Business Machines 1.7 +* Corporation and others. All Rights Reserved. 1.8 +***************************************************************************************** 1.9 +*/ 1.10 + 1.11 +#ifndef UREGION_H 1.12 +#define UREGION_H 1.13 + 1.14 +#include "unicode/utypes.h" 1.15 +#include "unicode/uenum.h" 1.16 + 1.17 +/** 1.18 + * \file 1.19 + * \brief C API: URegion (territory containment and mapping) 1.20 + * 1.21 + * URegion objects represent data associated with a particular Unicode Region Code, also known as a 1.22 + * Unicode Region Subtag, which is defined based upon the BCP 47 standard. These include: 1.23 + * * Two-letter codes defined by ISO 3166-1, with special LDML treatment of certain private-use or 1.24 + * reserved codes; 1.25 + * * A subset of 3-digit numeric codes defined by UN M.49. 1.26 + * URegion objects can also provide mappings to and from additional codes. There are different types 1.27 + * of regions that are important to distinguish: 1.28 + * <p> 1.29 + * Macroregion - A code for a "macro geographical (continental) region, geographical sub-region, or 1.30 + * selected economic and other grouping" as defined in UN M.49. These are typically 3-digit codes, 1.31 + * but contain some 2-letter codes for LDML extensions, such as "QO" for Outlying Oceania. 1.32 + * Macroregions are represented in ICU by one of three region types: WORLD (code 001), 1.33 + * CONTINENTS (regions contained directly by WORLD), and SUBCONTINENTS (regions contained directly 1.34 + * by a continent ). 1.35 + * <p> 1.36 + * TERRITORY - A Region that is not a Macroregion. These are typically codes for countries, but also 1.37 + * include areas that are not separate countries, such as the code "AQ" for Antarctica or the code 1.38 + * "HK" for Hong Kong (SAR China). Overseas dependencies of countries may or may not have separate 1.39 + * codes. The codes are typically 2-letter codes aligned with ISO 3166, but BCP47 allows for the use 1.40 + * of 3-digit codes in the future. 1.41 + * <p> 1.42 + * UNKNOWN - The code ZZ is defined by Unicode LDML for use in indicating that region is unknown, 1.43 + * or that the value supplied as a region was invalid. 1.44 + * <p> 1.45 + * DEPRECATED - Region codes that have been defined in the past but are no longer in modern usage, 1.46 + * usually due to a country splitting into multiple territories or changing its name. 1.47 + * <p> 1.48 + * GROUPING - A widely understood grouping of territories that has a well defined membership such 1.49 + * that a region code has been assigned for it. Some of these are UN M.49 codes that don't fall into 1.50 + * the world/continent/sub-continent hierarchy, while others are just well-known groupings that have 1.51 + * their own region code. Region "EU" (European Union) is one such region code that is a grouping. 1.52 + * Groupings will never be returned by the uregion_getContainingRegion, since a different type of region 1.53 + * (WORLD, CONTINENT, or SUBCONTINENT) will always be the containing region instead. 1.54 + * 1.55 + * URegion objects are const/immutable, owned and maintained by ICU itself, so there are not functions 1.56 + * to open or close them. 1.57 + */ 1.58 + 1.59 +#ifndef U_HIDE_DRAFT_API 1.60 +/** 1.61 + * URegionType is an enumeration defining the different types of regions. Current possible 1.62 + * values are URGN_WORLD, URGN_CONTINENT, URGN_SUBCONTINENT, URGN_TERRITORY, URGN_GROUPING, 1.63 + * URGN_DEPRECATED, and URGN_UNKNOWN. 1.64 + * 1.65 + * @draft ICU 51 1.66 + */ 1.67 +typedef enum URegionType { 1.68 + /** 1.69 + * Type representing the unknown region. 1.70 + * @draft ICU 51 1.71 + */ 1.72 + URGN_UNKNOWN, 1.73 + 1.74 + /** 1.75 + * Type representing a territory. 1.76 + * @draft ICU 51 1.77 + */ 1.78 + URGN_TERRITORY, 1.79 + 1.80 + /** 1.81 + * Type representing the whole world. 1.82 + * @draft ICU 51 1.83 + */ 1.84 + URGN_WORLD, 1.85 + 1.86 + /** 1.87 + * Type representing a continent. 1.88 + * @draft ICU 51 1.89 + */ 1.90 + URGN_CONTINENT, 1.91 + 1.92 + /** 1.93 + * Type representing a sub-continent. 1.94 + * @draft ICU 51 1.95 + */ 1.96 + URGN_SUBCONTINENT, 1.97 + 1.98 + /** 1.99 + * Type representing a grouping of territories that is not to be used in 1.100 + * the normal WORLD/CONTINENT/SUBCONTINENT/TERRITORY containment tree. 1.101 + * @draft ICU 51 1.102 + */ 1.103 + URGN_GROUPING, 1.104 + 1.105 + /** 1.106 + * Type representing a region whose code has been deprecated, usually 1.107 + * due to a country splitting into multiple territories or changing its name. 1.108 + * @draft ICU 51 1.109 + */ 1.110 + URGN_DEPRECATED, 1.111 + 1.112 + /** 1.113 + * Maximum value for this unumeration. 1.114 + * @draft ICU 51 1.115 + */ 1.116 + URGN_LIMIT 1.117 +} URegionType; 1.118 +#endif /* U_HIDE_DRAFT_API */ 1.119 + 1.120 +#if !UCONFIG_NO_FORMATTING 1.121 + 1.122 +#ifndef U_HIDE_DRAFT_API 1.123 + 1.124 +/** 1.125 + * Opaque URegion object for use in C programs. 1.126 + * @draft ICU 52 1.127 + */ 1.128 +struct URegion; 1.129 +typedef struct URegion URegion; /**< @draft ICU 52 */ 1.130 + 1.131 +/** 1.132 + * Returns a pointer to a URegion for the specified region code: A 2-letter or 3-letter ISO 3166 1.133 + * code, UN M.49 numeric code (superset of ISO 3166 numeric codes), or other valid Unicode Region 1.134 + * Code as defined by the LDML specification. The code will be canonicalized internally. If the 1.135 + * region code is NULL or not recognized, the appropriate error code will be set 1.136 + * (U_ILLEGAL_ARGUMENT_ERROR). 1.137 + * @draft ICU 52 1.138 + */ 1.139 +U_DRAFT const URegion* U_EXPORT2 1.140 +uregion_getRegionFromCode(const char *regionCode, UErrorCode *status); 1.141 + 1.142 +/** 1.143 + * Returns a pointer to a URegion for the specified numeric region code. If the numeric region 1.144 + * code is not recognized, the appropriate error code will be set (U_ILLEGAL_ARGUMENT_ERROR). 1.145 + * @draft ICU 52 1.146 + */ 1.147 +U_DRAFT const URegion* U_EXPORT2 1.148 +uregion_getRegionFromNumericCode (int32_t code, UErrorCode *status); 1.149 + 1.150 +/** 1.151 + * Returns an enumeration over the canonical codes of all known regions that match the given type. 1.152 + * The enumeration must be closed with with uenum_close(). 1.153 + * @draft ICU 52 1.154 + */ 1.155 +U_DRAFT UEnumeration* U_EXPORT2 1.156 +uregion_getAvailable(URegionType type, UErrorCode *status); 1.157 + 1.158 +/** 1.159 + * Returns true if the specified uregion is equal to the specified otherRegion. 1.160 + * @draft ICU 52 1.161 + */ 1.162 +U_DRAFT UBool U_EXPORT2 1.163 +uregion_areEqual(const URegion* uregion, const URegion* otherRegion); 1.164 + 1.165 +/** 1.166 + * Returns a pointer to the URegion that contains the specified uregion. Returns NULL if the 1.167 + * specified uregion is code "001" (World) or "ZZ" (Unknown region). For example, calling 1.168 + * this method with region "IT" (Italy) returns the URegion for "039" (Southern Europe). 1.169 + * @draft ICU 52 1.170 + */ 1.171 +U_DRAFT const URegion* U_EXPORT2 1.172 +uregion_getContainingRegion(const URegion* uregion); 1.173 + 1.174 +/** 1.175 + * Return a pointer to the URegion that geographically contains this uregion and matches the 1.176 + * specified type, moving multiple steps up the containment chain if necessary. Returns NULL if no 1.177 + * containing region can be found that matches the specified type. Will return NULL if URegionType 1.178 + * is URGN_GROUPING, URGN_DEPRECATED, or URGN_UNKNOWN which are not appropriate for this API. 1.179 + * For example, calling this method with uregion "IT" (Italy) for type URGN_CONTINENT returns the 1.180 + * URegion "150" (Europe). 1.181 + * @draft ICU 52 1.182 + */ 1.183 +U_DRAFT const URegion* U_EXPORT2 1.184 +uregion_getContainingRegionOfType(const URegion* uregion, URegionType type); 1.185 + 1.186 +/** 1.187 + * Return an enumeration over the canonical codes of all the regions that are immediate children 1.188 + * of the specified uregion in the region hierarchy. These returned regions could be either macro 1.189 + * regions, territories, or a mixture of the two, depending on the containment data as defined in 1.190 + * CLDR. This API returns NULL if this uregion doesn't have any sub-regions. For example, calling 1.191 + * this function for uregion "150" (Europe) returns an enumeration containing the various 1.192 + * sub-regions of Europe: "039" (Southern Europe), "151" (Eastern Europe), "154" (Northern Europe), 1.193 + * and "155" (Western Europe). The enumeration must be closed with with uenum_close(). 1.194 + * @draft ICU 52 1.195 + */ 1.196 +U_DRAFT UEnumeration* U_EXPORT2 1.197 +uregion_getContainedRegions(const URegion* uregion, UErrorCode *status); 1.198 + 1.199 +/** 1.200 + * Returns an enumeration over the canonical codes of all the regions that are children of the 1.201 + * specified uregion anywhere in the region hierarchy and match the given type. This API may return 1.202 + * an empty enumeration if this uregion doesn't have any sub-regions that match the given type. 1.203 + * For example, calling this method with region "150" (Europe) and type URGN_TERRITORY" returns an 1.204 + * enumeration containing all the territories in Europe: "FR" (France), "IT" (Italy), "DE" (Germany), 1.205 + * etc. The enumeration must be closed with with uenum_close(). 1.206 + * @draft ICU 52 1.207 + */ 1.208 +U_DRAFT UEnumeration* U_EXPORT2 1.209 +uregion_getContainedRegionsOfType(const URegion* uregion, URegionType type, UErrorCode *status); 1.210 + 1.211 +/** 1.212 + * Returns true if the specified uregion contains the specified otherRegion anywhere in the region 1.213 + * hierarchy. 1.214 + * @draft ICU 52 1.215 + */ 1.216 +U_DRAFT UBool U_EXPORT2 1.217 +uregion_contains(const URegion* uregion, const URegion* otherRegion); 1.218 + 1.219 +/** 1.220 + * If the specified uregion is deprecated, returns an enumeration over the canonical codes of the 1.221 + * regions that are the preferred replacement regions for the specified uregion. If the specified 1.222 + * uregion is not deprecated, returns NULL. For example, calling this method with uregion 1.223 + * "SU" (Soviet Union) returns a list of the regions containing "RU" (Russia), "AM" (Armenia), 1.224 + * "AZ" (Azerbaijan), etc... The enumeration must be closed with with uenum_close(). 1.225 + * @draft ICU 52 1.226 + */ 1.227 +U_DRAFT UEnumeration* U_EXPORT2 1.228 +uregion_getPreferredValues(const URegion* uregion, UErrorCode *status); 1.229 + 1.230 +/** 1.231 + * Returns the specified uregion's canonical code. 1.232 + * @draft ICU 52 1.233 + */ 1.234 +U_DRAFT const char* U_EXPORT2 1.235 +uregion_getRegionCode(const URegion* uregion); 1.236 + 1.237 +/** 1.238 + * Returns the specified uregion's numeric code, or a negative value if there is no numeric code 1.239 + * for the specified uregion. 1.240 + * @draft ICU 52 1.241 + */ 1.242 +U_DRAFT int32_t U_EXPORT2 1.243 +uregion_getNumericCode(const URegion* uregion); 1.244 + 1.245 +/** 1.246 + * Returns the URegionType of the specified uregion. 1.247 + * @draft ICU 52 1.248 + */ 1.249 +U_DRAFT URegionType U_EXPORT2 1.250 +uregion_getType(const URegion* uregion); 1.251 + 1.252 +#endif /* U_HIDE_DRAFT_API */ 1.253 + 1.254 +#endif /* #if !UCONFIG_NO_FORMATTING */ 1.255 + 1.256 +#endif