intl/icu/source/common/unicode/locid.h

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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

mercurial