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