| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 ****************************************************************************** | |
| 3 * | |
| 4 * Copyright (C) 1996-2010, International Business Machines | |
| 5 * Corporation and others. All Rights Reserved. | |
| 6 * | |
| 7 ****************************************************************************** | |
| 8 * | |
| 9 * File locid.h | |
| 10 * | |
| 11 * Created by: Helena Shih | |
| 12 * | |
| 13 * Modification History: | |
| 14 * | |
| 15 * Date Name Description | |
| 16 * 02/11/97 aliu Changed gLocPath to fgLocPath and added methods to | |
| 17 * get and set it. | |
| 18 * 04/02/97 aliu Made operator!= inline; fixed return value of getNam
e(). | |
| 19 * 04/15/97 aliu Cleanup for AIX/Win32. | |
| 20 * 04/24/97 aliu Numerous changes per code review. | |
| 21 * 08/18/98 stephen Added tokenizeString(),changed getDisplayName() | |
| 22 * 09/08/98 stephen Moved definition of kEmptyString for Mac Port | |
| 23 * 11/09/99 weiv Added const char * getName() const; | |
| 24 * 04/12/00 srl removing unicodestring api's and cached hash code | |
| 25 * 08/10/01 grhoten Change the static Locales to accessor functions | |
| 26 ****************************************************************************** | |
| 27 */ | |
| 28 | |
| 29 #ifndef LOCID_H | |
| 30 #define LOCID_H | |
| 31 | |
| 32 #include "unicode/utypes.h" | |
| 33 #include "unicode/uobject.h" | |
| 34 #include "unicode/unistr.h" | |
| 35 #include "unicode/putil.h" | |
| 36 #include "unicode/uloc.h" | |
| 37 #include "unicode/strenum.h" | |
| 38 | |
| 39 /** | |
| 40 * \file | |
| 41 * \brief C++ API: Locale ID object. | |
| 42 */ | |
| 43 | |
| 44 /** | |
| 45 * A <code>Locale</code> object represents a specific geographical, political, | |
| 46 * or cultural region. An operation that requires a <code>Locale</code> to perfo
rm | |
| 47 * its task is called <em>locale-sensitive</em> and uses the <code>Locale</code> | |
| 48 * to tailor information for the user. For example, displaying a number | |
| 49 * is a locale-sensitive operation--the number should be formatted | |
| 50 * according to the customs/conventions of the user's native country, | |
| 51 * region, or culture. | |
| 52 * | |
| 53 * The Locale class is not suitable for subclassing. | |
| 54 * | |
| 55 * <P> | |
| 56 * You can create a <code>Locale</code> object using the constructor in | |
| 57 * this class: | |
| 58 * \htmlonly<blockquote>\endhtmlonly | |
| 59 * <pre> | |
| 60 * Locale( const char* language, | |
| 61 * const char* country, | |
| 62 * const char* variant); | |
| 63 * </pre> | |
| 64 * \htmlonly</blockquote>\endhtmlonly | |
| 65 * The first argument to the constructors is a valid <STRONG>ISO | |
| 66 * Language Code.</STRONG> These codes are the lower-case two-letter | |
| 67 * codes as defined by ISO-639. | |
| 68 * You can find a full list of these codes at: | |
| 69 * <BR><a href ="http://www.loc.gov/standards/iso639-2/"> | |
| 70 * http://www.loc.gov/standards/iso639-2/</a> | |
| 71 * | |
| 72 * <P> | |
| 73 * The second argument to the constructors is a valid <STRONG>ISO Country | |
| 74 * Code.</STRONG> These codes are the upper-case two-letter codes | |
| 75 * as defined by ISO-3166. | |
| 76 * You can find a full list of these codes at a number of sites, such as: | |
| 77 * <BR><a href="http://www.iso.org/iso/en/prods-services/iso3166ma/index.html"> | |
| 78 * http://www.iso.org/iso/en/prods-services/iso3166ma/index.html</a> | |
| 79 * | |
| 80 * <P> | |
| 81 * The third constructor requires a third argument--the <STRONG>Variant.</STRONG
> | |
| 82 * The Variant codes are vendor and browser-specific. | |
| 83 * For example, use REVISED for a langauge's revised script orthography, and POS
IX for POSIX. | |
| 84 * Where there are two variants, separate them with an underscore, and | |
| 85 * put the most important one first. For | |
| 86 * example, a Traditional Spanish collation might be referenced, with | |
| 87 * "ES", "ES", "Traditional_POSIX". | |
| 88 * | |
| 89 * <P> | |
| 90 * Because a <code>Locale</code> object is just an identifier for a region, | |
| 91 * no validity check is performed when you construct a <code>Locale</code>. | |
| 92 * If you want to see whether particular resources are available for the | |
| 93 * <code>Locale</code> you construct, you must query those resources. For | |
| 94 * example, ask the <code>NumberFormat</code> for the locales it supports | |
| 95 * using its <code>getAvailableLocales</code> method. | |
| 96 * <BR><STRONG>Note:</STRONG> When you ask for a resource for a particular | |
| 97 * locale, you get back the best available match, not necessarily | |
| 98 * precisely what you asked for. For more information, look at | |
| 99 * <code>ResourceBundle</code>. | |
| 100 * | |
| 101 * <P> | |
| 102 * The <code>Locale</code> class provides a number of convenient constants | |
| 103 * that you can use to create <code>Locale</code> objects for commonly used | |
| 104 * locales. For example, the following refers to a <code>Locale</code> object | |
| 105 * for the United States: | |
| 106 * \htmlonly<blockquote>\endhtmlonly | |
| 107 * <pre> | |
| 108 * Locale::getUS() | |
| 109 * </pre> | |
| 110 * \htmlonly</blockquote>\endhtmlonly | |
| 111 * | |
| 112 * <P> | |
| 113 * Once you've created a <code>Locale</code> you can query it for information ab
out | |
| 114 * itself. Use <code>getCountry</code> to get the ISO Country Code and | |
| 115 * <code>getLanguage</code> to get the ISO Language Code. You can | |
| 116 * use <code>getDisplayCountry</code> to get the | |
| 117 * name of the country suitable for displaying to the user. Similarly, | |
| 118 * you can use <code>getDisplayLanguage</code> to get the name of | |
| 119 * the language suitable for displaying to the user. Interestingly, | |
| 120 * the <code>getDisplayXXX</code> methods are themselves locale-sensitive | |
| 121 * and have two versions: one that uses the default locale and one | |
| 122 * that takes a locale as an argument and displays the name or country in | |
| 123 * a language appropriate to that locale. | |
| 124 * | |
| 125 * <P> | |
| 126 * ICU provides a number of classes that perform locale-sensitive | |
| 127 * operations. For example, the <code>NumberFormat</code> class formats | |
| 128 * numbers, currency, or percentages in a locale-sensitive manner. Classes | |
| 129 * such as <code>NumberFormat</code> have a number of convenience methods | |
| 130 * for creating a default object of that type. For example, the | |
| 131 * <code>NumberFormat</code> class provides these three convenience methods | |
| 132 * for creating a default <code>NumberFormat</code> object: | |
| 133 * \htmlonly<blockquote>\endhtmlonly | |
| 134 * <pre> | |
| 135 * UErrorCode success = U_ZERO_ERROR; | |
| 136 * Locale myLocale; | |
| 137 * NumberFormat *nf; | |
| 138 * | |
| 139 * nf = NumberFormat::createInstance( success ); delete nf; | |
| 140 * nf = NumberFormat::createCurrencyInstance( success ); delete nf; | |
| 141 * nf = NumberFormat::createPercentInstance( success ); delete nf; | |
| 142 * </pre> | |
| 143 * \htmlonly</blockquote>\endhtmlonly | |
| 144 * Each of these methods has two variants; one with an explicit locale | |
| 145 * and one without; the latter using the default locale. | |
| 146 * \htmlonly<blockquote>\endhtmlonly | |
| 147 * <pre> | |
| 148 * nf = NumberFormat::createInstance( myLocale, success ); delete n
f; | |
| 149 * nf = NumberFormat::createCurrencyInstance( myLocale, success ); delete n
f; | |
| 150 * nf = NumberFormat::createPercentInstance( myLocale, success ); delete n
f; | |
| 151 * </pre> | |
| 152 * \htmlonly</blockquote>\endhtmlonly | |
| 153 * A <code>Locale</code> is the mechanism for identifying the kind of object | |
| 154 * (<code>NumberFormat</code>) that you would like to get. The locale is | |
| 155 * <STRONG>just</STRONG> a mechanism for identifying objects, | |
| 156 * <STRONG>not</STRONG> a container for the objects themselves. | |
| 157 * | |
| 158 * <P> | |
| 159 * Each class that performs locale-sensitive operations allows you | |
| 160 * to get all the available objects of that type. You can sift | |
| 161 * through these objects by language, country, or variant, | |
| 162 * and use the display names to present a menu to the user. | |
| 163 * For example, you can create a menu of all the collation objects | |
| 164 * suitable for a given language. Such classes implement these | |
| 165 * three class methods: | |
| 166 * \htmlonly<blockquote>\endhtmlonly | |
| 167 * <pre> | |
| 168 * static Locale* getAvailableLocales(int32_t& numLocales) | |
| 169 * static UnicodeString& getDisplayName(const Locale& objectLocale, | |
| 170 * const Locale& displayLocale, | |
| 171 * UnicodeString& displayName) | |
| 172 * static UnicodeString& getDisplayName(const Locale& objectLocale, | |
| 173 * UnicodeString& displayName) | |
| 174 * </pre> | |
| 175 * \htmlonly</blockquote>\endhtmlonly | |
| 176 * | |
| 177 * @stable ICU 2.0 | |
| 178 * @see ResourceBundle | |
| 179 */ | |
| 180 U_NAMESPACE_BEGIN | |
| 181 class U_COMMON_API Locale : public UObject { | |
| 182 public: | |
| 183 /** Useful constant for the Root locale. @stable ICU 4.4 */ | |
| 184 static const Locale &U_EXPORT2 getRoot(void); | |
| 185 /** Useful constant for this language. @stable ICU 2.0 */ | |
| 186 static const Locale &U_EXPORT2 getEnglish(void); | |
| 187 /** Useful constant for this language. @stable ICU 2.0 */ | |
| 188 static const Locale &U_EXPORT2 getFrench(void); | |
| 189 /** Useful constant for this language. @stable ICU 2.0 */ | |
| 190 static const Locale &U_EXPORT2 getGerman(void); | |
| 191 /** Useful constant for this language. @stable ICU 2.0 */ | |
| 192 static const Locale &U_EXPORT2 getItalian(void); | |
| 193 /** Useful constant for this language. @stable ICU 2.0 */ | |
| 194 static const Locale &U_EXPORT2 getJapanese(void); | |
| 195 /** Useful constant for this language. @stable ICU 2.0 */ | |
| 196 static const Locale &U_EXPORT2 getKorean(void); | |
| 197 /** Useful constant for this language. @stable ICU 2.0 */ | |
| 198 static const Locale &U_EXPORT2 getChinese(void); | |
| 199 /** Useful constant for this language. @stable ICU 2.0 */ | |
| 200 static const Locale &U_EXPORT2 getSimplifiedChinese(void); | |
| 201 /** Useful constant for this language. @stable ICU 2.0 */ | |
| 202 static const Locale &U_EXPORT2 getTraditionalChinese(void); | |
| 203 | |
| 204 /** Useful constant for this country/region. @stable ICU 2.0 */ | |
| 205 static const Locale &U_EXPORT2 getFrance(void); | |
| 206 /** Useful constant for this country/region. @stable ICU 2.0 */ | |
| 207 static const Locale &U_EXPORT2 getGermany(void); | |
| 208 /** Useful constant for this country/region. @stable ICU 2.0 */ | |
| 209 static const Locale &U_EXPORT2 getItaly(void); | |
| 210 /** Useful constant for this country/region. @stable ICU 2.0 */ | |
| 211 static const Locale &U_EXPORT2 getJapan(void); | |
| 212 /** Useful constant for this country/region. @stable ICU 2.0 */ | |
| 213 static const Locale &U_EXPORT2 getKorea(void); | |
| 214 /** Useful constant for this country/region. @stable ICU 2.0 */ | |
| 215 static const Locale &U_EXPORT2 getChina(void); | |
| 216 /** Useful constant for this country/region. @stable ICU 2.0 */ | |
| 217 static const Locale &U_EXPORT2 getPRC(void); | |
| 218 /** Useful constant for this country/region. @stable ICU 2.0 */ | |
| 219 static const Locale &U_EXPORT2 getTaiwan(void); | |
| 220 /** Useful constant for this country/region. @stable ICU 2.0 */ | |
| 221 static const Locale &U_EXPORT2 getUK(void); | |
| 222 /** Useful constant for this country/region. @stable ICU 2.0 */ | |
| 223 static const Locale &U_EXPORT2 getUS(void); | |
| 224 /** Useful constant for this country/region. @stable ICU 2.0 */ | |
| 225 static const Locale &U_EXPORT2 getCanada(void); | |
| 226 /** Useful constant for this country/region. @stable ICU 2.0 */ | |
| 227 static const Locale &U_EXPORT2 getCanadaFrench(void); | |
| 228 | |
| 229 | |
| 230 /** | |
| 231 * Construct a default locale object, a Locale for the default locale ID. | |
| 232 * | |
| 233 * @see getDefault | |
| 234 * @see uloc_getDefault | |
| 235 * @stable ICU 2.0 | |
| 236 */ | |
| 237 Locale(); | |
| 238 | |
| 239 /** | |
| 240 * Construct a locale from language, country, variant. | |
| 241 * If an error occurs, then the constructed object will be "bogus" | |
| 242 * (isBogus() will return TRUE). | |
| 243 * | |
| 244 * @param language Lowercase two-letter or three-letter ISO-639 code. | |
| 245 * This parameter can instead be an ICU style C locale (e.g. "en_US"), | |
| 246 * but the other parameters must not be used. | |
| 247 * This parameter can be NULL; if so, | |
| 248 * the locale is initialized to match the current default locale. | |
| 249 * (This is the same as using the default constructor.) | |
| 250 * Please note: The Java Locale class does NOT accept the form | |
| 251 * 'new Locale("en_US")' but only 'new Locale("en","US")' | |
| 252 * | |
| 253 * @param country Uppercase two-letter ISO-3166 code. (optional) | |
| 254 * @param variant Uppercase vendor and browser specific code. See class | |
| 255 * description. (optional) | |
| 256 * @param keywordsAndValues A string consisting of keyword/values pairs, suc
h as | |
| 257 * "collation=phonebook;currency=euro" | |
| 258 * | |
| 259 * @see getDefault | |
| 260 * @see uloc_getDefault | |
| 261 * @stable ICU 2.0 | |
| 262 */ | |
| 263 Locale( const char * language, | |
| 264 const char * country = 0, | |
| 265 const char * variant = 0, | |
| 266 const char * keywordsAndValues = 0); | |
| 267 | |
| 268 /** | |
| 269 * Initializes a Locale object from another Locale object. | |
| 270 * | |
| 271 * @param other The Locale object being copied in. | |
| 272 * @stable ICU 2.0 | |
| 273 */ | |
| 274 Locale(const Locale& other); | |
| 275 | |
| 276 | |
| 277 /** | |
| 278 * Destructor | |
| 279 * @stable ICU 2.0 | |
| 280 */ | |
| 281 virtual ~Locale() ; | |
| 282 | |
| 283 /** | |
| 284 * Replaces the entire contents of *this with the specified value. | |
| 285 * | |
| 286 * @param other The Locale object being copied in. | |
| 287 * @return *this | |
| 288 * @stable ICU 2.0 | |
| 289 */ | |
| 290 Locale& operator=(const Locale& other); | |
| 291 | |
| 292 /** | |
| 293 * Checks if two locale keys are the same. | |
| 294 * | |
| 295 * @param other The locale key object to be compared with this. | |
| 296 * @return True if the two locale keys are the same, false otherwise. | |
| 297 * @stable ICU 2.0 | |
| 298 */ | |
| 299 UBool operator==(const Locale& other) const; | |
| 300 | |
| 301 /** | |
| 302 * Checks if two locale keys are not the same. | |
| 303 * | |
| 304 * @param other The locale key object to be compared with this. | |
| 305 * @return True if the two locale keys are not the same, false | |
| 306 * otherwise. | |
| 307 * @stable ICU 2.0 | |
| 308 */ | |
| 309 UBool operator!=(const Locale& other) const; | |
| 310 | |
| 311 /** | |
| 312 * Clone this object. | |
| 313 * Clones can be used concurrently in multiple threads. | |
| 314 * If an error occurs, then NULL is returned. | |
| 315 * The caller must delete the clone. | |
| 316 * | |
| 317 * @return a clone of this object | |
| 318 * | |
| 319 * @see getDynamicClassID | |
| 320 * @stable ICU 2.8 | |
| 321 */ | |
| 322 Locale *clone() const; | |
| 323 | |
| 324 /** | |
| 325 * Common methods of getting the current default Locale. Used for the | |
| 326 * presentation: menus, dialogs, etc. Generally set once when your applet or | |
| 327 * application is initialized, then never reset. (If you do reset the | |
| 328 * default locale, you probably want to reload your GUI, so that the change | |
| 329 * is reflected in your interface.) | |
| 330 * | |
| 331 * More advanced programs will allow users to use different locales for | |
| 332 * different fields, e.g. in a spreadsheet. | |
| 333 * | |
| 334 * Note that the initial setting will match the host system. | |
| 335 * @return a reference to the Locale object for the default locale ID | |
| 336 * @system | |
| 337 * @stable ICU 2.0 | |
| 338 */ | |
| 339 static const Locale& U_EXPORT2 getDefault(void); | |
| 340 | |
| 341 /** | |
| 342 * Sets the default. Normally set once at the beginning of a process, | |
| 343 * then never reset. | |
| 344 * setDefault() only changes ICU's default locale ID, <strong>not</strong> | |
| 345 * the default locale ID of the runtime environment. | |
| 346 * | |
| 347 * @param newLocale Locale to set to. If NULL, set to the value obtained | |
| 348 * from the runtime environement. | |
| 349 * @param success The error code. | |
| 350 * @system | |
| 351 * @stable ICU 2.0 | |
| 352 */ | |
| 353 static void U_EXPORT2 setDefault(const Locale& newLocale, | |
| 354 UErrorCode& success); | |
| 355 | |
| 356 /** | |
| 357 * Creates a locale which has had minimal canonicalization | |
| 358 * as per uloc_getName(). | |
| 359 * @param name The name to create from. If name is null, | |
| 360 * the default Locale is used. | |
| 361 * @return new locale object | |
| 362 * @stable ICU 2.0 | |
| 363 * @see uloc_getName | |
| 364 */ | |
| 365 static Locale U_EXPORT2 createFromName(const char *name); | |
| 366 | |
| 367 /** | |
| 368 * Creates a locale from the given string after canonicalizing | |
| 369 * the string by calling uloc_canonicalize(). | |
| 370 * @param name the locale ID to create from. Must not be NULL. | |
| 371 * @return a new locale object corresponding to the given name | |
| 372 * @stable ICU 3.0 | |
| 373 * @see uloc_canonicalize | |
| 374 */ | |
| 375 static Locale U_EXPORT2 createCanonical(const char* name); | |
| 376 | |
| 377 /** | |
| 378 * Returns the locale's ISO-639 language code. | |
| 379 * @return An alias to the code | |
| 380 * @stable ICU 2.0 | |
| 381 */ | |
| 382 inline const char * getLanguage( ) const; | |
| 383 | |
| 384 /** | |
| 385 * Returns the locale's ISO-15924 abbreviation script code. | |
| 386 * @return An alias to the code | |
| 387 * @see uscript_getShortName | |
| 388 * @see uscript_getCode | |
| 389 * @stable ICU 2.8 | |
| 390 */ | |
| 391 inline const char * getScript( ) const; | |
| 392 | |
| 393 /** | |
| 394 * Returns the locale's ISO-3166 country code. | |
| 395 * @return An alias to the code | |
| 396 * @stable ICU 2.0 | |
| 397 */ | |
| 398 inline const char * getCountry( ) const; | |
| 399 | |
| 400 /** | |
| 401 * Returns the locale's variant code. | |
| 402 * @return An alias to the code | |
| 403 * @stable ICU 2.0 | |
| 404 */ | |
| 405 inline const char * getVariant( ) const; | |
| 406 | |
| 407 /** | |
| 408 * Returns the programmatic name of the entire locale, with the language, | |
| 409 * country and variant separated by underbars. If a field is missing, up | |
| 410 * to two leading underbars will occur. Example: "en", "de_DE", "en_US_WIN", | |
| 411 * "de__POSIX", "fr__MAC", "__MAC", "_MT", "_FR_EURO" | |
| 412 * @return A pointer to "name". | |
| 413 * @stable ICU 2.0 | |
| 414 */ | |
| 415 inline const char * getName() const; | |
| 416 | |
| 417 /** | |
| 418 * Returns the programmatic name of the entire locale as getName would retur
n, | |
| 419 * but without keywords. | |
| 420 * @return A pointer to "name". | |
| 421 * @see getName | |
| 422 * @stable ICU 2.8 | |
| 423 */ | |
| 424 const char * getBaseName() const; | |
| 425 | |
| 426 | |
| 427 /** | |
| 428 * Gets the list of keywords for the specified locale. | |
| 429 * | |
| 430 * @param status the status code | |
| 431 * @return pointer to StringEnumeration class, or NULL if there are no keywo
rds. | |
| 432 * Client must dispose of it by calling delete. | |
| 433 * @stable ICU 2.8 | |
| 434 */ | |
| 435 StringEnumeration * createKeywords(UErrorCode &status) const; | |
| 436 | |
| 437 /** | |
| 438 * Get the value for a keyword. | |
| 439 * | |
| 440 * @param keywordName name of the keyword for which we want the value. Case
insensitive. | |
| 441 * @param buffer The buffer to receive the keyword value. | |
| 442 * @param bufferCapacity The capacity of receiving buffer | |
| 443 * @param status Returns any error information while performing this operati
on. | |
| 444 * @return the length of the keyword value | |
| 445 * | |
| 446 * @stable ICU 2.8 | |
| 447 */ | |
| 448 int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t buffe
rCapacity, UErrorCode &status) const; | |
| 449 | |
| 450 /** | |
| 451 * Set the value for a keyword. | |
| 452 * | |
| 453 * @param keywordName name of the keyword to be set. Case insensitive. | |
| 454 * @param keywordValue value of the keyword to be set. If 0-length or | |
| 455 * NULL, will result in the keyword being removed. No error is given if | |
| 456 * that keyword does not exist. | |
| 457 * @param status Returns any error information while performing this operati
on. | |
| 458 * | |
| 459 * @internal | |
| 460 */ | |
| 461 void setKeywordValue(const char* keywordName, const char* keywordValue, UErr
orCode &status); | |
| 462 | |
| 463 /** | |
| 464 * returns the locale's three-letter language code, as specified | |
| 465 * in ISO draft standard ISO-639-2. | |
| 466 * @return An alias to the code, or NULL | |
| 467 * @stable ICU 2.0 | |
| 468 */ | |
| 469 const char * getISO3Language() const; | |
| 470 | |
| 471 /** | |
| 472 * Fills in "name" with the locale's three-letter ISO-3166 country code. | |
| 473 * @return An alias to the code, or NULL | |
| 474 * @stable ICU 2.0 | |
| 475 */ | |
| 476 const char * getISO3Country() const; | |
| 477 | |
| 478 /** | |
| 479 * Returns the Windows LCID value corresponding to this locale. | |
| 480 * This value is stored in the resource data for the locale as a one-to-four
-digit | |
| 481 * hexadecimal number. If the resource is missing, in the wrong format, or | |
| 482 * there is no Windows LCID value that corresponds to this locale, returns 0
. | |
| 483 * @stable ICU 2.0 | |
| 484 */ | |
| 485 uint32_t getLCID(void) const; | |
| 486 | |
| 487 /** | |
| 488 * Fills in "dispLang" with the name of this locale's language in a format s
uitable for | |
| 489 * user display in the default locale. For example, if the locale's languag
e code is | |
| 490 * "fr" and the default locale's language code is "en", this function would
set | |
| 491 * dispLang to "French". | |
| 492 * @param dispLang Receives the language's display name. | |
| 493 * @return A reference to "dispLang". | |
| 494 * @stable ICU 2.0 | |
| 495 */ | |
| 496 UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const; | |
| 497 | |
| 498 /** | |
| 499 * Fills in "dispLang" with the name of this locale's language in a format s
uitable for | |
| 500 * user display in the locale specified by "displayLocale". For example, if
the locale's | |
| 501 * language code is "en" and displayLocale's language code is "fr", this fun
ction would set | |
| 502 * dispLang to "Anglais". | |
| 503 * @param displayLocale Specifies the locale to be used to display the name
. In other words, | |
| 504 * if the locale's language code is "en", passing Locale::g
etFrench() for | |
| 505 * displayLocale would result in "Anglais", while passing L
ocale::getGerman() | |
| 506 * for displayLocale would result in "Englisch". | |
| 507 * @param dispLang Receives the language's display name. | |
| 508 * @return A reference to "dispLang". | |
| 509 * @stable ICU 2.0 | |
| 510 */ | |
| 511 UnicodeString& getDisplayLanguage( const Locale& displayLocale, | |
| 512 UnicodeString& dispLang) const; | |
| 513 | |
| 514 /** | |
| 515 * Fills in "dispScript" with the name of this locale's script in a format s
uitable | |
| 516 * for user display in the default locale. For example, if the locale's scr
ipt code | |
| 517 * is "LATN" and the default locale's language code is "en", this function w
ould set | |
| 518 * dispScript to "Latin". | |
| 519 * @param dispScript Receives the scripts's display name. | |
| 520 * @return A reference to "dispScript". | |
| 521 * @stable ICU 2.8 | |
| 522 */ | |
| 523 UnicodeString& getDisplayScript( UnicodeString& dispScript) const; | |
| 524 | |
| 525 /** | |
| 526 * Fills in "dispScript" with the name of this locale's country in a format
suitable | |
| 527 * for user display in the locale specified by "displayLocale". For example
, if the locale's | |
| 528 * script code is "LATN" and displayLocale's language code is "en", this fun
ction would set | |
| 529 * dispScript to "Latin". | |
| 530 * @param displayLocale Specifies the locale to be used to display the
name. In other | |
| 531 * words, if the locale's script code is "LATN", passin
g | |
| 532 * Locale::getFrench() for displayLocale would result i
n "", while | |
| 533 * passing Locale::getGerman() for displayLocale would
result in | |
| 534 * "". | |
| 535 * @param dispScript Receives the scripts's display name. | |
| 536 * @return A reference to "dispScript". | |
| 537 * @stable ICU 2.8 | |
| 538 */ | |
| 539 UnicodeString& getDisplayScript( const Locale& displayLocale, | |
| 540 UnicodeString& dispScript) const
; | |
| 541 | |
| 542 /** | |
| 543 * Fills in "dispCountry" with the name of this locale's country in a format
suitable | |
| 544 * for user display in the default locale. For example, if the locale's cou
ntry code | |
| 545 * is "FR" and the default locale's language code is "en", this function wou
ld set | |
| 546 * dispCountry to "France". | |
| 547 * @param dispCountry Receives the country's display name. | |
| 548 * @return A reference to "dispCountry". | |
| 549 * @stable ICU 2.0 | |
| 550 */ | |
| 551 UnicodeString& getDisplayCountry( UnicodeString& dispCountry) cons
t; | |
| 552 | |
| 553 /** | |
| 554 * Fills in "dispCountry" with the name of this locale's country in a format
suitable | |
| 555 * for user display in the locale specified by "displayLocale". For example
, if the locale's | |
| 556 * country code is "US" and displayLocale's language code is "fr", this func
tion would set | |
| 557 * dispCountry to "États-Unis". | |
| 558 * @param displayLocale Specifies the locale to be used to display the
name. In other | |
| 559 * words, if the locale's country code is "US", passing | |
| 560 * Locale::getFrench() for displayLocale would result i
n "États-Unis", while | |
| 561 * passing Locale::getGerman() for displayLocale would
result in | |
| 562 * "Vereinigte Staaten". | |
| 563 * @param dispCountry Receives the country's display name. | |
| 564 * @return A reference to "dispCountry". | |
| 565 * @stable ICU 2.0 | |
| 566 */ | |
| 567 UnicodeString& getDisplayCountry( const Locale& displayLocale, | |
| 568 UnicodeString& dispCountry) con
st; | |
| 569 | |
| 570 /** | |
| 571 * Fills in "dispVar" with the name of this locale's variant code in a forma
t suitable | |
| 572 * for user display in the default locale. | |
| 573 * @param dispVar Receives the variant's name. | |
| 574 * @return A reference to "dispVar". | |
| 575 * @stable ICU 2.0 | |
| 576 */ | |
| 577 UnicodeString& getDisplayVariant( UnicodeString& dispVar) const; | |
| 578 | |
| 579 /** | |
| 580 * Fills in "dispVar" with the name of this locale's variant code in a forma
t | |
| 581 * suitable for user display in the locale specified by "displayLocale". | |
| 582 * @param displayLocale Specifies the locale to be used to display the name
. | |
| 583 * @param dispVar Receives the variant's display name. | |
| 584 * @return A reference to "dispVar". | |
| 585 * @stable ICU 2.0 | |
| 586 */ | |
| 587 UnicodeString& getDisplayVariant( const Locale& displayLocale, | |
| 588 UnicodeString& dispVar) const; | |
| 589 | |
| 590 /** | |
| 591 * Fills in "name" with the name of this locale in a format suitable for use
r display | |
| 592 * in the default locale. This function uses getDisplayLanguage(), getDispl
ayCountry(), | |
| 593 * and getDisplayVariant() to do its work, and outputs the display name in t
he format | |
| 594 * "language (country[,variant])". For example, if the default locale is en
_US, then | |
| 595 * fr_FR's display name would be "French (France)", and es_MX_Traditional's
display name | |
| 596 * would be "Spanish (Mexico,Traditional)". | |
| 597 * @param name Receives the locale's display name. | |
| 598 * @return A reference to "name". | |
| 599 * @stable ICU 2.0 | |
| 600 */ | |
| 601 UnicodeString& getDisplayName( UnicodeString& name) const; | |
| 602 | |
| 603 /** | |
| 604 * Fills in "name" with the name of this locale in a format suitable for use
r display | |
| 605 * in the locale specfied by "displayLocale". This function uses getDisplay
Language(), | |
| 606 * getDisplayCountry(), and getDisplayVariant() to do its work, and outputs
the display | |
| 607 * name in the format "language (country[,variant])". For example, if displ
ayLocale is | |
| 608 * fr_FR, then en_US's display name would be "Anglais (États-Unis)",
and no_NO_NY's | |
| 609 * display name would be "norvégien (Norvège,NY)". | |
| 610 * @param displayLocale Specifies the locale to be used to display the name
. | |
| 611 * @param name Receives the locale's display name. | |
| 612 * @return A reference to "name". | |
| 613 * @stable ICU 2.0 | |
| 614 */ | |
| 615 UnicodeString& getDisplayName( const Locale& displayLocale, | |
| 616 UnicodeString& name) const; | |
| 617 | |
| 618 /** | |
| 619 * Generates a hash code for the locale. | |
| 620 * @stable ICU 2.0 | |
| 621 */ | |
| 622 int32_t hashCode(void) const; | |
| 623 | |
| 624 /** | |
| 625 * Sets the locale to bogus | |
| 626 * A bogus locale represents a non-existing locale associated | |
| 627 * with services that can be instantiated from non-locale data | |
| 628 * in addition to locale (for example, collation can be | |
| 629 * instantiated from a locale and from a rule set). | |
| 630 * @stable ICU 2.1 | |
| 631 */ | |
| 632 void setToBogus(); | |
| 633 | |
| 634 /** | |
| 635 * Gets the bogus state. Locale object can be bogus if it doesn't exist | |
| 636 * @return FALSE if it is a real locale, TRUE if it is a bogus locale | |
| 637 * @stable ICU 2.1 | |
| 638 */ | |
| 639 UBool isBogus(void) const; | |
| 640 | |
| 641 /** | |
| 642 * Returns a list of all installed locales. | |
| 643 * @param count Receives the number of locales in the list. | |
| 644 * @return A pointer to an array of Locale objects. This array is the
list | |
| 645 * of all locales with installed resource files. The called do
es NOT | |
| 646 * get ownership of this list, and must NOT delete it. | |
| 647 * @stable ICU 2.0 | |
| 648 */ | |
| 649 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count); | |
| 650 | |
| 651 /** | |
| 652 * Gets a list of all available 2-letter country codes defined in ISO 3166.
This is a | |
| 653 * pointer to an array of pointers to arrays of char. All of these pointers
are | |
| 654 * owned by ICU-- do not delete them, and do not write through them. The ar
ray is | |
| 655 * terminated with a null pointer. | |
| 656 * @return a list of all available country codes | |
| 657 * @stable ICU 2.0 | |
| 658 */ | |
| 659 static const char* const* U_EXPORT2 getISOCountries(); | |
| 660 | |
| 661 /** | |
| 662 * Gets a list of all available language codes defined in ISO 639. This is
a pointer | |
| 663 * to an array of pointers to arrays of char. All of these pointers are own
ed | |
| 664 * by ICU-- do not delete them, and do not write through them. The array is | |
| 665 * terminated with a null pointer. | |
| 666 * @return a list of all available language codes | |
| 667 * @stable ICU 2.0 | |
| 668 */ | |
| 669 static const char* const* U_EXPORT2 getISOLanguages(); | |
| 670 | |
| 671 /** | |
| 672 * ICU "poor man's RTTI", returns a UClassID for this class. | |
| 673 * | |
| 674 * @stable ICU 2.2 | |
| 675 */ | |
| 676 static UClassID U_EXPORT2 getStaticClassID(); | |
| 677 | |
| 678 /** | |
| 679 * ICU "poor man's RTTI", returns a UClassID for the actual class. | |
| 680 * | |
| 681 * @stable ICU 2.2 | |
| 682 */ | |
| 683 virtual UClassID getDynamicClassID() const; | |
| 684 | |
| 685 protected: /* only protected for testing purposes. DO NOT USE. */ | |
| 686 /** | |
| 687 * Set this from a single POSIX style locale string. | |
| 688 * @internal | |
| 689 */ | |
| 690 void setFromPOSIXID(const char *posixID); | |
| 691 | |
| 692 private: | |
| 693 /** | |
| 694 * Initialize the locale object with a new name. | |
| 695 * Was deprecated - used in implementation - moved internal | |
| 696 * | |
| 697 * @param cLocaleID The new locale name. | |
| 698 */ | |
| 699 Locale& init(const char* cLocaleID, UBool canonicalize); | |
| 700 | |
| 701 /* | |
| 702 * Internal constructor to allow construction of a locale object with | |
| 703 * NO side effects. (Default constructor tries to get | |
| 704 * the default locale.) | |
| 705 */ | |
| 706 enum ELocaleType { | |
| 707 eBOGUS | |
| 708 }; | |
| 709 Locale(ELocaleType); | |
| 710 | |
| 711 /** | |
| 712 * Initialize the locale cache for commonly used locales | |
| 713 */ | |
| 714 static Locale *getLocaleCache(void); | |
| 715 | |
| 716 char language[ULOC_LANG_CAPACITY]; | |
| 717 char script[ULOC_SCRIPT_CAPACITY]; | |
| 718 char country[ULOC_COUNTRY_CAPACITY]; | |
| 719 int32_t variantBegin; | |
| 720 char* fullName; | |
| 721 char fullNameBuffer[ULOC_FULLNAME_CAPACITY]; | |
| 722 // name without keywords | |
| 723 char* baseName; | |
| 724 char baseNameBuffer[ULOC_FULLNAME_CAPACITY]; | |
| 725 | |
| 726 UBool fIsBogus; | |
| 727 | |
| 728 static const Locale &getLocale(int locid); | |
| 729 | |
| 730 /** | |
| 731 * A friend to allow the default locale to be set by either the C or C++ API
. | |
| 732 * @internal | |
| 733 */ | |
| 734 friend void locale_set_default_internal(const char *); | |
| 735 }; | |
| 736 | |
| 737 inline UBool | |
| 738 Locale::operator!=(const Locale& other) const | |
| 739 { | |
| 740 return !operator==(other); | |
| 741 } | |
| 742 | |
| 743 inline const char * | |
| 744 Locale::getCountry() const | |
| 745 { | |
| 746 return country; | |
| 747 } | |
| 748 | |
| 749 inline const char * | |
| 750 Locale::getLanguage() const | |
| 751 { | |
| 752 return language; | |
| 753 } | |
| 754 | |
| 755 inline const char * | |
| 756 Locale::getScript() const | |
| 757 { | |
| 758 return script; | |
| 759 } | |
| 760 | |
| 761 inline const char * | |
| 762 Locale::getVariant() const | |
| 763 { | |
| 764 getBaseName(); // lazy init | |
| 765 return &baseName[variantBegin]; | |
| 766 } | |
| 767 | |
| 768 inline const char * | |
| 769 Locale::getName() const | |
| 770 { | |
| 771 return fullName; | |
| 772 } | |
| 773 | |
| 774 inline UBool | |
| 775 Locale::isBogus(void) const { | |
| 776 return fIsBogus; | |
| 777 } | |
| 778 | |
| 779 U_NAMESPACE_END | |
| 780 | |
| 781 #endif | |
| OLD | NEW |