1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/common/unicode/locid.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,798 @@ 1.4 +/* 1.5 +****************************************************************************** 1.6 +* 1.7 +* Copyright (C) 1996-2013, International Business Machines 1.8 +* Corporation and others. All Rights Reserved. 1.9 +* 1.10 +****************************************************************************** 1.11 +* 1.12 +* File locid.h 1.13 +* 1.14 +* Created by: Helena Shih 1.15 +* 1.16 +* Modification History: 1.17 +* 1.18 +* Date Name Description 1.19 +* 02/11/97 aliu Changed gLocPath to fgLocPath and added methods to 1.20 +* get and set it. 1.21 +* 04/02/97 aliu Made operator!= inline; fixed return value of getName(). 1.22 +* 04/15/97 aliu Cleanup for AIX/Win32. 1.23 +* 04/24/97 aliu Numerous changes per code review. 1.24 +* 08/18/98 stephen Added tokenizeString(),changed getDisplayName() 1.25 +* 09/08/98 stephen Moved definition of kEmptyString for Mac Port 1.26 +* 11/09/99 weiv Added const char * getName() const; 1.27 +* 04/12/00 srl removing unicodestring api's and cached hash code 1.28 +* 08/10/01 grhoten Change the static Locales to accessor functions 1.29 +****************************************************************************** 1.30 +*/ 1.31 + 1.32 +#ifndef LOCID_H 1.33 +#define LOCID_H 1.34 + 1.35 +#include "unicode/utypes.h" 1.36 +#include "unicode/uobject.h" 1.37 +#include "unicode/unistr.h" 1.38 +#include "unicode/putil.h" 1.39 +#include "unicode/uloc.h" 1.40 +#include "unicode/strenum.h" 1.41 + 1.42 +/** 1.43 + * \file 1.44 + * \brief C++ API: Locale ID object. 1.45 + */ 1.46 + 1.47 +U_NAMESPACE_BEGIN 1.48 + 1.49 +// Forward Declarations 1.50 +void U_CALLCONV locale_available_init(); /**< @internal */ 1.51 + 1.52 +/** 1.53 + * A <code>Locale</code> object represents a specific geographical, political, 1.54 + * or cultural region. An operation that requires a <code>Locale</code> to perform 1.55 + * its task is called <em>locale-sensitive</em> and uses the <code>Locale</code> 1.56 + * to tailor information for the user. For example, displaying a number 1.57 + * is a locale-sensitive operation--the number should be formatted 1.58 + * according to the customs/conventions of the user's native country, 1.59 + * region, or culture. 1.60 + * 1.61 + * The Locale class is not suitable for subclassing. 1.62 + * 1.63 + * <P> 1.64 + * You can create a <code>Locale</code> object using the constructor in 1.65 + * this class: 1.66 + * \htmlonly<blockquote>\endhtmlonly 1.67 + * <pre> 1.68 + * Locale( const char* language, 1.69 + * const char* country, 1.70 + * const char* variant); 1.71 + * </pre> 1.72 + * \htmlonly</blockquote>\endhtmlonly 1.73 + * The first argument to the constructors is a valid <STRONG>ISO 1.74 + * Language Code.</STRONG> These codes are the lower-case two-letter 1.75 + * codes as defined by ISO-639. 1.76 + * You can find a full list of these codes at: 1.77 + * <BR><a href ="http://www.loc.gov/standards/iso639-2/"> 1.78 + * http://www.loc.gov/standards/iso639-2/</a> 1.79 + * 1.80 + * <P> 1.81 + * The second argument to the constructors is a valid <STRONG>ISO Country 1.82 + * Code.</STRONG> These codes are the upper-case two-letter codes 1.83 + * as defined by ISO-3166. 1.84 + * You can find a full list of these codes at a number of sites, such as: 1.85 + * <BR><a href="http://www.iso.org/iso/en/prods-services/iso3166ma/index.html"> 1.86 + * http://www.iso.org/iso/en/prods-services/iso3166ma/index.html</a> 1.87 + * 1.88 + * <P> 1.89 + * The third constructor requires a third argument--the <STRONG>Variant.</STRONG> 1.90 + * The Variant codes are vendor and browser-specific. 1.91 + * For example, use REVISED for a langauge's revised script orthography, and POSIX for POSIX. 1.92 + * Where there are two variants, separate them with an underscore, and 1.93 + * put the most important one first. For 1.94 + * example, a Traditional Spanish collation might be referenced, with 1.95 + * "ES", "ES", "Traditional_POSIX". 1.96 + * 1.97 + * <P> 1.98 + * Because a <code>Locale</code> object is just an identifier for a region, 1.99 + * no validity check is performed when you construct a <code>Locale</code>. 1.100 + * If you want to see whether particular resources are available for the 1.101 + * <code>Locale</code> you construct, you must query those resources. For 1.102 + * example, ask the <code>NumberFormat</code> for the locales it supports 1.103 + * using its <code>getAvailableLocales</code> method. 1.104 + * <BR><STRONG>Note:</STRONG> When you ask for a resource for a particular 1.105 + * locale, you get back the best available match, not necessarily 1.106 + * precisely what you asked for. For more information, look at 1.107 + * <code>ResourceBundle</code>. 1.108 + * 1.109 + * <P> 1.110 + * The <code>Locale</code> class provides a number of convenient constants 1.111 + * that you can use to create <code>Locale</code> objects for commonly used 1.112 + * locales. For example, the following refers to a <code>Locale</code> object 1.113 + * for the United States: 1.114 + * \htmlonly<blockquote>\endhtmlonly 1.115 + * <pre> 1.116 + * Locale::getUS() 1.117 + * </pre> 1.118 + * \htmlonly</blockquote>\endhtmlonly 1.119 + * 1.120 + * <P> 1.121 + * Once you've created a <code>Locale</code> you can query it for information about 1.122 + * itself. Use <code>getCountry</code> to get the ISO Country Code and 1.123 + * <code>getLanguage</code> to get the ISO Language Code. You can 1.124 + * use <code>getDisplayCountry</code> to get the 1.125 + * name of the country suitable for displaying to the user. Similarly, 1.126 + * you can use <code>getDisplayLanguage</code> to get the name of 1.127 + * the language suitable for displaying to the user. Interestingly, 1.128 + * the <code>getDisplayXXX</code> methods are themselves locale-sensitive 1.129 + * and have two versions: one that uses the default locale and one 1.130 + * that takes a locale as an argument and displays the name or country in 1.131 + * a language appropriate to that locale. 1.132 + * 1.133 + * <P> 1.134 + * ICU provides a number of classes that perform locale-sensitive 1.135 + * operations. For example, the <code>NumberFormat</code> class formats 1.136 + * numbers, currency, or percentages in a locale-sensitive manner. Classes 1.137 + * such as <code>NumberFormat</code> have a number of convenience methods 1.138 + * for creating a default object of that type. For example, the 1.139 + * <code>NumberFormat</code> class provides these three convenience methods 1.140 + * for creating a default <code>NumberFormat</code> object: 1.141 + * \htmlonly<blockquote>\endhtmlonly 1.142 + * <pre> 1.143 + * UErrorCode success = U_ZERO_ERROR; 1.144 + * Locale myLocale; 1.145 + * NumberFormat *nf; 1.146 + * 1.147 + * nf = NumberFormat::createInstance( success ); delete nf; 1.148 + * nf = NumberFormat::createCurrencyInstance( success ); delete nf; 1.149 + * nf = NumberFormat::createPercentInstance( success ); delete nf; 1.150 + * </pre> 1.151 + * \htmlonly</blockquote>\endhtmlonly 1.152 + * Each of these methods has two variants; one with an explicit locale 1.153 + * and one without; the latter using the default locale. 1.154 + * \htmlonly<blockquote>\endhtmlonly 1.155 + * <pre> 1.156 + * nf = NumberFormat::createInstance( myLocale, success ); delete nf; 1.157 + * nf = NumberFormat::createCurrencyInstance( myLocale, success ); delete nf; 1.158 + * nf = NumberFormat::createPercentInstance( myLocale, success ); delete nf; 1.159 + * </pre> 1.160 + * \htmlonly</blockquote>\endhtmlonly 1.161 + * A <code>Locale</code> is the mechanism for identifying the kind of object 1.162 + * (<code>NumberFormat</code>) that you would like to get. The locale is 1.163 + * <STRONG>just</STRONG> a mechanism for identifying objects, 1.164 + * <STRONG>not</STRONG> a container for the objects themselves. 1.165 + * 1.166 + * <P> 1.167 + * Each class that performs locale-sensitive operations allows you 1.168 + * to get all the available objects of that type. You can sift 1.169 + * through these objects by language, country, or variant, 1.170 + * and use the display names to present a menu to the user. 1.171 + * For example, you can create a menu of all the collation objects 1.172 + * suitable for a given language. Such classes implement these 1.173 + * three class methods: 1.174 + * \htmlonly<blockquote>\endhtmlonly 1.175 + * <pre> 1.176 + * static Locale* getAvailableLocales(int32_t& numLocales) 1.177 + * static UnicodeString& getDisplayName(const Locale& objectLocale, 1.178 + * const Locale& displayLocale, 1.179 + * UnicodeString& displayName) 1.180 + * static UnicodeString& getDisplayName(const Locale& objectLocale, 1.181 + * UnicodeString& displayName) 1.182 + * </pre> 1.183 + * \htmlonly</blockquote>\endhtmlonly 1.184 + * 1.185 + * @stable ICU 2.0 1.186 + * @see ResourceBundle 1.187 + */ 1.188 +class U_COMMON_API Locale : public UObject { 1.189 +public: 1.190 + /** Useful constant for the Root locale. @stable ICU 4.4 */ 1.191 + static const Locale &U_EXPORT2 getRoot(void); 1.192 + /** Useful constant for this language. @stable ICU 2.0 */ 1.193 + static const Locale &U_EXPORT2 getEnglish(void); 1.194 + /** Useful constant for this language. @stable ICU 2.0 */ 1.195 + static const Locale &U_EXPORT2 getFrench(void); 1.196 + /** Useful constant for this language. @stable ICU 2.0 */ 1.197 + static const Locale &U_EXPORT2 getGerman(void); 1.198 + /** Useful constant for this language. @stable ICU 2.0 */ 1.199 + static const Locale &U_EXPORT2 getItalian(void); 1.200 + /** Useful constant for this language. @stable ICU 2.0 */ 1.201 + static const Locale &U_EXPORT2 getJapanese(void); 1.202 + /** Useful constant for this language. @stable ICU 2.0 */ 1.203 + static const Locale &U_EXPORT2 getKorean(void); 1.204 + /** Useful constant for this language. @stable ICU 2.0 */ 1.205 + static const Locale &U_EXPORT2 getChinese(void); 1.206 + /** Useful constant for this language. @stable ICU 2.0 */ 1.207 + static const Locale &U_EXPORT2 getSimplifiedChinese(void); 1.208 + /** Useful constant for this language. @stable ICU 2.0 */ 1.209 + static const Locale &U_EXPORT2 getTraditionalChinese(void); 1.210 + 1.211 + /** Useful constant for this country/region. @stable ICU 2.0 */ 1.212 + static const Locale &U_EXPORT2 getFrance(void); 1.213 + /** Useful constant for this country/region. @stable ICU 2.0 */ 1.214 + static const Locale &U_EXPORT2 getGermany(void); 1.215 + /** Useful constant for this country/region. @stable ICU 2.0 */ 1.216 + static const Locale &U_EXPORT2 getItaly(void); 1.217 + /** Useful constant for this country/region. @stable ICU 2.0 */ 1.218 + static const Locale &U_EXPORT2 getJapan(void); 1.219 + /** Useful constant for this country/region. @stable ICU 2.0 */ 1.220 + static const Locale &U_EXPORT2 getKorea(void); 1.221 + /** Useful constant for this country/region. @stable ICU 2.0 */ 1.222 + static const Locale &U_EXPORT2 getChina(void); 1.223 + /** Useful constant for this country/region. @stable ICU 2.0 */ 1.224 + static const Locale &U_EXPORT2 getPRC(void); 1.225 + /** Useful constant for this country/region. @stable ICU 2.0 */ 1.226 + static const Locale &U_EXPORT2 getTaiwan(void); 1.227 + /** Useful constant for this country/region. @stable ICU 2.0 */ 1.228 + static const Locale &U_EXPORT2 getUK(void); 1.229 + /** Useful constant for this country/region. @stable ICU 2.0 */ 1.230 + static const Locale &U_EXPORT2 getUS(void); 1.231 + /** Useful constant for this country/region. @stable ICU 2.0 */ 1.232 + static const Locale &U_EXPORT2 getCanada(void); 1.233 + /** Useful constant for this country/region. @stable ICU 2.0 */ 1.234 + static const Locale &U_EXPORT2 getCanadaFrench(void); 1.235 + 1.236 + 1.237 + /** 1.238 + * Construct a default locale object, a Locale for the default locale ID. 1.239 + * 1.240 + * @see getDefault 1.241 + * @see uloc_getDefault 1.242 + * @stable ICU 2.0 1.243 + */ 1.244 + Locale(); 1.245 + 1.246 + /** 1.247 + * Construct a locale from language, country, variant. 1.248 + * If an error occurs, then the constructed object will be "bogus" 1.249 + * (isBogus() will return TRUE). 1.250 + * 1.251 + * @param language Lowercase two-letter or three-letter ISO-639 code. 1.252 + * This parameter can instead be an ICU style C locale (e.g. "en_US"), 1.253 + * but the other parameters must not be used. 1.254 + * This parameter can be NULL; if so, 1.255 + * the locale is initialized to match the current default locale. 1.256 + * (This is the same as using the default constructor.) 1.257 + * Please note: The Java Locale class does NOT accept the form 1.258 + * 'new Locale("en_US")' but only 'new Locale("en","US")' 1.259 + * 1.260 + * @param country Uppercase two-letter ISO-3166 code. (optional) 1.261 + * @param variant Uppercase vendor and browser specific code. See class 1.262 + * description. (optional) 1.263 + * @param keywordsAndValues A string consisting of keyword/values pairs, such as 1.264 + * "collation=phonebook;currency=euro" 1.265 + * 1.266 + * @see getDefault 1.267 + * @see uloc_getDefault 1.268 + * @stable ICU 2.0 1.269 + */ 1.270 + Locale( const char * language, 1.271 + const char * country = 0, 1.272 + const char * variant = 0, 1.273 + const char * keywordsAndValues = 0); 1.274 + 1.275 + /** 1.276 + * Initializes a Locale object from another Locale object. 1.277 + * 1.278 + * @param other The Locale object being copied in. 1.279 + * @stable ICU 2.0 1.280 + */ 1.281 + Locale(const Locale& other); 1.282 + 1.283 + 1.284 + /** 1.285 + * Destructor 1.286 + * @stable ICU 2.0 1.287 + */ 1.288 + virtual ~Locale() ; 1.289 + 1.290 + /** 1.291 + * Replaces the entire contents of *this with the specified value. 1.292 + * 1.293 + * @param other The Locale object being copied in. 1.294 + * @return *this 1.295 + * @stable ICU 2.0 1.296 + */ 1.297 + Locale& operator=(const Locale& other); 1.298 + 1.299 + /** 1.300 + * Checks if two locale keys are the same. 1.301 + * 1.302 + * @param other The locale key object to be compared with this. 1.303 + * @return True if the two locale keys are the same, false otherwise. 1.304 + * @stable ICU 2.0 1.305 + */ 1.306 + UBool operator==(const Locale& other) const; 1.307 + 1.308 + /** 1.309 + * Checks if two locale keys are not the same. 1.310 + * 1.311 + * @param other The locale key object to be compared with this. 1.312 + * @return True if the two locale keys are not the same, false 1.313 + * otherwise. 1.314 + * @stable ICU 2.0 1.315 + */ 1.316 + UBool operator!=(const Locale& other) const; 1.317 + 1.318 + /** 1.319 + * Clone this object. 1.320 + * Clones can be used concurrently in multiple threads. 1.321 + * If an error occurs, then NULL is returned. 1.322 + * The caller must delete the clone. 1.323 + * 1.324 + * @return a clone of this object 1.325 + * 1.326 + * @see getDynamicClassID 1.327 + * @stable ICU 2.8 1.328 + */ 1.329 + Locale *clone() const; 1.330 + 1.331 +#ifndef U_HIDE_SYSTEM_API 1.332 + /** 1.333 + * Common methods of getting the current default Locale. Used for the 1.334 + * presentation: menus, dialogs, etc. Generally set once when your applet or 1.335 + * application is initialized, then never reset. (If you do reset the 1.336 + * default locale, you probably want to reload your GUI, so that the change 1.337 + * is reflected in your interface.) 1.338 + * 1.339 + * More advanced programs will allow users to use different locales for 1.340 + * different fields, e.g. in a spreadsheet. 1.341 + * 1.342 + * Note that the initial setting will match the host system. 1.343 + * @return a reference to the Locale object for the default locale ID 1.344 + * @system 1.345 + * @stable ICU 2.0 1.346 + */ 1.347 + static const Locale& U_EXPORT2 getDefault(void); 1.348 + 1.349 + /** 1.350 + * Sets the default. Normally set once at the beginning of a process, 1.351 + * then never reset. 1.352 + * setDefault() only changes ICU's default locale ID, <strong>not</strong> 1.353 + * the default locale ID of the runtime environment. 1.354 + * 1.355 + * @param newLocale Locale to set to. If NULL, set to the value obtained 1.356 + * from the runtime environement. 1.357 + * @param success The error code. 1.358 + * @system 1.359 + * @stable ICU 2.0 1.360 + */ 1.361 + static void U_EXPORT2 setDefault(const Locale& newLocale, 1.362 + UErrorCode& success); 1.363 +#endif /* U_HIDE_SYSTEM_API */ 1.364 + 1.365 + /** 1.366 + * Creates a locale which has had minimal canonicalization 1.367 + * as per uloc_getName(). 1.368 + * @param name The name to create from. If name is null, 1.369 + * the default Locale is used. 1.370 + * @return new locale object 1.371 + * @stable ICU 2.0 1.372 + * @see uloc_getName 1.373 + */ 1.374 + static Locale U_EXPORT2 createFromName(const char *name); 1.375 + 1.376 + /** 1.377 + * Creates a locale from the given string after canonicalizing 1.378 + * the string by calling uloc_canonicalize(). 1.379 + * @param name the locale ID to create from. Must not be NULL. 1.380 + * @return a new locale object corresponding to the given name 1.381 + * @stable ICU 3.0 1.382 + * @see uloc_canonicalize 1.383 + */ 1.384 + static Locale U_EXPORT2 createCanonical(const char* name); 1.385 + 1.386 + /** 1.387 + * Returns the locale's ISO-639 language code. 1.388 + * @return An alias to the code 1.389 + * @stable ICU 2.0 1.390 + */ 1.391 + inline const char * getLanguage( ) const; 1.392 + 1.393 + /** 1.394 + * Returns the locale's ISO-15924 abbreviation script code. 1.395 + * @return An alias to the code 1.396 + * @see uscript_getShortName 1.397 + * @see uscript_getCode 1.398 + * @stable ICU 2.8 1.399 + */ 1.400 + inline const char * getScript( ) const; 1.401 + 1.402 + /** 1.403 + * Returns the locale's ISO-3166 country code. 1.404 + * @return An alias to the code 1.405 + * @stable ICU 2.0 1.406 + */ 1.407 + inline const char * getCountry( ) const; 1.408 + 1.409 + /** 1.410 + * Returns the locale's variant code. 1.411 + * @return An alias to the code 1.412 + * @stable ICU 2.0 1.413 + */ 1.414 + inline const char * getVariant( ) const; 1.415 + 1.416 + /** 1.417 + * Returns the programmatic name of the entire locale, with the language, 1.418 + * country and variant separated by underbars. If a field is missing, up 1.419 + * to two leading underbars will occur. Example: "en", "de_DE", "en_US_WIN", 1.420 + * "de__POSIX", "fr__MAC", "__MAC", "_MT", "_FR_EURO" 1.421 + * @return A pointer to "name". 1.422 + * @stable ICU 2.0 1.423 + */ 1.424 + inline const char * getName() const; 1.425 + 1.426 + /** 1.427 + * Returns the programmatic name of the entire locale as getName() would return, 1.428 + * but without keywords. 1.429 + * @return A pointer to "name". 1.430 + * @see getName 1.431 + * @stable ICU 2.8 1.432 + */ 1.433 + const char * getBaseName() const; 1.434 + 1.435 + 1.436 + /** 1.437 + * Gets the list of keywords for the specified locale. 1.438 + * 1.439 + * @param status the status code 1.440 + * @return pointer to StringEnumeration class, or NULL if there are no keywords. 1.441 + * Client must dispose of it by calling delete. 1.442 + * @stable ICU 2.8 1.443 + */ 1.444 + StringEnumeration * createKeywords(UErrorCode &status) const; 1.445 + 1.446 + /** 1.447 + * Gets the value for a keyword. 1.448 + * 1.449 + * @param keywordName name of the keyword for which we want the value. Case insensitive. 1.450 + * @param buffer The buffer to receive the keyword value. 1.451 + * @param bufferCapacity The capacity of receiving buffer 1.452 + * @param status Returns any error information while performing this operation. 1.453 + * @return the length of the keyword value 1.454 + * 1.455 + * @stable ICU 2.8 1.456 + */ 1.457 + int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const; 1.458 + 1.459 + /** 1.460 + * Sets or removes the value for a keyword. 1.461 + * 1.462 + * For removing all keywords, use getBaseName(), 1.463 + * and construct a new Locale if it differs from getName(). 1.464 + * 1.465 + * @param keywordName name of the keyword to be set. Case insensitive. 1.466 + * @param keywordValue value of the keyword to be set. If 0-length or 1.467 + * NULL, will result in the keyword being removed. No error is given if 1.468 + * that keyword does not exist. 1.469 + * @param status Returns any error information while performing this operation. 1.470 + * 1.471 + * @stable ICU 49 1.472 + */ 1.473 + void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status); 1.474 + 1.475 + /** 1.476 + * returns the locale's three-letter language code, as specified 1.477 + * in ISO draft standard ISO-639-2. 1.478 + * @return An alias to the code, or an empty string 1.479 + * @stable ICU 2.0 1.480 + */ 1.481 + const char * getISO3Language() const; 1.482 + 1.483 + /** 1.484 + * Fills in "name" with the locale's three-letter ISO-3166 country code. 1.485 + * @return An alias to the code, or an empty string 1.486 + * @stable ICU 2.0 1.487 + */ 1.488 + const char * getISO3Country() const; 1.489 + 1.490 + /** 1.491 + * Returns the Windows LCID value corresponding to this locale. 1.492 + * This value is stored in the resource data for the locale as a one-to-four-digit 1.493 + * hexadecimal number. If the resource is missing, in the wrong format, or 1.494 + * there is no Windows LCID value that corresponds to this locale, returns 0. 1.495 + * @stable ICU 2.0 1.496 + */ 1.497 + uint32_t getLCID(void) const; 1.498 + 1.499 + /** 1.500 + * Fills in "dispLang" with the name of this locale's language in a format suitable for 1.501 + * user display in the default locale. For example, if the locale's language code is 1.502 + * "fr" and the default locale's language code is "en", this function would set 1.503 + * dispLang to "French". 1.504 + * @param dispLang Receives the language's display name. 1.505 + * @return A reference to "dispLang". 1.506 + * @stable ICU 2.0 1.507 + */ 1.508 + UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const; 1.509 + 1.510 + /** 1.511 + * Fills in "dispLang" with the name of this locale's language in a format suitable for 1.512 + * user display in the locale specified by "displayLocale". For example, if the locale's 1.513 + * language code is "en" and displayLocale's language code is "fr", this function would set 1.514 + * dispLang to "Anglais". 1.515 + * @param displayLocale Specifies the locale to be used to display the name. In other words, 1.516 + * if the locale's language code is "en", passing Locale::getFrench() for 1.517 + * displayLocale would result in "Anglais", while passing Locale::getGerman() 1.518 + * for displayLocale would result in "Englisch". 1.519 + * @param dispLang Receives the language's display name. 1.520 + * @return A reference to "dispLang". 1.521 + * @stable ICU 2.0 1.522 + */ 1.523 + UnicodeString& getDisplayLanguage( const Locale& displayLocale, 1.524 + UnicodeString& dispLang) const; 1.525 + 1.526 + /** 1.527 + * Fills in "dispScript" with the name of this locale's script in a format suitable 1.528 + * for user display in the default locale. For example, if the locale's script code 1.529 + * is "LATN" and the default locale's language code is "en", this function would set 1.530 + * dispScript to "Latin". 1.531 + * @param dispScript Receives the scripts's display name. 1.532 + * @return A reference to "dispScript". 1.533 + * @stable ICU 2.8 1.534 + */ 1.535 + UnicodeString& getDisplayScript( UnicodeString& dispScript) const; 1.536 + 1.537 + /** 1.538 + * Fills in "dispScript" with the name of this locale's country in a format suitable 1.539 + * for user display in the locale specified by "displayLocale". For example, if the locale's 1.540 + * script code is "LATN" and displayLocale's language code is "en", this function would set 1.541 + * dispScript to "Latin". 1.542 + * @param displayLocale Specifies the locale to be used to display the name. In other 1.543 + * words, if the locale's script code is "LATN", passing 1.544 + * Locale::getFrench() for displayLocale would result in "", while 1.545 + * passing Locale::getGerman() for displayLocale would result in 1.546 + * "". 1.547 + * @param dispScript Receives the scripts's display name. 1.548 + * @return A reference to "dispScript". 1.549 + * @stable ICU 2.8 1.550 + */ 1.551 + UnicodeString& getDisplayScript( const Locale& displayLocale, 1.552 + UnicodeString& dispScript) const; 1.553 + 1.554 + /** 1.555 + * Fills in "dispCountry" with the name of this locale's country in a format suitable 1.556 + * for user display in the default locale. For example, if the locale's country code 1.557 + * is "FR" and the default locale's language code is "en", this function would set 1.558 + * dispCountry to "France". 1.559 + * @param dispCountry Receives the country's display name. 1.560 + * @return A reference to "dispCountry". 1.561 + * @stable ICU 2.0 1.562 + */ 1.563 + UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const; 1.564 + 1.565 + /** 1.566 + * Fills in "dispCountry" with the name of this locale's country in a format suitable 1.567 + * for user display in the locale specified by "displayLocale". For example, if the locale's 1.568 + * country code is "US" and displayLocale's language code is "fr", this function would set 1.569 + * dispCountry to "États-Unis". 1.570 + * @param displayLocale Specifies the locale to be used to display the name. In other 1.571 + * words, if the locale's country code is "US", passing 1.572 + * Locale::getFrench() for displayLocale would result in "États-Unis", while 1.573 + * passing Locale::getGerman() for displayLocale would result in 1.574 + * "Vereinigte Staaten". 1.575 + * @param dispCountry Receives the country's display name. 1.576 + * @return A reference to "dispCountry". 1.577 + * @stable ICU 2.0 1.578 + */ 1.579 + UnicodeString& getDisplayCountry( const Locale& displayLocale, 1.580 + UnicodeString& dispCountry) const; 1.581 + 1.582 + /** 1.583 + * Fills in "dispVar" with the name of this locale's variant code in a format suitable 1.584 + * for user display in the default locale. 1.585 + * @param dispVar Receives the variant's name. 1.586 + * @return A reference to "dispVar". 1.587 + * @stable ICU 2.0 1.588 + */ 1.589 + UnicodeString& getDisplayVariant( UnicodeString& dispVar) const; 1.590 + 1.591 + /** 1.592 + * Fills in "dispVar" with the name of this locale's variant code in a format 1.593 + * suitable for user display in the locale specified by "displayLocale". 1.594 + * @param displayLocale Specifies the locale to be used to display the name. 1.595 + * @param dispVar Receives the variant's display name. 1.596 + * @return A reference to "dispVar". 1.597 + * @stable ICU 2.0 1.598 + */ 1.599 + UnicodeString& getDisplayVariant( const Locale& displayLocale, 1.600 + UnicodeString& dispVar) const; 1.601 + 1.602 + /** 1.603 + * Fills in "name" with the name of this locale in a format suitable for user display 1.604 + * in the default locale. This function uses getDisplayLanguage(), getDisplayCountry(), 1.605 + * and getDisplayVariant() to do its work, and outputs the display name in the format 1.606 + * "language (country[,variant])". For example, if the default locale is en_US, then 1.607 + * fr_FR's display name would be "French (France)", and es_MX_Traditional's display name 1.608 + * would be "Spanish (Mexico,Traditional)". 1.609 + * @param name Receives the locale's display name. 1.610 + * @return A reference to "name". 1.611 + * @stable ICU 2.0 1.612 + */ 1.613 + UnicodeString& getDisplayName( UnicodeString& name) const; 1.614 + 1.615 + /** 1.616 + * Fills in "name" with the name of this locale in a format suitable for user display 1.617 + * in the locale specfied by "displayLocale". This function uses getDisplayLanguage(), 1.618 + * getDisplayCountry(), and getDisplayVariant() to do its work, and outputs the display 1.619 + * name in the format "language (country[,variant])". For example, if displayLocale is 1.620 + * fr_FR, then en_US's display name would be "Anglais (États-Unis)", and no_NO_NY's 1.621 + * display name would be "norvégien (Norvège,NY)". 1.622 + * @param displayLocale Specifies the locale to be used to display the name. 1.623 + * @param name Receives the locale's display name. 1.624 + * @return A reference to "name". 1.625 + * @stable ICU 2.0 1.626 + */ 1.627 + UnicodeString& getDisplayName( const Locale& displayLocale, 1.628 + UnicodeString& name) const; 1.629 + 1.630 + /** 1.631 + * Generates a hash code for the locale. 1.632 + * @stable ICU 2.0 1.633 + */ 1.634 + int32_t hashCode(void) const; 1.635 + 1.636 + /** 1.637 + * Sets the locale to bogus 1.638 + * A bogus locale represents a non-existing locale associated 1.639 + * with services that can be instantiated from non-locale data 1.640 + * in addition to locale (for example, collation can be 1.641 + * instantiated from a locale and from a rule set). 1.642 + * @stable ICU 2.1 1.643 + */ 1.644 + void setToBogus(); 1.645 + 1.646 + /** 1.647 + * Gets the bogus state. Locale object can be bogus if it doesn't exist 1.648 + * @return FALSE if it is a real locale, TRUE if it is a bogus locale 1.649 + * @stable ICU 2.1 1.650 + */ 1.651 + UBool isBogus(void) const; 1.652 + 1.653 + /** 1.654 + * Returns a list of all installed locales. 1.655 + * @param count Receives the number of locales in the list. 1.656 + * @return A pointer to an array of Locale objects. This array is the list 1.657 + * of all locales with installed resource files. The called does NOT 1.658 + * get ownership of this list, and must NOT delete it. 1.659 + * @stable ICU 2.0 1.660 + */ 1.661 + static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count); 1.662 + 1.663 + /** 1.664 + * Gets a list of all available 2-letter country codes defined in ISO 3166. This is a 1.665 + * pointer to an array of pointers to arrays of char. All of these pointers are 1.666 + * owned by ICU-- do not delete them, and do not write through them. The array is 1.667 + * terminated with a null pointer. 1.668 + * @return a list of all available country codes 1.669 + * @stable ICU 2.0 1.670 + */ 1.671 + static const char* const* U_EXPORT2 getISOCountries(); 1.672 + 1.673 + /** 1.674 + * Gets a list of all available language codes defined in ISO 639. This is a pointer 1.675 + * to an array of pointers to arrays of char. All of these pointers are owned 1.676 + * by ICU-- do not delete them, and do not write through them. The array is 1.677 + * terminated with a null pointer. 1.678 + * @return a list of all available language codes 1.679 + * @stable ICU 2.0 1.680 + */ 1.681 + static const char* const* U_EXPORT2 getISOLanguages(); 1.682 + 1.683 + /** 1.684 + * ICU "poor man's RTTI", returns a UClassID for this class. 1.685 + * 1.686 + * @stable ICU 2.2 1.687 + */ 1.688 + static UClassID U_EXPORT2 getStaticClassID(); 1.689 + 1.690 + /** 1.691 + * ICU "poor man's RTTI", returns a UClassID for the actual class. 1.692 + * 1.693 + * @stable ICU 2.2 1.694 + */ 1.695 + virtual UClassID getDynamicClassID() const; 1.696 + 1.697 +protected: /* only protected for testing purposes. DO NOT USE. */ 1.698 +#ifndef U_HIDE_INTERNAL_API 1.699 + /** 1.700 + * Set this from a single POSIX style locale string. 1.701 + * @internal 1.702 + */ 1.703 + void setFromPOSIXID(const char *posixID); 1.704 +#endif /* U_HIDE_INTERNAL_API */ 1.705 + 1.706 +private: 1.707 + /** 1.708 + * Initialize the locale object with a new name. 1.709 + * Was deprecated - used in implementation - moved internal 1.710 + * 1.711 + * @param cLocaleID The new locale name. 1.712 + * @param canonicalize whether to call uloc_canonicalize on cLocaleID 1.713 + */ 1.714 + Locale& init(const char* cLocaleID, UBool canonicalize); 1.715 + 1.716 + /* 1.717 + * Internal constructor to allow construction of a locale object with 1.718 + * NO side effects. (Default constructor tries to get 1.719 + * the default locale.) 1.720 + */ 1.721 + enum ELocaleType { 1.722 + eBOGUS 1.723 + }; 1.724 + Locale(ELocaleType); 1.725 + 1.726 + /** 1.727 + * Initialize the locale cache for commonly used locales 1.728 + */ 1.729 + static Locale *getLocaleCache(void); 1.730 + 1.731 + char language[ULOC_LANG_CAPACITY]; 1.732 + char script[ULOC_SCRIPT_CAPACITY]; 1.733 + char country[ULOC_COUNTRY_CAPACITY]; 1.734 + int32_t variantBegin; 1.735 + char* fullName; 1.736 + char fullNameBuffer[ULOC_FULLNAME_CAPACITY]; 1.737 + // name without keywords 1.738 + char* baseName; 1.739 + char baseNameBuffer[ULOC_FULLNAME_CAPACITY]; 1.740 + 1.741 + UBool fIsBogus; 1.742 + 1.743 + static const Locale &getLocale(int locid); 1.744 + 1.745 + /** 1.746 + * A friend to allow the default locale to be set by either the C or C++ API. 1.747 + * @internal 1.748 + */ 1.749 + friend Locale *locale_set_default_internal(const char *, UErrorCode& status); 1.750 + 1.751 + /** 1.752 + * @internal 1.753 + */ 1.754 + friend void locale_available_init(); 1.755 +}; 1.756 + 1.757 +inline UBool 1.758 +Locale::operator!=(const Locale& other) const 1.759 +{ 1.760 + return !operator==(other); 1.761 +} 1.762 + 1.763 +inline const char * 1.764 +Locale::getCountry() const 1.765 +{ 1.766 + return country; 1.767 +} 1.768 + 1.769 +inline const char * 1.770 +Locale::getLanguage() const 1.771 +{ 1.772 + return language; 1.773 +} 1.774 + 1.775 +inline const char * 1.776 +Locale::getScript() const 1.777 +{ 1.778 + return script; 1.779 +} 1.780 + 1.781 +inline const char * 1.782 +Locale::getVariant() const 1.783 +{ 1.784 + getBaseName(); // lazy init 1.785 + return &baseName[variantBegin]; 1.786 +} 1.787 + 1.788 +inline const char * 1.789 +Locale::getName() const 1.790 +{ 1.791 + return fullName; 1.792 +} 1.793 + 1.794 +inline UBool 1.795 +Locale::isBogus(void) const { 1.796 + return fIsBogus; 1.797 +} 1.798 + 1.799 +U_NAMESPACE_END 1.800 + 1.801 +#endif