]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/unicode/locid.h
f25c212e80820c1ead26acbe92bb0a25a7faf67b
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
6 * Copyright (C) 1996-2015, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 ******************************************************************************
13 * Created by: Helena Shih
15 * Modification History:
17 * Date Name Description
18 * 02/11/97 aliu Changed gLocPath to fgLocPath and added methods to
20 * 04/02/97 aliu Made operator!= inline; fixed return value of getName().
21 * 04/15/97 aliu Cleanup for AIX/Win32.
22 * 04/24/97 aliu Numerous changes per code review.
23 * 08/18/98 stephen Added tokenizeString(),changed getDisplayName()
24 * 09/08/98 stephen Moved definition of kEmptyString for Mac Port
25 * 11/09/99 weiv Added const char * getName() const;
26 * 04/12/00 srl removing unicodestring api's and cached hash code
27 * 08/10/01 grhoten Change the static Locales to accessor functions
28 ******************************************************************************
34 #include "unicode/bytestream.h"
35 #include "unicode/localpointer.h"
36 #include "unicode/strenum.h"
37 #include "unicode/stringpiece.h"
38 #include "unicode/utypes.h"
39 #include "unicode/uobject.h"
40 #include "unicode/putil.h"
41 #include "unicode/uloc.h"
45 * \brief C++ API: Locale ID object.
48 #if U_SHOW_CPLUSPLUS_API
51 // Forward Declarations
52 void U_CALLCONV
locale_available_init(); /**< @internal */
54 class StringEnumeration
;
58 * A <code>Locale</code> object represents a specific geographical, political,
59 * or cultural region. An operation that requires a <code>Locale</code> to perform
60 * its task is called <em>locale-sensitive</em> and uses the <code>Locale</code>
61 * to tailor information for the user. For example, displaying a number
62 * is a locale-sensitive operation--the number should be formatted
63 * according to the customs/conventions of the user's native country,
66 * The Locale class is not suitable for subclassing.
69 * You can create a <code>Locale</code> object using the constructor in
71 * \htmlonly<blockquote>\endhtmlonly
73 * Locale( const char* language,
74 * const char* country,
75 * const char* variant);
77 * \htmlonly</blockquote>\endhtmlonly
78 * The first argument to the constructors is a valid <STRONG>ISO
79 * Language Code.</STRONG> These codes are the lower-case two-letter
80 * codes as defined by ISO-639.
81 * You can find a full list of these codes at:
82 * <BR><a href ="http://www.loc.gov/standards/iso639-2/">
83 * http://www.loc.gov/standards/iso639-2/</a>
86 * The second argument to the constructors is a valid <STRONG>ISO Country
87 * Code.</STRONG> These codes are the upper-case two-letter codes
88 * as defined by ISO-3166.
89 * You can find a full list of these codes at a number of sites, such as:
90 * <BR><a href="http://www.iso.org/iso/en/prods-services/iso3166ma/index.html">
91 * http://www.iso.org/iso/en/prods-services/iso3166ma/index.html</a>
94 * The third constructor requires a third argument--the <STRONG>Variant.</STRONG>
95 * The Variant codes are vendor and browser-specific.
96 * For example, use REVISED for a language's revised script orthography, and POSIX for POSIX.
97 * Where there are two variants, separate them with an underscore, and
98 * put the most important one first. For
99 * example, a Traditional Spanish collation might be referenced, with
100 * "ES", "ES", "Traditional_POSIX".
103 * Because a <code>Locale</code> object is just an identifier for a region,
104 * no validity check is performed when you construct a <code>Locale</code>.
105 * If you want to see whether particular resources are available for the
106 * <code>Locale</code> you construct, you must query those resources. For
107 * example, ask the <code>NumberFormat</code> for the locales it supports
108 * using its <code>getAvailableLocales</code> method.
109 * <BR><STRONG>Note:</STRONG> When you ask for a resource for a particular
110 * locale, you get back the best available match, not necessarily
111 * precisely what you asked for. For more information, look at
112 * <code>ResourceBundle</code>.
115 * The <code>Locale</code> class provides a number of convenient constants
116 * that you can use to create <code>Locale</code> objects for commonly used
117 * locales. For example, the following refers to a <code>Locale</code> object
118 * for the United States:
119 * \htmlonly<blockquote>\endhtmlonly
123 * \htmlonly</blockquote>\endhtmlonly
126 * Once you've created a <code>Locale</code> you can query it for information about
127 * itself. Use <code>getCountry</code> to get the ISO Country Code and
128 * <code>getLanguage</code> to get the ISO Language Code. You can
129 * use <code>getDisplayCountry</code> to get the
130 * name of the country suitable for displaying to the user. Similarly,
131 * you can use <code>getDisplayLanguage</code> to get the name of
132 * the language suitable for displaying to the user. Interestingly,
133 * the <code>getDisplayXXX</code> methods are themselves locale-sensitive
134 * and have two versions: one that uses the default locale and one
135 * that takes a locale as an argument and displays the name or country in
136 * a language appropriate to that locale.
139 * ICU provides a number of classes that perform locale-sensitive
140 * operations. For example, the <code>NumberFormat</code> class formats
141 * numbers, currency, or percentages in a locale-sensitive manner. Classes
142 * such as <code>NumberFormat</code> have a number of convenience methods
143 * for creating a default object of that type. For example, the
144 * <code>NumberFormat</code> class provides these three convenience methods
145 * for creating a default <code>NumberFormat</code> object:
146 * \htmlonly<blockquote>\endhtmlonly
148 * UErrorCode success = U_ZERO_ERROR;
152 * nf = NumberFormat::createInstance( success ); delete nf;
153 * nf = NumberFormat::createCurrencyInstance( success ); delete nf;
154 * nf = NumberFormat::createPercentInstance( success ); delete nf;
156 * \htmlonly</blockquote>\endhtmlonly
157 * Each of these methods has two variants; one with an explicit locale
158 * and one without; the latter using the default locale.
159 * \htmlonly<blockquote>\endhtmlonly
161 * nf = NumberFormat::createInstance( myLocale, success ); delete nf;
162 * nf = NumberFormat::createCurrencyInstance( myLocale, success ); delete nf;
163 * nf = NumberFormat::createPercentInstance( myLocale, success ); delete nf;
165 * \htmlonly</blockquote>\endhtmlonly
166 * A <code>Locale</code> is the mechanism for identifying the kind of object
167 * (<code>NumberFormat</code>) that you would like to get. The locale is
168 * <STRONG>just</STRONG> a mechanism for identifying objects,
169 * <STRONG>not</STRONG> a container for the objects themselves.
172 * Each class that performs locale-sensitive operations allows you
173 * to get all the available objects of that type. You can sift
174 * through these objects by language, country, or variant,
175 * and use the display names to present a menu to the user.
176 * For example, you can create a menu of all the collation objects
177 * suitable for a given language. Such classes implement these
178 * three class methods:
179 * \htmlonly<blockquote>\endhtmlonly
181 * static Locale* getAvailableLocales(int32_t& numLocales)
182 * static UnicodeString& getDisplayName(const Locale& objectLocale,
183 * const Locale& displayLocale,
184 * UnicodeString& displayName)
185 * static UnicodeString& getDisplayName(const Locale& objectLocale,
186 * UnicodeString& displayName)
188 * \htmlonly</blockquote>\endhtmlonly
191 * @see ResourceBundle
193 class U_COMMON_API Locale
: public UObject
{
195 /** Useful constant for the Root locale. @stable ICU 4.4 */
196 static const Locale
&U_EXPORT2
getRoot(void);
197 /** Useful constant for this language. @stable ICU 2.0 */
198 static const Locale
&U_EXPORT2
getEnglish(void);
199 /** Useful constant for this language. @stable ICU 2.0 */
200 static const Locale
&U_EXPORT2
getFrench(void);
201 /** Useful constant for this language. @stable ICU 2.0 */
202 static const Locale
&U_EXPORT2
getGerman(void);
203 /** Useful constant for this language. @stable ICU 2.0 */
204 static const Locale
&U_EXPORT2
getItalian(void);
205 /** Useful constant for this language. @stable ICU 2.0 */
206 static const Locale
&U_EXPORT2
getJapanese(void);
207 /** Useful constant for this language. @stable ICU 2.0 */
208 static const Locale
&U_EXPORT2
getKorean(void);
209 /** Useful constant for this language. @stable ICU 2.0 */
210 static const Locale
&U_EXPORT2
getChinese(void);
211 /** Useful constant for this language. @stable ICU 2.0 */
212 static const Locale
&U_EXPORT2
getSimplifiedChinese(void);
213 /** Useful constant for this language. @stable ICU 2.0 */
214 static const Locale
&U_EXPORT2
getTraditionalChinese(void);
216 /** Useful constant for this country/region. @stable ICU 2.0 */
217 static const Locale
&U_EXPORT2
getFrance(void);
218 /** Useful constant for this country/region. @stable ICU 2.0 */
219 static const Locale
&U_EXPORT2
getGermany(void);
220 /** Useful constant for this country/region. @stable ICU 2.0 */
221 static const Locale
&U_EXPORT2
getItaly(void);
222 /** Useful constant for this country/region. @stable ICU 2.0 */
223 static const Locale
&U_EXPORT2
getJapan(void);
224 /** Useful constant for this country/region. @stable ICU 2.0 */
225 static const Locale
&U_EXPORT2
getKorea(void);
226 /** Useful constant for this country/region. @stable ICU 2.0 */
227 static const Locale
&U_EXPORT2
getChina(void);
228 /** Useful constant for this country/region. @stable ICU 2.0 */
229 static const Locale
&U_EXPORT2
getPRC(void);
230 /** Useful constant for this country/region. @stable ICU 2.0 */
231 static const Locale
&U_EXPORT2
getTaiwan(void);
232 /** Useful constant for this country/region. @stable ICU 2.0 */
233 static const Locale
&U_EXPORT2
getUK(void);
234 /** Useful constant for this country/region. @stable ICU 2.0 */
235 static const Locale
&U_EXPORT2
getUS(void);
236 /** Useful constant for this country/region. @stable ICU 2.0 */
237 static const Locale
&U_EXPORT2
getCanada(void);
238 /** Useful constant for this country/region. @stable ICU 2.0 */
239 static const Locale
&U_EXPORT2
getCanadaFrench(void);
243 * Construct a default locale object, a Locale for the default locale ID.
246 * @see uloc_getDefault
252 * Construct a locale from language, country, variant.
253 * If an error occurs, then the constructed object will be "bogus"
254 * (isBogus() will return TRUE).
256 * @param language Lowercase two-letter or three-letter ISO-639 code.
257 * This parameter can instead be an ICU style C locale (e.g. "en_US"),
258 * but the other parameters must not be used.
259 * This parameter can be NULL; if so,
260 * the locale is initialized to match the current default locale.
261 * (This is the same as using the default constructor.)
262 * Please note: The Java Locale class does NOT accept the form
263 * 'new Locale("en_US")' but only 'new Locale("en","US")'
265 * @param country Uppercase two-letter ISO-3166 code. (optional)
266 * @param variant Uppercase vendor and browser specific code. See class
267 * description. (optional)
268 * @param keywordsAndValues A string consisting of keyword/values pairs, such as
269 * "collation=phonebook;currency=euro"
272 * @see uloc_getDefault
275 Locale( const char * language
,
276 const char * country
= 0,
277 const char * variant
= 0,
278 const char * keywordsAndValues
= 0);
281 * Initializes a Locale object from another Locale object.
283 * @param other The Locale object being copied in.
286 Locale(const Locale
& other
);
288 #ifndef U_HIDE_DRAFT_API
290 * Move constructor; might leave source in bogus state.
291 * This locale will have the same contents that the source locale had.
293 * @param other The Locale object being moved in.
296 Locale(Locale
&& other
) U_NOEXCEPT
;
297 #endif // U_HIDE_DRAFT_API
306 * Replaces the entire contents of *this with the specified value.
308 * @param other The Locale object being copied in.
312 Locale
& operator=(const Locale
& other
);
314 #ifndef U_HIDE_DRAFT_API
316 * Move assignment operator; might leave source in bogus state.
317 * This locale will have the same contents that the source locale had.
318 * The behavior is undefined if *this and the source are the same object.
320 * @param other The Locale object being moved in.
324 Locale
& operator=(Locale
&& other
) U_NOEXCEPT
;
325 #endif // U_HIDE_DRAFT_API
328 * Checks if two locale keys are the same.
330 * @param other The locale key object to be compared with this.
331 * @return True if the two locale keys are the same, false otherwise.
334 UBool
operator==(const Locale
& other
) const;
337 * Checks if two locale keys are not the same.
339 * @param other The locale key object to be compared with this.
340 * @return True if the two locale keys are not the same, false
344 inline UBool
operator!=(const Locale
& other
) const;
348 * Clones can be used concurrently in multiple threads.
349 * If an error occurs, then NULL is returned.
350 * The caller must delete the clone.
352 * @return a clone of this object
354 * @see getDynamicClassID
357 Locale
*clone() const;
359 #ifndef U_HIDE_SYSTEM_API
361 * Common methods of getting the current default Locale. Used for the
362 * presentation: menus, dialogs, etc. Generally set once when your applet or
363 * application is initialized, then never reset. (If you do reset the
364 * default locale, you probably want to reload your GUI, so that the change
365 * is reflected in your interface.)
367 * More advanced programs will allow users to use different locales for
368 * different fields, e.g. in a spreadsheet.
370 * Note that the initial setting will match the host system.
371 * @return a reference to the Locale object for the default locale ID
375 static const Locale
& U_EXPORT2
getDefault(void);
378 * Sets the default. Normally set once at the beginning of a process,
380 * setDefault() only changes ICU's default locale ID, <strong>not</strong>
381 * the default locale ID of the runtime environment.
383 * @param newLocale Locale to set to. If NULL, set to the value obtained
384 * from the runtime environment.
385 * @param success The error code.
389 static void U_EXPORT2
setDefault(const Locale
& newLocale
,
390 UErrorCode
& success
);
391 #endif /* U_HIDE_SYSTEM_API */
393 #ifndef U_HIDE_DRAFT_API
395 * Returns a Locale for the specified BCP47 language tag string.
396 * If the specified language tag contains any ill-formed subtags,
397 * the first such subtag and all following subtags are ignored.
399 * This implements the 'Language-Tag' production of BCP47, and so
400 * supports grandfathered (regular and irregular) as well as private
401 * use language tags. Private use tags are represented as 'x-whatever',
402 * and grandfathered tags are converted to their canonical replacements
403 * where they exist. Note that a few grandfathered tags have no modern
404 * replacement, these will be converted using the fallback described in
405 * the first paragraph, so some information might be lost.
406 * @param tag the input BCP47 language tag.
407 * @param status error information if creating the Locale failed.
408 * @return the Locale for the specified BCP47 language tag.
411 static Locale U_EXPORT2
forLanguageTag(StringPiece tag
, UErrorCode
& status
);
414 * Returns a well-formed language tag for this Locale.
416 * <b>Note</b>: Any locale fields which do not satisfy the BCP47 syntax
417 * requirement will be silently omitted from the result.
419 * If this function fails, partial output may have been written to the sink.
421 * @param sink the output sink receiving the BCP47 language
422 * tag for this Locale.
423 * @param status error information if creating the language tag failed.
426 void toLanguageTag(ByteSink
& sink
, UErrorCode
& status
) const;
429 * Returns a well-formed language tag for this Locale.
431 * <b>Note</b>: Any locale fields which do not satisfy the BCP47 syntax
432 * requirement will be silently omitted from the result.
434 * @param status error information if creating the language tag failed.
435 * @return the BCP47 language tag for this Locale.
438 template<typename StringClass
>
439 inline StringClass
toLanguageTag(UErrorCode
& status
) const;
440 #endif // U_HIDE_DRAFT_API
443 * Creates a locale which has had minimal canonicalization
444 * as per uloc_getName().
445 * @param name The name to create from. If name is null,
446 * the default Locale is used.
447 * @return new locale object
451 static Locale U_EXPORT2
createFromName(const char *name
);
454 * Creates a locale from the given string after canonicalizing
455 * the string by calling uloc_canonicalize().
456 * @param name the locale ID to create from. Must not be NULL.
457 * @return a new locale object corresponding to the given name
459 * @see uloc_canonicalize
461 static Locale U_EXPORT2
createCanonical(const char* name
);
464 * Returns the locale's ISO-639 language code.
465 * @return An alias to the code
468 inline const char * getLanguage( ) const;
471 * Returns the locale's ISO-15924 abbreviation script code.
472 * @return An alias to the code
473 * @see uscript_getShortName
474 * @see uscript_getCode
477 inline const char * getScript( ) const;
480 * Returns the locale's ISO-3166 country code.
481 * @return An alias to the code
484 inline const char * getCountry( ) const;
487 * Returns the locale's variant code.
488 * @return An alias to the code
491 inline const char * getVariant( ) const;
494 * Returns the programmatic name of the entire locale, with the language,
495 * country and variant separated by underbars. If a field is missing, up
496 * to two leading underbars will occur. Example: "en", "de_DE", "en_US_WIN",
497 * "de__POSIX", "fr__MAC", "__MAC", "_MT", "_FR_EURO"
498 * @return A pointer to "name".
501 inline const char * getName() const;
504 * Returns the programmatic name of the entire locale as getName() would return,
505 * but without keywords.
506 * @return A pointer to "name".
510 const char * getBaseName() const;
512 #ifndef U_HIDE_DRAFT_API
514 * Add the likely subtags for this Locale, per the algorithm described
515 * in the following CLDR technical report:
517 * http://www.unicode.org/reports/tr35/#Likely_Subtags
519 * If this Locale is already in the maximal form, or not valid, or there is
520 * no data available for maximization, the Locale will be unchanged.
522 * For example, "und-Zzzz" cannot be maximized, since there is no
523 * reasonable maximization.
527 * "en" maximizes to "en_Latn_US"
529 * "de" maximizes to "de_Latn_US"
531 * "sr" maximizes to "sr_Cyrl_RS"
533 * "sh" maximizes to "sr_Latn_RS" (Note this will not reverse.)
535 * "zh_Hani" maximizes to "zh_Hans_CN" (Note this will not reverse.)
537 * @param status error information if maximizing this Locale failed.
538 * If this Locale is not well-formed, the error code is
539 * U_ILLEGAL_ARGUMENT_ERROR.
542 void addLikelySubtags(UErrorCode
& status
);
545 * Minimize the subtags for this Locale, per the algorithm described
546 * in the following CLDR technical report:
548 * http://www.unicode.org/reports/tr35/#Likely_Subtags
550 * If this Locale is already in the minimal form, or not valid, or there is
551 * no data available for minimization, the Locale will be unchanged.
553 * Since the minimization algorithm relies on proper maximization, see the
554 * comments for addLikelySubtags for reasons why there might not be any
559 * "en_Latn_US" minimizes to "en"
561 * "de_Latn_US" minimizes to "de"
563 * "sr_Cyrl_RS" minimizes to "sr"
565 * "zh_Hant_TW" minimizes to "zh_TW" (The region is preferred to the
566 * script, and minimizing to "zh" would imply "zh_Hans_CN".)
568 * @param status error information if maximizing this Locale failed.
569 * If this Locale is not well-formed, the error code is
570 * U_ILLEGAL_ARGUMENT_ERROR.
573 void minimizeSubtags(UErrorCode
& status
);
574 #endif // U_HIDE_DRAFT_API
577 * Gets the list of keywords for the specified locale.
579 * @param status the status code
580 * @return pointer to StringEnumeration class, or NULL if there are no keywords.
581 * Client must dispose of it by calling delete.
585 StringEnumeration
* createKeywords(UErrorCode
&status
) const;
587 #ifndef U_HIDE_DRAFT_API
590 * Gets the list of Unicode keywords for the specified locale.
592 * @param status the status code
593 * @return pointer to StringEnumeration class, or NULL if there are no keywords.
594 * Client must dispose of it by calling delete.
595 * @see getUnicodeKeywords
598 StringEnumeration
* createUnicodeKeywords(UErrorCode
&status
) const;
601 * Gets the set of keywords for this Locale.
603 * A wrapper to call createKeywords() and write the resulting
604 * keywords as standard strings (or compatible objects) into any kind of
605 * container that can be written to by an STL style output iterator.
607 * @param iterator an STL style output iterator to write the keywords to.
608 * @param status error information if creating set of keywords failed.
611 template<typename StringClass
, typename OutputIterator
>
612 inline void getKeywords(OutputIterator iterator
, UErrorCode
& status
) const;
615 * Gets the set of Unicode keywords for this Locale.
617 * A wrapper to call createUnicodeKeywords() and write the resulting
618 * keywords as standard strings (or compatible objects) into any kind of
619 * container that can be written to by an STL style output iterator.
621 * @param iterator an STL style output iterator to write the keywords to.
622 * @param status error information if creating set of keywords failed.
625 template<typename StringClass
, typename OutputIterator
>
626 inline void getUnicodeKeywords(OutputIterator iterator
, UErrorCode
& status
) const;
628 #endif // U_HIDE_DRAFT_API
631 * Gets the value for a keyword.
633 * This uses legacy keyword=value pairs, like "collation=phonebook".
635 * ICU4C doesn't do automatic conversion between legacy and Unicode
636 * keywords and values in getters and setters (as opposed to ICU4J).
638 * @param keywordName name of the keyword for which we want the value. Case insensitive.
639 * @param buffer The buffer to receive the keyword value.
640 * @param bufferCapacity The capacity of receiving buffer
641 * @param status Returns any error information while performing this operation.
642 * @return the length of the keyword value
646 int32_t getKeywordValue(const char* keywordName
, char *buffer
, int32_t bufferCapacity
, UErrorCode
&status
) const;
648 #ifndef U_HIDE_DRAFT_API
650 * Gets the value for a keyword.
652 * This uses legacy keyword=value pairs, like "collation=phonebook".
654 * ICU4C doesn't do automatic conversion between legacy and Unicode
655 * keywords and values in getters and setters (as opposed to ICU4J).
657 * @param keywordName name of the keyword for which we want the value.
658 * @param sink the sink to receive the keyword value.
659 * @param status error information if getting the value failed.
662 void getKeywordValue(StringPiece keywordName
, ByteSink
& sink
, UErrorCode
& status
) const;
665 * Gets the value for a keyword.
667 * This uses legacy keyword=value pairs, like "collation=phonebook".
669 * ICU4C doesn't do automatic conversion between legacy and Unicode
670 * keywords and values in getters and setters (as opposed to ICU4J).
672 * @param keywordName name of the keyword for which we want the value.
673 * @param status error information if getting the value failed.
674 * @return the keyword value.
677 template<typename StringClass
>
678 inline StringClass
getKeywordValue(StringPiece keywordName
, UErrorCode
& status
) const;
681 * Gets the Unicode value for a Unicode keyword.
683 * This uses Unicode key-value pairs, like "co-phonebk".
685 * ICU4C doesn't do automatic conversion between legacy and Unicode
686 * keywords and values in getters and setters (as opposed to ICU4J).
688 * @param keywordName name of the keyword for which we want the value.
689 * @param sink the sink to receive the keyword value.
690 * @param status error information if getting the value failed.
693 void getUnicodeKeywordValue(StringPiece keywordName
, ByteSink
& sink
, UErrorCode
& status
) const;
696 * Gets the Unicode value for a Unicode keyword.
698 * This uses Unicode key-value pairs, like "co-phonebk".
700 * ICU4C doesn't do automatic conversion between legacy and Unicode
701 * keywords and values in getters and setters (as opposed to ICU4J).
703 * @param keywordName name of the keyword for which we want the value.
704 * @param status error information if getting the value failed.
705 * @return the keyword value.
708 template<typename StringClass
>
709 inline StringClass
getUnicodeKeywordValue(StringPiece keywordName
, UErrorCode
& status
) const;
710 #endif // U_HIDE_DRAFT_API
713 * Sets or removes the value for a keyword.
715 * For removing all keywords, use getBaseName(),
716 * and construct a new Locale if it differs from getName().
718 * This uses legacy keyword=value pairs, like "collation=phonebook".
720 * ICU4C doesn't do automatic conversion between legacy and Unicode
721 * keywords and values in getters and setters (as opposed to ICU4J).
723 * @param keywordName name of the keyword to be set. Case insensitive.
724 * @param keywordValue value of the keyword to be set. If 0-length or
725 * NULL, will result in the keyword being removed. No error is given if
726 * that keyword does not exist.
727 * @param status Returns any error information while performing this operation.
731 void setKeywordValue(const char* keywordName
, const char* keywordValue
, UErrorCode
&status
);
733 #ifndef U_HIDE_DRAFT_API
735 * Sets or removes the value for a keyword.
737 * For removing all keywords, use getBaseName(),
738 * and construct a new Locale if it differs from getName().
740 * This uses legacy keyword=value pairs, like "collation=phonebook".
742 * ICU4C doesn't do automatic conversion between legacy and Unicode
743 * keywords and values in getters and setters (as opposed to ICU4J).
745 * @param keywordName name of the keyword to be set.
746 * @param keywordValue value of the keyword to be set. If 0-length or
747 * NULL, will result in the keyword being removed. No error is given if
748 * that keyword does not exist.
749 * @param status Returns any error information while performing this operation.
752 void setKeywordValue(StringPiece keywordName
, StringPiece keywordValue
, UErrorCode
& status
);
755 * Sets or removes the Unicode value for a Unicode keyword.
757 * For removing all keywords, use getBaseName(),
758 * and construct a new Locale if it differs from getName().
760 * This uses Unicode key-value pairs, like "co-phonebk".
762 * ICU4C doesn't do automatic conversion between legacy and Unicode
763 * keywords and values in getters and setters (as opposed to ICU4J).
765 * @param keywordName name of the keyword to be set.
766 * @param keywordValue value of the keyword to be set. If 0-length or
767 * NULL, will result in the keyword being removed. No error is given if
768 * that keyword does not exist.
769 * @param status Returns any error information while performing this operation.
772 void setUnicodeKeywordValue(StringPiece keywordName
, StringPiece keywordValue
, UErrorCode
& status
);
773 #endif // U_HIDE_DRAFT_API
776 * returns the locale's three-letter language code, as specified
777 * in ISO draft standard ISO-639-2.
778 * @return An alias to the code, or an empty string
781 const char * getISO3Language() const;
784 * Fills in "name" with the locale's three-letter ISO-3166 country code.
785 * @return An alias to the code, or an empty string
788 const char * getISO3Country() const;
791 * Returns the Windows LCID value corresponding to this locale.
792 * This value is stored in the resource data for the locale as a one-to-four-digit
793 * hexadecimal number. If the resource is missing, in the wrong format, or
794 * there is no Windows LCID value that corresponds to this locale, returns 0.
797 uint32_t getLCID(void) const;
800 * Returns whether this locale's script is written right-to-left.
801 * If there is no script subtag, then the likely script is used, see uloc_addLikelySubtags().
802 * If no likely script is known, then FALSE is returned.
804 * A script is right-to-left according to the CLDR script metadata
805 * which corresponds to whether the script's letters have Bidi_Class=R or AL.
807 * Returns TRUE for "ar" and "en-Hebr", FALSE for "zh" and "fa-Cyrl".
809 * @return TRUE if the locale's script is written right-to-left
812 UBool
isRightToLeft() const;
815 * Fills in "dispLang" with the name of this locale's language in a format suitable for
816 * user display in the default locale. For example, if the locale's language code is
817 * "fr" and the default locale's language code is "en", this function would set
818 * dispLang to "French".
819 * @param dispLang Receives the language's display name.
820 * @return A reference to "dispLang".
823 UnicodeString
& getDisplayLanguage(UnicodeString
& dispLang
) const;
826 * Fills in "dispLang" with the name of this locale's language in a format suitable for
827 * user display in the locale specified by "displayLocale". For example, if the locale's
828 * language code is "en" and displayLocale's language code is "fr", this function would set
829 * dispLang to "Anglais".
830 * @param displayLocale Specifies the locale to be used to display the name. In other words,
831 * if the locale's language code is "en", passing Locale::getFrench() for
832 * displayLocale would result in "Anglais", while passing Locale::getGerman()
833 * for displayLocale would result in "Englisch".
834 * @param dispLang Receives the language's display name.
835 * @return A reference to "dispLang".
838 UnicodeString
& getDisplayLanguage( const Locale
& displayLocale
,
839 UnicodeString
& dispLang
) const;
842 * Fills in "dispScript" with the name of this locale's script in a format suitable
843 * for user display in the default locale. For example, if the locale's script code
844 * is "LATN" and the default locale's language code is "en", this function would set
845 * dispScript to "Latin".
846 * @param dispScript Receives the scripts's display name.
847 * @return A reference to "dispScript".
850 UnicodeString
& getDisplayScript( UnicodeString
& dispScript
) const;
853 * Fills in "dispScript" with the name of this locale's country in a format suitable
854 * for user display in the locale specified by "displayLocale". For example, if the locale's
855 * script code is "LATN" and displayLocale's language code is "en", this function would set
856 * dispScript to "Latin".
857 * @param displayLocale Specifies the locale to be used to display the name. In other
858 * words, if the locale's script code is "LATN", passing
859 * Locale::getFrench() for displayLocale would result in "", while
860 * passing Locale::getGerman() for displayLocale would result in
862 * @param dispScript Receives the scripts's display name.
863 * @return A reference to "dispScript".
866 UnicodeString
& getDisplayScript( const Locale
& displayLocale
,
867 UnicodeString
& dispScript
) const;
870 * Fills in "dispCountry" with the name of this locale's country in a format suitable
871 * for user display in the default locale. For example, if the locale's country code
872 * is "FR" and the default locale's language code is "en", this function would set
873 * dispCountry to "France".
874 * @param dispCountry Receives the country's display name.
875 * @return A reference to "dispCountry".
878 UnicodeString
& getDisplayCountry( UnicodeString
& dispCountry
) const;
881 * Fills in "dispCountry" with the name of this locale's country in a format suitable
882 * for user display in the locale specified by "displayLocale". For example, if the locale's
883 * country code is "US" and displayLocale's language code is "fr", this function would set
884 * dispCountry to "États-Unis".
885 * @param displayLocale Specifies the locale to be used to display the name. In other
886 * words, if the locale's country code is "US", passing
887 * Locale::getFrench() for displayLocale would result in "États-Unis", while
888 * passing Locale::getGerman() for displayLocale would result in
889 * "Vereinigte Staaten".
890 * @param dispCountry Receives the country's display name.
891 * @return A reference to "dispCountry".
894 UnicodeString
& getDisplayCountry( const Locale
& displayLocale
,
895 UnicodeString
& dispCountry
) const;
898 * Fills in "dispVar" with the name of this locale's variant code in a format suitable
899 * for user display in the default locale.
900 * @param dispVar Receives the variant's name.
901 * @return A reference to "dispVar".
904 UnicodeString
& getDisplayVariant( UnicodeString
& dispVar
) const;
907 * Fills in "dispVar" with the name of this locale's variant code in a format
908 * suitable for user display in the locale specified by "displayLocale".
909 * @param displayLocale Specifies the locale to be used to display the name.
910 * @param dispVar Receives the variant's display name.
911 * @return A reference to "dispVar".
914 UnicodeString
& getDisplayVariant( const Locale
& displayLocale
,
915 UnicodeString
& dispVar
) const;
918 * Fills in "name" with the name of this locale in a format suitable for user display
919 * in the default locale. This function uses getDisplayLanguage(), getDisplayCountry(),
920 * and getDisplayVariant() to do its work, and outputs the display name in the format
921 * "language (country[,variant])". For example, if the default locale is en_US, then
922 * fr_FR's display name would be "French (France)", and es_MX_Traditional's display name
923 * would be "Spanish (Mexico,Traditional)".
924 * @param name Receives the locale's display name.
925 * @return A reference to "name".
928 UnicodeString
& getDisplayName( UnicodeString
& name
) const;
931 * Fills in "name" with the name of this locale in a format suitable for user display
932 * in the locale specified by "displayLocale". This function uses getDisplayLanguage(),
933 * getDisplayCountry(), and getDisplayVariant() to do its work, and outputs the display
934 * name in the format "language (country[,variant])". For example, if displayLocale is
935 * fr_FR, then en_US's display name would be "Anglais (États-Unis)", and no_NO_NY's
936 * display name would be "norvégien (Norvège,NY)".
937 * @param displayLocale Specifies the locale to be used to display the name.
938 * @param name Receives the locale's display name.
939 * @return A reference to "name".
942 UnicodeString
& getDisplayName( const Locale
& displayLocale
,
943 UnicodeString
& name
) const;
946 * Generates a hash code for the locale.
949 int32_t hashCode(void) const;
952 * Sets the locale to bogus
953 * A bogus locale represents a non-existing locale associated
954 * with services that can be instantiated from non-locale data
955 * in addition to locale (for example, collation can be
956 * instantiated from a locale and from a rule set).
962 * Gets the bogus state. Locale object can be bogus if it doesn't exist
963 * @return FALSE if it is a real locale, TRUE if it is a bogus locale
966 inline UBool
isBogus(void) const;
969 * Returns a list of all installed locales.
970 * @param count Receives the number of locales in the list.
971 * @return A pointer to an array of Locale objects. This array is the list
972 * of all locales with installed resource files. The called does NOT
973 * get ownership of this list, and must NOT delete it.
976 static const Locale
* U_EXPORT2
getAvailableLocales(int32_t& count
);
979 * Gets a list of all available 2-letter country codes defined in ISO 3166. This is a
980 * pointer to an array of pointers to arrays of char. All of these pointers are
981 * owned by ICU-- do not delete them, and do not write through them. The array is
982 * terminated with a null pointer.
983 * @return a list of all available country codes
986 static const char* const* U_EXPORT2
getISOCountries();
989 * Gets a list of all available language codes defined in ISO 639. This is a pointer
990 * to an array of pointers to arrays of char. All of these pointers are owned
991 * by ICU-- do not delete them, and do not write through them. The array is
992 * terminated with a null pointer.
993 * @return a list of all available language codes
996 static const char* const* U_EXPORT2
getISOLanguages();
999 * ICU "poor man's RTTI", returns a UClassID for this class.
1003 static UClassID U_EXPORT2
getStaticClassID();
1006 * ICU "poor man's RTTI", returns a UClassID for the actual class.
1010 virtual UClassID
getDynamicClassID() const;
1012 protected: /* only protected for testing purposes. DO NOT USE. */
1013 #ifndef U_HIDE_INTERNAL_API
1015 * Set this from a single POSIX style locale string.
1018 void setFromPOSIXID(const char *posixID
);
1019 #endif /* U_HIDE_INTERNAL_API */
1023 * Initialize the locale object with a new name.
1024 * Was deprecated - used in implementation - moved internal
1026 * @param cLocaleID The new locale name.
1027 * @param canonicalize whether to call uloc_canonicalize on cLocaleID
1029 Locale
& init(const char* cLocaleID
, UBool canonicalize
);
1032 * Internal constructor to allow construction of a locale object with
1033 * NO side effects. (Default constructor tries to get
1034 * the default locale.)
1039 Locale(ELocaleType
);
1042 * Initialize the locale cache for commonly used locales
1044 static Locale
*getLocaleCache(void);
1046 char language
[ULOC_LANG_CAPACITY
];
1047 char script
[ULOC_SCRIPT_CAPACITY
];
1048 char country
[ULOC_COUNTRY_CAPACITY
];
1049 int32_t variantBegin
;
1051 char fullNameBuffer
[ULOC_FULLNAME_CAPACITY
];
1052 // name without keywords
1054 void initBaseName(UErrorCode
& status
);
1058 static const Locale
&getLocale(int locid
);
1061 * A friend to allow the default locale to be set by either the C or C++ API.
1062 * @internal (private)
1064 friend Locale
*locale_set_default_internal(const char *, UErrorCode
& status
);
1067 * @internal (private)
1069 friend void U_CALLCONV
locale_available_init();
1073 Locale::operator!=(const Locale
& other
) const
1075 return !operator==(other
);
1078 #ifndef U_HIDE_DRAFT_API
1079 template<typename StringClass
> inline StringClass
1080 Locale::toLanguageTag(UErrorCode
& status
) const
1083 StringByteSink
<StringClass
> sink(&result
);
1084 toLanguageTag(sink
, status
);
1087 #endif // U_HIDE_DRAFT_API
1090 Locale::getCountry() const
1096 Locale::getLanguage() const
1102 Locale::getScript() const
1108 Locale::getVariant() const
1110 return &baseName
[variantBegin
];
1114 Locale::getName() const
1119 #ifndef U_HIDE_DRAFT_API
1121 template<typename StringClass
, typename OutputIterator
> inline void
1122 Locale::getKeywords(OutputIterator iterator
, UErrorCode
& status
) const
1124 LocalPointer
<StringEnumeration
> keys(createKeywords(status
));
1125 if (U_FAILURE(status
)) {
1129 int32_t resultLength
;
1130 const char* buffer
= keys
->next(&resultLength
, status
);
1131 if (U_FAILURE(status
) || buffer
== nullptr) {
1134 *iterator
++ = StringClass(buffer
, resultLength
);
1138 template<typename StringClass
, typename OutputIterator
> inline void
1139 Locale::getUnicodeKeywords(OutputIterator iterator
, UErrorCode
& status
) const
1141 LocalPointer
<StringEnumeration
> keys(createUnicodeKeywords(status
));
1142 if (U_FAILURE(status
)) {
1146 int32_t resultLength
;
1147 const char* buffer
= keys
->next(&resultLength
, status
);
1148 if (U_FAILURE(status
) || buffer
== nullptr) {
1151 *iterator
++ = StringClass(buffer
, resultLength
);
1155 template<typename StringClass
> inline StringClass
1156 Locale::getKeywordValue(StringPiece keywordName
, UErrorCode
& status
) const
1159 StringByteSink
<StringClass
> sink(&result
);
1160 getKeywordValue(keywordName
, sink
, status
);
1164 template<typename StringClass
> inline StringClass
1165 Locale::getUnicodeKeywordValue(StringPiece keywordName
, UErrorCode
& status
) const
1168 StringByteSink
<StringClass
> sink(&result
);
1169 getUnicodeKeywordValue(keywordName
, sink
, status
);
1173 #endif // U_HIDE_DRAFT_API
1176 Locale::isBogus(void) const {
1181 #endif // U_SHOW_CPLUSPLUS_API