• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 ******************************************************************************
3 *
4 *   Copyright (C) 1996-2013, 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     /**
454      * Sets the value for a keyword.
455      *
456      * @param keywordName name of the keyword to be set. Case insensitive.
457      * @param keywordValue value of the keyword to be set. If 0-length or
458      *  NULL, will result in the keyword being removed. No error is given if
459      *  that keyword does not exist.
460      * @param status Returns any error information while performing this operation.
461      *
462      * @stable ICU 49
463      */
464     void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
465 
466     /**
467      * returns the locale's three-letter language code, as specified
468      * in ISO draft standard ISO-639-2.
469      * @return      An alias to the code, or an empty string
470      * @stable ICU 2.0
471      */
472     const char * getISO3Language() const;
473 
474     /**
475      * Fills in "name" with the locale's three-letter ISO-3166 country code.
476      * @return      An alias to the code, or an empty string
477      * @stable ICU 2.0
478      */
479     const char * getISO3Country() const;
480 
481     /**
482      * Returns the Windows LCID value corresponding to this locale.
483      * This value is stored in the resource data for the locale as a one-to-four-digit
484      * hexadecimal number.  If the resource is missing, in the wrong format, or
485      * there is no Windows LCID value that corresponds to this locale, returns 0.
486      * @stable ICU 2.0
487      */
488     uint32_t        getLCID(void) const;
489 
490     /**
491      * Fills in "dispLang" with the name of this locale's language in a format suitable for
492      * user display in the default locale.  For example, if the locale's language code is
493      * "fr" and the default locale's language code is "en", this function would set
494      * dispLang to "French".
495      * @param dispLang  Receives the language's display name.
496      * @return          A reference to "dispLang".
497      * @stable ICU 2.0
498      */
499     UnicodeString&  getDisplayLanguage(UnicodeString&   dispLang) const;
500 
501     /**
502      * Fills in "dispLang" with the name of this locale's language in a format suitable for
503      * user display in the locale specified by "displayLocale".  For example, if the locale's
504      * language code is "en" and displayLocale's language code is "fr", this function would set
505      * dispLang to "Anglais".
506      * @param displayLocale  Specifies the locale to be used to display the name.  In other words,
507      *                  if the locale's language code is "en", passing Locale::getFrench() for
508      *                  displayLocale would result in "Anglais", while passing Locale::getGerman()
509      *                  for displayLocale would result in "Englisch".
510      * @param dispLang  Receives the language's display name.
511      * @return          A reference to "dispLang".
512      * @stable ICU 2.0
513      */
514     UnicodeString&  getDisplayLanguage( const   Locale&         displayLocale,
515                                                 UnicodeString&  dispLang) const;
516 
517     /**
518      * Fills in "dispScript" with the name of this locale's script in a format suitable
519      * for user display in the default locale.  For example, if the locale's script code
520      * is "LATN" and the default locale's language code is "en", this function would set
521      * dispScript to "Latin".
522      * @param dispScript    Receives the scripts's display name.
523      * @return              A reference to "dispScript".
524      * @stable ICU 2.8
525      */
526     UnicodeString&  getDisplayScript(          UnicodeString& dispScript) const;
527 
528     /**
529      * Fills in "dispScript" with the name of this locale's country in a format suitable
530      * for user display in the locale specified by "displayLocale".  For example, if the locale's
531      * script code is "LATN" and displayLocale's language code is "en", this function would set
532      * dispScript to "Latin".
533      * @param displayLocale      Specifies the locale to be used to display the name.  In other
534      *                      words, if the locale's script code is "LATN", passing
535      *                      Locale::getFrench() for displayLocale would result in "", while
536      *                      passing Locale::getGerman() for displayLocale would result in
537      *                      "".
538      * @param dispScript    Receives the scripts's display name.
539      * @return              A reference to "dispScript".
540      * @stable ICU 2.8
541      */
542     UnicodeString&  getDisplayScript(  const   Locale&         displayLocale,
543                                                UnicodeString&  dispScript) const;
544 
545     /**
546      * Fills in "dispCountry" with the name of this locale's country in a format suitable
547      * for user display in the default locale.  For example, if the locale's country code
548      * is "FR" and the default locale's language code is "en", this function would set
549      * dispCountry to "France".
550      * @param dispCountry   Receives the country's display name.
551      * @return              A reference to "dispCountry".
552      * @stable ICU 2.0
553      */
554     UnicodeString&  getDisplayCountry(          UnicodeString& dispCountry) const;
555 
556     /**
557      * Fills in "dispCountry" with the name of this locale's country in a format suitable
558      * for user display in the locale specified by "displayLocale".  For example, if the locale's
559      * country code is "US" and displayLocale's language code is "fr", this function would set
560      * dispCountry to "&Eacute;tats-Unis".
561      * @param displayLocale      Specifies the locale to be used to display the name.  In other
562      *                      words, if the locale's country code is "US", passing
563      *                      Locale::getFrench() for displayLocale would result in "&Eacute;tats-Unis", while
564      *                      passing Locale::getGerman() for displayLocale would result in
565      *                      "Vereinigte Staaten".
566      * @param dispCountry   Receives the country's display name.
567      * @return              A reference to "dispCountry".
568      * @stable ICU 2.0
569      */
570     UnicodeString&  getDisplayCountry(  const   Locale&         displayLocale,
571                                                 UnicodeString&  dispCountry) const;
572 
573     /**
574      * Fills in "dispVar" with the name of this locale's variant code in a format suitable
575      * for user display in the default locale.
576      * @param dispVar   Receives the variant's name.
577      * @return          A reference to "dispVar".
578      * @stable ICU 2.0
579      */
580     UnicodeString&  getDisplayVariant(      UnicodeString& dispVar) const;
581 
582     /**
583      * Fills in "dispVar" with the name of this locale's variant code in a format
584      * suitable for user display in the locale specified by "displayLocale".
585      * @param displayLocale  Specifies the locale to be used to display the name.
586      * @param dispVar   Receives the variant's display name.
587      * @return          A reference to "dispVar".
588      * @stable ICU 2.0
589      */
590     UnicodeString&  getDisplayVariant(  const   Locale&         displayLocale,
591                                                 UnicodeString&  dispVar) const;
592 
593     /**
594      * Fills in "name" with the name of this locale in a format suitable for user display
595      * in the default locale.  This function uses getDisplayLanguage(), getDisplayCountry(),
596      * and getDisplayVariant() to do its work, and outputs the display name in the format
597      * "language (country[,variant])".  For example, if the default locale is en_US, then
598      * fr_FR's display name would be "French (France)", and es_MX_Traditional's display name
599      * would be "Spanish (Mexico,Traditional)".
600      * @param name  Receives the locale's display name.
601      * @return      A reference to "name".
602      * @stable ICU 2.0
603      */
604     UnicodeString&  getDisplayName(         UnicodeString&  name) const;
605 
606     /**
607      * Fills in "name" with the name of this locale in a format suitable for user display
608      * in the locale specfied by "displayLocale".  This function uses getDisplayLanguage(),
609      * getDisplayCountry(), and getDisplayVariant() to do its work, and outputs the display
610      * name in the format "language (country[,variant])".  For example, if displayLocale is
611      * fr_FR, then en_US's display name would be "Anglais (&Eacute;tats-Unis)", and no_NO_NY's
612      * display name would be "norv&eacute;gien (Norv&egrave;ge,NY)".
613      * @param displayLocale  Specifies the locale to be used to display the name.
614      * @param name      Receives the locale's display name.
615      * @return          A reference to "name".
616      * @stable ICU 2.0
617      */
618     UnicodeString&  getDisplayName( const   Locale&         displayLocale,
619                                             UnicodeString&  name) const;
620 
621     /**
622      * Generates a hash code for the locale.
623      * @stable ICU 2.0
624      */
625     int32_t         hashCode(void) const;
626 
627     /**
628      * Sets the locale to bogus
629      * A bogus locale represents a non-existing locale associated
630      * with services that can be instantiated from non-locale data
631      * in addition to locale (for example, collation can be
632      * instantiated from a locale and from a rule set).
633      * @stable ICU 2.1
634      */
635     void setToBogus();
636 
637     /**
638      * Gets the bogus state. Locale object can be bogus if it doesn't exist
639      * @return FALSE if it is a real locale, TRUE if it is a bogus locale
640      * @stable ICU 2.1
641      */
642     UBool isBogus(void) const;
643 
644     /**
645      * Returns a list of all installed locales.
646      * @param count Receives the number of locales in the list.
647      * @return      A pointer to an array of Locale objects.  This array is the list
648      *              of all locales with installed resource files.  The called does NOT
649      *              get ownership of this list, and must NOT delete it.
650      * @stable ICU 2.0
651      */
652     static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
653 
654     /**
655      * Gets a list of all available 2-letter country codes defined in ISO 3166.  This is a
656      * pointer to an array of pointers to arrays of char.  All of these pointers are
657      * owned by ICU-- do not delete them, and do not write through them.  The array is
658      * terminated with a null pointer.
659      * @return a list of all available country codes
660      * @stable ICU 2.0
661      */
662     static const char* const* U_EXPORT2 getISOCountries();
663 
664     /**
665      * Gets a list of all available language codes defined in ISO 639.  This is a pointer
666      * to an array of pointers to arrays of char.  All of these pointers are owned
667      * by ICU-- do not delete them, and do not write through them.  The array is
668      * terminated with a null pointer.
669      * @return a list of all available language codes
670      * @stable ICU 2.0
671      */
672     static const char* const* U_EXPORT2 getISOLanguages();
673 
674     /**
675      * ICU "poor man's RTTI", returns a UClassID for this class.
676      *
677      * @stable ICU 2.2
678      */
679     static UClassID U_EXPORT2 getStaticClassID();
680 
681     /**
682      * ICU "poor man's RTTI", returns a UClassID for the actual class.
683      *
684      * @stable ICU 2.2
685      */
686     virtual UClassID getDynamicClassID() const;
687 
688 protected: /* only protected for testing purposes. DO NOT USE. */
689 #ifndef U_HIDE_INTERNAL_API
690     /**
691      * Set this from a single POSIX style locale string.
692      * @internal
693      */
694     void setFromPOSIXID(const char *posixID);
695 #endif  /* U_HIDE_INTERNAL_API */
696 
697 private:
698     /**
699      * Initialize the locale object with a new name.
700      * Was deprecated - used in implementation - moved internal
701      *
702      * @param cLocaleID The new locale name.
703      * @param canonicalize whether to call uloc_canonicalize on cLocaleID
704      */
705     Locale& init(const char* cLocaleID, UBool canonicalize);
706 
707     /*
708      * Internal constructor to allow construction of a locale object with
709      *   NO side effects.   (Default constructor tries to get
710      *   the default locale.)
711      */
712     enum ELocaleType {
713         eBOGUS
714     };
715     Locale(ELocaleType);
716 
717     /**
718      * Initialize the locale cache for commonly used locales
719      */
720     static Locale *getLocaleCache(void);
721 
722     char language[ULOC_LANG_CAPACITY];
723     char script[ULOC_SCRIPT_CAPACITY];
724     char country[ULOC_COUNTRY_CAPACITY];
725     int32_t variantBegin;
726     char* fullName;
727     char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
728     // name without keywords
729     char* baseName;
730     char baseNameBuffer[ULOC_FULLNAME_CAPACITY];
731 
732     UBool fIsBogus;
733 
734     static const Locale &getLocale(int locid);
735 
736     /**
737      * A friend to allow the default locale to be set by either the C or C++ API.
738      * @internal
739      */
740     friend Locale *locale_set_default_internal(const char *, UErrorCode& status);
741 };
742 
743 inline UBool
744 Locale::operator!=(const    Locale&     other) const
745 {
746     return !operator==(other);
747 }
748 
749 inline const char *
getCountry()750 Locale::getCountry() const
751 {
752     return country;
753 }
754 
755 inline const char *
getLanguage()756 Locale::getLanguage() const
757 {
758     return language;
759 }
760 
761 inline const char *
getScript()762 Locale::getScript() const
763 {
764     return script;
765 }
766 
767 inline const char *
getVariant()768 Locale::getVariant() const
769 {
770     getBaseName(); // lazy init
771     return &baseName[variantBegin];
772 }
773 
774 inline const char *
getName()775 Locale::getName() const
776 {
777     return fullName;
778 }
779 
780 inline UBool
isBogus(void)781 Locale::isBogus(void) const {
782     return fIsBogus;
783 }
784 
785 U_NAMESPACE_END
786 
787 #endif
788