Path: blob/jdk8u272-b10-aarch32-20201026/jdk/src/share/native/common/unicode/locid.h
48773 views
// © 2016 and later: Unicode, Inc. and others.1// License & terms of use: http://www.unicode.org/copyright.html2/*3******************************************************************************4*5* Copyright (C) 1996-2015, International Business Machines6* Corporation and others. All Rights Reserved.7*8******************************************************************************9*10* File locid.h11*12* Created by: Helena Shih13*14* Modification History:15*16* Date Name Description17* 02/11/97 aliu Changed gLocPath to fgLocPath and added methods to18* get and set it.19* 04/02/97 aliu Made operator!= inline; fixed return value of getName().20* 04/15/97 aliu Cleanup for AIX/Win32.21* 04/24/97 aliu Numerous changes per code review.22* 08/18/98 stephen Added tokenizeString(),changed getDisplayName()23* 09/08/98 stephen Moved definition of kEmptyString for Mac Port24* 11/09/99 weiv Added const char * getName() const;25* 04/12/00 srl removing unicodestring api's and cached hash code26* 08/10/01 grhoten Change the static Locales to accessor functions27******************************************************************************28*/2930#ifndef LOCID_H31#define LOCID_H3233#include "unicode/bytestream.h"34#include "unicode/localpointer.h"35#include "unicode/strenum.h"36#include "unicode/stringpiece.h"37#include "unicode/utypes.h"38#include "unicode/uobject.h"39#include "unicode/putil.h"40#include "unicode/uloc.h"4142/**43* \file44* \brief C++ API: Locale ID object.45*/4647U_NAMESPACE_BEGIN4849// Forward Declarations50void U_CALLCONV locale_available_init(); /**< @internal */5152class StringEnumeration;53class UnicodeString;5455/**56* A <code>Locale</code> object represents a specific geographical, political,57* or cultural region. An operation that requires a <code>Locale</code> to perform58* its task is called <em>locale-sensitive</em> and uses the <code>Locale</code>59* to tailor information for the user. For example, displaying a number60* is a locale-sensitive operation--the number should be formatted61* according to the customs/conventions of the user's native country,62* region, or culture.63*64* The Locale class is not suitable for subclassing.65*66* <P>67* You can create a <code>Locale</code> object using the constructor in68* this class:69* \htmlonly<blockquote>\endhtmlonly70* <pre>71* Locale( const char* language,72* const char* country,73* const char* variant);74* </pre>75* \htmlonly</blockquote>\endhtmlonly76* The first argument to the constructors is a valid <STRONG>ISO77* Language Code.</STRONG> These codes are the lower-case two-letter78* codes as defined by ISO-639.79* You can find a full list of these codes at:80* <BR><a href ="http://www.loc.gov/standards/iso639-2/">81* http://www.loc.gov/standards/iso639-2/</a>82*83* <P>84* The second argument to the constructors is a valid <STRONG>ISO Country85* Code.</STRONG> These codes are the upper-case two-letter codes86* as defined by ISO-3166.87* You can find a full list of these codes at a number of sites, such as:88* <BR><a href="http://www.iso.org/iso/en/prods-services/iso3166ma/index.html">89* http://www.iso.org/iso/en/prods-services/iso3166ma/index.html</a>90*91* <P>92* The third constructor requires a third argument--the <STRONG>Variant.</STRONG>93* The Variant codes are vendor and browser-specific.94* For example, use REVISED for a language's revised script orthography, and POSIX for POSIX.95* Where there are two variants, separate them with an underscore, and96* put the most important one first. For97* example, a Traditional Spanish collation might be referenced, with98* "ES", "ES", "Traditional_POSIX".99*100* <P>101* Because a <code>Locale</code> object is just an identifier for a region,102* no validity check is performed when you construct a <code>Locale</code>.103* If you want to see whether particular resources are available for the104* <code>Locale</code> you construct, you must query those resources. For105* example, ask the <code>NumberFormat</code> for the locales it supports106* using its <code>getAvailableLocales</code> method.107* <BR><STRONG>Note:</STRONG> When you ask for a resource for a particular108* locale, you get back the best available match, not necessarily109* precisely what you asked for. For more information, look at110* <code>ResourceBundle</code>.111*112* <P>113* The <code>Locale</code> class provides a number of convenient constants114* that you can use to create <code>Locale</code> objects for commonly used115* locales. For example, the following refers to a <code>Locale</code> object116* for the United States:117* \htmlonly<blockquote>\endhtmlonly118* <pre>119* Locale::getUS()120* </pre>121* \htmlonly</blockquote>\endhtmlonly122*123* <P>124* Once you've created a <code>Locale</code> you can query it for information about125* itself. Use <code>getCountry</code> to get the ISO Country Code and126* <code>getLanguage</code> to get the ISO Language Code. You can127* use <code>getDisplayCountry</code> to get the128* name of the country suitable for displaying to the user. Similarly,129* you can use <code>getDisplayLanguage</code> to get the name of130* the language suitable for displaying to the user. Interestingly,131* the <code>getDisplayXXX</code> methods are themselves locale-sensitive132* and have two versions: one that uses the default locale and one133* that takes a locale as an argument and displays the name or country in134* a language appropriate to that locale.135*136* <P>137* ICU provides a number of classes that perform locale-sensitive138* operations. For example, the <code>NumberFormat</code> class formats139* numbers, currency, or percentages in a locale-sensitive manner. Classes140* such as <code>NumberFormat</code> have a number of convenience methods141* for creating a default object of that type. For example, the142* <code>NumberFormat</code> class provides these three convenience methods143* for creating a default <code>NumberFormat</code> object:144* \htmlonly<blockquote>\endhtmlonly145* <pre>146* UErrorCode success = U_ZERO_ERROR;147* Locale myLocale;148* NumberFormat *nf;149*150* nf = NumberFormat::createInstance( success ); delete nf;151* nf = NumberFormat::createCurrencyInstance( success ); delete nf;152* nf = NumberFormat::createPercentInstance( success ); delete nf;153* </pre>154* \htmlonly</blockquote>\endhtmlonly155* Each of these methods has two variants; one with an explicit locale156* and one without; the latter using the default locale.157* \htmlonly<blockquote>\endhtmlonly158* <pre>159* nf = NumberFormat::createInstance( myLocale, success ); delete nf;160* nf = NumberFormat::createCurrencyInstance( myLocale, success ); delete nf;161* nf = NumberFormat::createPercentInstance( myLocale, success ); delete nf;162* </pre>163* \htmlonly</blockquote>\endhtmlonly164* A <code>Locale</code> is the mechanism for identifying the kind of object165* (<code>NumberFormat</code>) that you would like to get. The locale is166* <STRONG>just</STRONG> a mechanism for identifying objects,167* <STRONG>not</STRONG> a container for the objects themselves.168*169* <P>170* Each class that performs locale-sensitive operations allows you171* to get all the available objects of that type. You can sift172* through these objects by language, country, or variant,173* and use the display names to present a menu to the user.174* For example, you can create a menu of all the collation objects175* suitable for a given language. Such classes implement these176* three class methods:177* \htmlonly<blockquote>\endhtmlonly178* <pre>179* static Locale* getAvailableLocales(int32_t& numLocales)180* static UnicodeString& getDisplayName(const Locale& objectLocale,181* const Locale& displayLocale,182* UnicodeString& displayName)183* static UnicodeString& getDisplayName(const Locale& objectLocale,184* UnicodeString& displayName)185* </pre>186* \htmlonly</blockquote>\endhtmlonly187*188* @stable ICU 2.0189* @see ResourceBundle190*/191class U_COMMON_API Locale : public UObject {192public:193/** Useful constant for the Root locale. @stable ICU 4.4 */194static const Locale &U_EXPORT2 getRoot(void);195/** Useful constant for this language. @stable ICU 2.0 */196static const Locale &U_EXPORT2 getEnglish(void);197/** Useful constant for this language. @stable ICU 2.0 */198static const Locale &U_EXPORT2 getFrench(void);199/** Useful constant for this language. @stable ICU 2.0 */200static const Locale &U_EXPORT2 getGerman(void);201/** Useful constant for this language. @stable ICU 2.0 */202static const Locale &U_EXPORT2 getItalian(void);203/** Useful constant for this language. @stable ICU 2.0 */204static const Locale &U_EXPORT2 getJapanese(void);205/** Useful constant for this language. @stable ICU 2.0 */206static const Locale &U_EXPORT2 getKorean(void);207/** Useful constant for this language. @stable ICU 2.0 */208static const Locale &U_EXPORT2 getChinese(void);209/** Useful constant for this language. @stable ICU 2.0 */210static const Locale &U_EXPORT2 getSimplifiedChinese(void);211/** Useful constant for this language. @stable ICU 2.0 */212static const Locale &U_EXPORT2 getTraditionalChinese(void);213214/** Useful constant for this country/region. @stable ICU 2.0 */215static const Locale &U_EXPORT2 getFrance(void);216/** Useful constant for this country/region. @stable ICU 2.0 */217static const Locale &U_EXPORT2 getGermany(void);218/** Useful constant for this country/region. @stable ICU 2.0 */219static const Locale &U_EXPORT2 getItaly(void);220/** Useful constant for this country/region. @stable ICU 2.0 */221static const Locale &U_EXPORT2 getJapan(void);222/** Useful constant for this country/region. @stable ICU 2.0 */223static const Locale &U_EXPORT2 getKorea(void);224/** Useful constant for this country/region. @stable ICU 2.0 */225static const Locale &U_EXPORT2 getChina(void);226/** Useful constant for this country/region. @stable ICU 2.0 */227static const Locale &U_EXPORT2 getPRC(void);228/** Useful constant for this country/region. @stable ICU 2.0 */229static const Locale &U_EXPORT2 getTaiwan(void);230/** Useful constant for this country/region. @stable ICU 2.0 */231static const Locale &U_EXPORT2 getUK(void);232/** Useful constant for this country/region. @stable ICU 2.0 */233static const Locale &U_EXPORT2 getUS(void);234/** Useful constant for this country/region. @stable ICU 2.0 */235static const Locale &U_EXPORT2 getCanada(void);236/** Useful constant for this country/region. @stable ICU 2.0 */237static const Locale &U_EXPORT2 getCanadaFrench(void);238239240/**241* Construct a default locale object, a Locale for the default locale ID.242*243* @see getDefault244* @see uloc_getDefault245* @stable ICU 2.0246*/247Locale();248249/**250* Construct a locale from language, country, variant.251* If an error occurs, then the constructed object will be "bogus"252* (isBogus() will return TRUE).253*254* @param language Lowercase two-letter or three-letter ISO-639 code.255* This parameter can instead be an ICU style C locale (e.g. "en_US"),256* but the other parameters must not be used.257* This parameter can be NULL; if so,258* the locale is initialized to match the current default locale.259* (This is the same as using the default constructor.)260* Please note: The Java Locale class does NOT accept the form261* 'new Locale("en_US")' but only 'new Locale("en","US")'262*263* @param country Uppercase two-letter ISO-3166 code. (optional)264* @param variant Uppercase vendor and browser specific code. See class265* description. (optional)266* @param keywordsAndValues A string consisting of keyword/values pairs, such as267* "collation=phonebook;currency=euro"268*269* @see getDefault270* @see uloc_getDefault271* @stable ICU 2.0272*/273Locale( const char * language,274const char * country = 0,275const char * variant = 0,276const char * keywordsAndValues = 0);277278/**279* Initializes a Locale object from another Locale object.280*281* @param other The Locale object being copied in.282* @stable ICU 2.0283*/284Locale(const Locale& other);285286#ifndef U_HIDE_DRAFT_API287/**288* Move constructor; might leave source in bogus state.289* This locale will have the same contents that the source locale had.290*291* @param other The Locale object being moved in.292* @draft ICU 63293*/294Locale(Locale&& other) U_NOEXCEPT;295#endif // U_HIDE_DRAFT_API296297/**298* Destructor299* @stable ICU 2.0300*/301virtual ~Locale() ;302303/**304* Replaces the entire contents of *this with the specified value.305*306* @param other The Locale object being copied in.307* @return *this308* @stable ICU 2.0309*/310Locale& operator=(const Locale& other);311312#ifndef U_HIDE_DRAFT_API313/**314* Move assignment operator; might leave source in bogus state.315* This locale will have the same contents that the source locale had.316* The behavior is undefined if *this and the source are the same object.317*318* @param other The Locale object being moved in.319* @return *this320* @draft ICU 63321*/322Locale& operator=(Locale&& other) U_NOEXCEPT;323#endif // U_HIDE_DRAFT_API324325/**326* Checks if two locale keys are the same.327*328* @param other The locale key object to be compared with this.329* @return True if the two locale keys are the same, false otherwise.330* @stable ICU 2.0331*/332UBool operator==(const Locale& other) const;333334/**335* Checks if two locale keys are not the same.336*337* @param other The locale key object to be compared with this.338* @return True if the two locale keys are not the same, false339* otherwise.340* @stable ICU 2.0341*/342inline UBool operator!=(const Locale& other) const;343344/**345* Clone this object.346* Clones can be used concurrently in multiple threads.347* If an error occurs, then NULL is returned.348* The caller must delete the clone.349*350* @return a clone of this object351*352* @see getDynamicClassID353* @stable ICU 2.8354*/355Locale *clone() const;356357#ifndef U_HIDE_SYSTEM_API358/**359* Common methods of getting the current default Locale. Used for the360* presentation: menus, dialogs, etc. Generally set once when your applet or361* application is initialized, then never reset. (If you do reset the362* default locale, you probably want to reload your GUI, so that the change363* is reflected in your interface.)364*365* More advanced programs will allow users to use different locales for366* different fields, e.g. in a spreadsheet.367*368* Note that the initial setting will match the host system.369* @return a reference to the Locale object for the default locale ID370* @system371* @stable ICU 2.0372*/373static const Locale& U_EXPORT2 getDefault(void);374375/**376* Sets the default. Normally set once at the beginning of a process,377* then never reset.378* setDefault() only changes ICU's default locale ID, <strong>not</strong>379* the default locale ID of the runtime environment.380*381* @param newLocale Locale to set to. If NULL, set to the value obtained382* from the runtime environment.383* @param success The error code.384* @system385* @stable ICU 2.0386*/387static void U_EXPORT2 setDefault(const Locale& newLocale,388UErrorCode& success);389#endif /* U_HIDE_SYSTEM_API */390391#ifndef U_HIDE_DRAFT_API392/**393* Returns a Locale for the specified BCP47 language tag string.394* If the specified language tag contains any ill-formed subtags,395* the first such subtag and all following subtags are ignored.396* <p>397* This implements the 'Language-Tag' production of BCP47, and so398* supports grandfathered (regular and irregular) as well as private399* use language tags. Private use tags are represented as 'x-whatever',400* and grandfathered tags are converted to their canonical replacements401* where they exist. Note that a few grandfathered tags have no modern402* replacement, these will be converted using the fallback described in403* the first paragraph, so some information might be lost.404* @param tag the input BCP47 language tag.405* @param status error information if creating the Locale failed.406* @return the Locale for the specified BCP47 language tag.407* @draft ICU 63408*/409static Locale U_EXPORT2 forLanguageTag(StringPiece tag, UErrorCode& status);410411/**412* Returns a well-formed language tag for this Locale.413* <p>414* <b>Note</b>: Any locale fields which do not satisfy the BCP47 syntax415* requirement will be silently omitted from the result.416*417* If this function fails, partial output may have been written to the sink.418*419* @param sink the output sink receiving the BCP47 language420* tag for this Locale.421* @param status error information if creating the language tag failed.422* @draft ICU 63423*/424void toLanguageTag(ByteSink& sink, UErrorCode& status) const;425426/**427* Returns a well-formed language tag for this Locale.428* <p>429* <b>Note</b>: Any locale fields which do not satisfy the BCP47 syntax430* requirement will be silently omitted from the result.431*432* @param status error information if creating the language tag failed.433* @return the BCP47 language tag for this Locale.434* @draft ICU 63435*/436template<typename StringClass>437inline StringClass toLanguageTag(UErrorCode& status) const;438#endif // U_HIDE_DRAFT_API439440/**441* Creates a locale which has had minimal canonicalization442* as per uloc_getName().443* @param name The name to create from. If name is null,444* the default Locale is used.445* @return new locale object446* @stable ICU 2.0447* @see uloc_getName448*/449static Locale U_EXPORT2 createFromName(const char *name);450451/**452* Creates a locale from the given string after canonicalizing453* the string by calling uloc_canonicalize().454* @param name the locale ID to create from. Must not be NULL.455* @return a new locale object corresponding to the given name456* @stable ICU 3.0457* @see uloc_canonicalize458*/459static Locale U_EXPORT2 createCanonical(const char* name);460461/**462* Returns the locale's ISO-639 language code.463* @return An alias to the code464* @stable ICU 2.0465*/466inline const char * getLanguage( ) const;467468/**469* Returns the locale's ISO-15924 abbreviation script code.470* @return An alias to the code471* @see uscript_getShortName472* @see uscript_getCode473* @stable ICU 2.8474*/475inline const char * getScript( ) const;476477/**478* Returns the locale's ISO-3166 country code.479* @return An alias to the code480* @stable ICU 2.0481*/482inline const char * getCountry( ) const;483484/**485* Returns the locale's variant code.486* @return An alias to the code487* @stable ICU 2.0488*/489inline const char * getVariant( ) const;490491/**492* Returns the programmatic name of the entire locale, with the language,493* country and variant separated by underbars. If a field is missing, up494* to two leading underbars will occur. Example: "en", "de_DE", "en_US_WIN",495* "de__POSIX", "fr__MAC", "__MAC", "_MT", "_FR_EURO"496* @return A pointer to "name".497* @stable ICU 2.0498*/499inline const char * getName() const;500501/**502* Returns the programmatic name of the entire locale as getName() would return,503* but without keywords.504* @return A pointer to "name".505* @see getName506* @stable ICU 2.8507*/508const char * getBaseName() const;509510#ifndef U_HIDE_DRAFT_API511/**512* Add the likely subtags for this Locale, per the algorithm described513* in the following CLDR technical report:514*515* http://www.unicode.org/reports/tr35/#Likely_Subtags516*517* If this Locale is already in the maximal form, or not valid, or there is518* no data available for maximization, the Locale will be unchanged.519*520* For example, "und-Zzzz" cannot be maximized, since there is no521* reasonable maximization.522*523* Examples:524*525* "en" maximizes to "en_Latn_US"526*527* "de" maximizes to "de_Latn_US"528*529* "sr" maximizes to "sr_Cyrl_RS"530*531* "sh" maximizes to "sr_Latn_RS" (Note this will not reverse.)532*533* "zh_Hani" maximizes to "zh_Hans_CN" (Note this will not reverse.)534*535* @param status error information if maximizing this Locale failed.536* If this Locale is not well-formed, the error code is537* U_ILLEGAL_ARGUMENT_ERROR.538* @draft ICU 63539*/540void addLikelySubtags(UErrorCode& status);541542/**543* Minimize the subtags for this Locale, per the algorithm described544* in the following CLDR technical report:545*546* http://www.unicode.org/reports/tr35/#Likely_Subtags547*548* If this Locale is already in the minimal form, or not valid, or there is549* no data available for minimization, the Locale will be unchanged.550*551* Since the minimization algorithm relies on proper maximization, see the552* comments for addLikelySubtags for reasons why there might not be any553* data.554*555* Examples:556*557* "en_Latn_US" minimizes to "en"558*559* "de_Latn_US" minimizes to "de"560*561* "sr_Cyrl_RS" minimizes to "sr"562*563* "zh_Hant_TW" minimizes to "zh_TW" (The region is preferred to the564* script, and minimizing to "zh" would imply "zh_Hans_CN".)565*566* @param status error information if maximizing this Locale failed.567* If this Locale is not well-formed, the error code is568* U_ILLEGAL_ARGUMENT_ERROR.569* @draft ICU 63570*/571void minimizeSubtags(UErrorCode& status);572#endif // U_HIDE_DRAFT_API573574/**575* Gets the list of keywords for the specified locale.576*577* @param status the status code578* @return pointer to StringEnumeration class, or NULL if there are no keywords.579* Client must dispose of it by calling delete.580* @see getKeywords581* @stable ICU 2.8582*/583StringEnumeration * createKeywords(UErrorCode &status) const;584585#ifndef U_HIDE_DRAFT_API586587/**588* Gets the list of Unicode keywords for the specified locale.589*590* @param status the status code591* @return pointer to StringEnumeration class, or NULL if there are no keywords.592* Client must dispose of it by calling delete.593* @see getUnicodeKeywords594* @draft ICU 63595*/596StringEnumeration * createUnicodeKeywords(UErrorCode &status) const;597598/**599* Gets the set of keywords for this Locale.600*601* A wrapper to call createKeywords() and write the resulting602* keywords as standard strings (or compatible objects) into any kind of603* container that can be written to by an STL style output iterator.604*605* @param iterator an STL style output iterator to write the keywords to.606* @param status error information if creating set of keywords failed.607* @draft ICU 63608*/609template<typename StringClass, typename OutputIterator>610inline void getKeywords(OutputIterator iterator, UErrorCode& status) const;611612/**613* Gets the set of Unicode keywords for this Locale.614*615* A wrapper to call createUnicodeKeywords() and write the resulting616* keywords as standard strings (or compatible objects) into any kind of617* container that can be written to by an STL style output iterator.618*619* @param iterator an STL style output iterator to write the keywords to.620* @param status error information if creating set of keywords failed.621* @draft ICU 63622*/623template<typename StringClass, typename OutputIterator>624inline void getUnicodeKeywords(OutputIterator iterator, UErrorCode& status) const;625626#endif // U_HIDE_DRAFT_API627628/**629* Gets the value for a keyword.630*631* This uses legacy keyword=value pairs, like "collation=phonebook".632*633* ICU4C doesn't do automatic conversion between legacy and Unicode634* keywords and values in getters and setters (as opposed to ICU4J).635*636* @param keywordName name of the keyword for which we want the value. Case insensitive.637* @param buffer The buffer to receive the keyword value.638* @param bufferCapacity The capacity of receiving buffer639* @param status Returns any error information while performing this operation.640* @return the length of the keyword value641*642* @stable ICU 2.8643*/644int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;645646#ifndef U_HIDE_DRAFT_API647/**648* Gets the value for a keyword.649*650* This uses legacy keyword=value pairs, like "collation=phonebook".651*652* ICU4C doesn't do automatic conversion between legacy and Unicode653* keywords and values in getters and setters (as opposed to ICU4J).654*655* @param keywordName name of the keyword for which we want the value.656* @param sink the sink to receive the keyword value.657* @param status error information if getting the value failed.658* @draft ICU 63659*/660void getKeywordValue(StringPiece keywordName, ByteSink& sink, UErrorCode& status) const;661662/**663* Gets the value for a keyword.664*665* This uses legacy keyword=value pairs, like "collation=phonebook".666*667* ICU4C doesn't do automatic conversion between legacy and Unicode668* keywords and values in getters and setters (as opposed to ICU4J).669*670* @param keywordName name of the keyword for which we want the value.671* @param status error information if getting the value failed.672* @return the keyword value.673* @draft ICU 63674*/675template<typename StringClass>676inline StringClass getKeywordValue(StringPiece keywordName, UErrorCode& status) const;677678/**679* Gets the Unicode value for a Unicode keyword.680*681* This uses Unicode key-value pairs, like "co-phonebk".682*683* ICU4C doesn't do automatic conversion between legacy and Unicode684* keywords and values in getters and setters (as opposed to ICU4J).685*686* @param keywordName name of the keyword for which we want the value.687* @param sink the sink to receive the keyword value.688* @param status error information if getting the value failed.689* @draft ICU 63690*/691void getUnicodeKeywordValue(StringPiece keywordName, ByteSink& sink, UErrorCode& status) const;692693/**694* Gets the Unicode value for a Unicode keyword.695*696* This uses Unicode key-value pairs, like "co-phonebk".697*698* ICU4C doesn't do automatic conversion between legacy and Unicode699* keywords and values in getters and setters (as opposed to ICU4J).700*701* @param keywordName name of the keyword for which we want the value.702* @param status error information if getting the value failed.703* @return the keyword value.704* @draft ICU 63705*/706template<typename StringClass>707inline StringClass getUnicodeKeywordValue(StringPiece keywordName, UErrorCode& status) const;708#endif // U_HIDE_DRAFT_API709710/**711* Sets or removes the value for a keyword.712*713* For removing all keywords, use getBaseName(),714* and construct a new Locale if it differs from getName().715*716* This uses legacy keyword=value pairs, like "collation=phonebook".717*718* ICU4C doesn't do automatic conversion between legacy and Unicode719* keywords and values in getters and setters (as opposed to ICU4J).720*721* @param keywordName name of the keyword to be set. Case insensitive.722* @param keywordValue value of the keyword to be set. If 0-length or723* NULL, will result in the keyword being removed. No error is given if724* that keyword does not exist.725* @param status Returns any error information while performing this operation.726*727* @stable ICU 49728*/729void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);730731#ifndef U_HIDE_DRAFT_API732/**733* Sets or removes the value for a keyword.734*735* For removing all keywords, use getBaseName(),736* and construct a new Locale if it differs from getName().737*738* This uses legacy keyword=value pairs, like "collation=phonebook".739*740* ICU4C doesn't do automatic conversion between legacy and Unicode741* keywords and values in getters and setters (as opposed to ICU4J).742*743* @param keywordName name of the keyword to be set.744* @param keywordValue value of the keyword to be set. If 0-length or745* NULL, will result in the keyword being removed. No error is given if746* that keyword does not exist.747* @param status Returns any error information while performing this operation.748* @draft ICU 63749*/750void setKeywordValue(StringPiece keywordName, StringPiece keywordValue, UErrorCode& status);751752/**753* Sets or removes the Unicode value for a Unicode keyword.754*755* For removing all keywords, use getBaseName(),756* and construct a new Locale if it differs from getName().757*758* This uses Unicode key-value pairs, like "co-phonebk".759*760* ICU4C doesn't do automatic conversion between legacy and Unicode761* keywords and values in getters and setters (as opposed to ICU4J).762*763* @param keywordName name of the keyword to be set.764* @param keywordValue value of the keyword to be set. If 0-length or765* NULL, will result in the keyword being removed. No error is given if766* that keyword does not exist.767* @param status Returns any error information while performing this operation.768* @draft ICU 63769*/770void setUnicodeKeywordValue(StringPiece keywordName, StringPiece keywordValue, UErrorCode& status);771#endif // U_HIDE_DRAFT_API772773/**774* returns the locale's three-letter language code, as specified775* in ISO draft standard ISO-639-2.776* @return An alias to the code, or an empty string777* @stable ICU 2.0778*/779const char * getISO3Language() const;780781/**782* Fills in "name" with the locale's three-letter ISO-3166 country code.783* @return An alias to the code, or an empty string784* @stable ICU 2.0785*/786const char * getISO3Country() const;787788/**789* Returns the Windows LCID value corresponding to this locale.790* This value is stored in the resource data for the locale as a one-to-four-digit791* hexadecimal number. If the resource is missing, in the wrong format, or792* there is no Windows LCID value that corresponds to this locale, returns 0.793* @stable ICU 2.0794*/795uint32_t getLCID(void) const;796797/**798* Returns whether this locale's script is written right-to-left.799* If there is no script subtag, then the likely script is used, see uloc_addLikelySubtags().800* If no likely script is known, then FALSE is returned.801*802* A script is right-to-left according to the CLDR script metadata803* which corresponds to whether the script's letters have Bidi_Class=R or AL.804*805* Returns TRUE for "ar" and "en-Hebr", FALSE for "zh" and "fa-Cyrl".806*807* @return TRUE if the locale's script is written right-to-left808* @stable ICU 54809*/810UBool isRightToLeft() const;811812/**813* Fills in "dispLang" with the name of this locale's language in a format suitable for814* user display in the default locale. For example, if the locale's language code is815* "fr" and the default locale's language code is "en", this function would set816* dispLang to "French".817* @param dispLang Receives the language's display name.818* @return A reference to "dispLang".819* @stable ICU 2.0820*/821UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const;822823/**824* Fills in "dispLang" with the name of this locale's language in a format suitable for825* user display in the locale specified by "displayLocale". For example, if the locale's826* language code is "en" and displayLocale's language code is "fr", this function would set827* dispLang to "Anglais".828* @param displayLocale Specifies the locale to be used to display the name. In other words,829* if the locale's language code is "en", passing Locale::getFrench() for830* displayLocale would result in "Anglais", while passing Locale::getGerman()831* for displayLocale would result in "Englisch".832* @param dispLang Receives the language's display name.833* @return A reference to "dispLang".834* @stable ICU 2.0835*/836UnicodeString& getDisplayLanguage( const Locale& displayLocale,837UnicodeString& dispLang) const;838839/**840* Fills in "dispScript" with the name of this locale's script in a format suitable841* for user display in the default locale. For example, if the locale's script code842* is "LATN" and the default locale's language code is "en", this function would set843* dispScript to "Latin".844* @param dispScript Receives the scripts's display name.845* @return A reference to "dispScript".846* @stable ICU 2.8847*/848UnicodeString& getDisplayScript( UnicodeString& dispScript) const;849850/**851* Fills in "dispScript" with the name of this locale's country in a format suitable852* for user display in the locale specified by "displayLocale". For example, if the locale's853* script code is "LATN" and displayLocale's language code is "en", this function would set854* dispScript to "Latin".855* @param displayLocale Specifies the locale to be used to display the name. In other856* words, if the locale's script code is "LATN", passing857* Locale::getFrench() for displayLocale would result in "", while858* passing Locale::getGerman() for displayLocale would result in859* "".860* @param dispScript Receives the scripts's display name.861* @return A reference to "dispScript".862* @stable ICU 2.8863*/864UnicodeString& getDisplayScript( const Locale& displayLocale,865UnicodeString& dispScript) const;866867/**868* Fills in "dispCountry" with the name of this locale's country in a format suitable869* for user display in the default locale. For example, if the locale's country code870* is "FR" and the default locale's language code is "en", this function would set871* dispCountry to "France".872* @param dispCountry Receives the country's display name.873* @return A reference to "dispCountry".874* @stable ICU 2.0875*/876UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const;877878/**879* Fills in "dispCountry" with the name of this locale's country in a format suitable880* for user display in the locale specified by "displayLocale". For example, if the locale's881* country code is "US" and displayLocale's language code is "fr", this function would set882* dispCountry to "États-Unis".883* @param displayLocale Specifies the locale to be used to display the name. In other884* words, if the locale's country code is "US", passing885* Locale::getFrench() for displayLocale would result in "États-Unis", while886* passing Locale::getGerman() for displayLocale would result in887* "Vereinigte Staaten".888* @param dispCountry Receives the country's display name.889* @return A reference to "dispCountry".890* @stable ICU 2.0891*/892UnicodeString& getDisplayCountry( const Locale& displayLocale,893UnicodeString& dispCountry) const;894895/**896* Fills in "dispVar" with the name of this locale's variant code in a format suitable897* for user display in the default locale.898* @param dispVar Receives the variant's name.899* @return A reference to "dispVar".900* @stable ICU 2.0901*/902UnicodeString& getDisplayVariant( UnicodeString& dispVar) const;903904/**905* Fills in "dispVar" with the name of this locale's variant code in a format906* suitable for user display in the locale specified by "displayLocale".907* @param displayLocale Specifies the locale to be used to display the name.908* @param dispVar Receives the variant's display name.909* @return A reference to "dispVar".910* @stable ICU 2.0911*/912UnicodeString& getDisplayVariant( const Locale& displayLocale,913UnicodeString& dispVar) const;914915/**916* Fills in "name" with the name of this locale in a format suitable for user display917* in the default locale. This function uses getDisplayLanguage(), getDisplayCountry(),918* and getDisplayVariant() to do its work, and outputs the display name in the format919* "language (country[,variant])". For example, if the default locale is en_US, then920* fr_FR's display name would be "French (France)", and es_MX_Traditional's display name921* would be "Spanish (Mexico,Traditional)".922* @param name Receives the locale's display name.923* @return A reference to "name".924* @stable ICU 2.0925*/926UnicodeString& getDisplayName( UnicodeString& name) const;927928/**929* Fills in "name" with the name of this locale in a format suitable for user display930* in the locale specified by "displayLocale". This function uses getDisplayLanguage(),931* getDisplayCountry(), and getDisplayVariant() to do its work, and outputs the display932* name in the format "language (country[,variant])". For example, if displayLocale is933* fr_FR, then en_US's display name would be "Anglais (États-Unis)", and no_NO_NY's934* display name would be "norvégien (Norvège,NY)".935* @param displayLocale Specifies the locale to be used to display the name.936* @param name Receives the locale's display name.937* @return A reference to "name".938* @stable ICU 2.0939*/940UnicodeString& getDisplayName( const Locale& displayLocale,941UnicodeString& name) const;942943/**944* Generates a hash code for the locale.945* @stable ICU 2.0946*/947int32_t hashCode(void) const;948949/**950* Sets the locale to bogus951* A bogus locale represents a non-existing locale associated952* with services that can be instantiated from non-locale data953* in addition to locale (for example, collation can be954* instantiated from a locale and from a rule set).955* @stable ICU 2.1956*/957void setToBogus();958959/**960* Gets the bogus state. Locale object can be bogus if it doesn't exist961* @return FALSE if it is a real locale, TRUE if it is a bogus locale962* @stable ICU 2.1963*/964inline UBool isBogus(void) const;965966/**967* Returns a list of all installed locales.968* @param count Receives the number of locales in the list.969* @return A pointer to an array of Locale objects. This array is the list970* of all locales with installed resource files. The called does NOT971* get ownership of this list, and must NOT delete it.972* @stable ICU 2.0973*/974static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);975976/**977* Gets a list of all available 2-letter country codes defined in ISO 3166. This is a978* pointer to an array of pointers to arrays of char. All of these pointers are979* owned by ICU-- do not delete them, and do not write through them. The array is980* terminated with a null pointer.981* @return a list of all available country codes982* @stable ICU 2.0983*/984static const char* const* U_EXPORT2 getISOCountries();985986/**987* Gets a list of all available language codes defined in ISO 639. This is a pointer988* to an array of pointers to arrays of char. All of these pointers are owned989* by ICU-- do not delete them, and do not write through them. The array is990* terminated with a null pointer.991* @return a list of all available language codes992* @stable ICU 2.0993*/994static const char* const* U_EXPORT2 getISOLanguages();995996/**997* ICU "poor man's RTTI", returns a UClassID for this class.998*999* @stable ICU 2.21000*/1001static UClassID U_EXPORT2 getStaticClassID();10021003/**1004* ICU "poor man's RTTI", returns a UClassID for the actual class.1005*1006* @stable ICU 2.21007*/1008virtual UClassID getDynamicClassID() const;10091010protected: /* only protected for testing purposes. DO NOT USE. */1011#ifndef U_HIDE_INTERNAL_API1012/**1013* Set this from a single POSIX style locale string.1014* @internal1015*/1016void setFromPOSIXID(const char *posixID);1017#endif /* U_HIDE_INTERNAL_API */10181019private:1020/**1021* Initialize the locale object with a new name.1022* Was deprecated - used in implementation - moved internal1023*1024* @param cLocaleID The new locale name.1025* @param canonicalize whether to call uloc_canonicalize on cLocaleID1026*/1027Locale& init(const char* cLocaleID, UBool canonicalize);10281029/*1030* Internal constructor to allow construction of a locale object with1031* NO side effects. (Default constructor tries to get1032* the default locale.)1033*/1034enum ELocaleType {1035eBOGUS1036};1037Locale(ELocaleType);10381039/**1040* Initialize the locale cache for commonly used locales1041*/1042static Locale *getLocaleCache(void);10431044char language[ULOC_LANG_CAPACITY];1045char script[ULOC_SCRIPT_CAPACITY];1046char country[ULOC_COUNTRY_CAPACITY];1047int32_t variantBegin;1048char* fullName;1049char fullNameBuffer[ULOC_FULLNAME_CAPACITY];1050// name without keywords1051char* baseName;1052void initBaseName(UErrorCode& status);10531054UBool fIsBogus;10551056static const Locale &getLocale(int locid);10571058/**1059* A friend to allow the default locale to be set by either the C or C++ API.1060* @internal (private)1061*/1062friend Locale *locale_set_default_internal(const char *, UErrorCode& status);10631064/**1065* @internal (private)1066*/1067friend void U_CALLCONV locale_available_init();1068};10691070inline UBool1071Locale::operator!=(const Locale& other) const1072{1073return !operator==(other);1074}10751076#ifndef U_HIDE_DRAFT_API1077template<typename StringClass> inline StringClass1078Locale::toLanguageTag(UErrorCode& status) const1079{1080StringClass result;1081StringByteSink<StringClass> sink(&result);1082toLanguageTag(sink, status);1083return result;1084}1085#endif // U_HIDE_DRAFT_API10861087inline const char *1088Locale::getCountry() const1089{1090return country;1091}10921093inline const char *1094Locale::getLanguage() const1095{1096return language;1097}10981099inline const char *1100Locale::getScript() const1101{1102return script;1103}11041105inline const char *1106Locale::getVariant() const1107{1108return &baseName[variantBegin];1109}11101111inline const char *1112Locale::getName() const1113{1114return fullName;1115}11161117#ifndef U_HIDE_DRAFT_API11181119template<typename StringClass, typename OutputIterator> inline void1120Locale::getKeywords(OutputIterator iterator, UErrorCode& status) const1121{1122LocalPointer<StringEnumeration> keys(createKeywords(status));1123if (U_FAILURE(status) || keys.isNull()) {1124return;1125}1126for (;;) {1127int32_t resultLength;1128const char* buffer = keys->next(&resultLength, status);1129if (U_FAILURE(status) || buffer == nullptr) {1130return;1131}1132*iterator++ = StringClass(buffer, resultLength);1133}1134}11351136template<typename StringClass, typename OutputIterator> inline void1137Locale::getUnicodeKeywords(OutputIterator iterator, UErrorCode& status) const1138{1139LocalPointer<StringEnumeration> keys(createUnicodeKeywords(status));1140if (U_FAILURE(status) || keys.isNull()) {1141return;1142}1143for (;;) {1144int32_t resultLength;1145const char* buffer = keys->next(&resultLength, status);1146if (U_FAILURE(status) || buffer == nullptr) {1147return;1148}1149*iterator++ = StringClass(buffer, resultLength);1150}1151}11521153template<typename StringClass> inline StringClass1154Locale::getKeywordValue(StringPiece keywordName, UErrorCode& status) const1155{1156StringClass result;1157StringByteSink<StringClass> sink(&result);1158getKeywordValue(keywordName, sink, status);1159return result;1160}11611162template<typename StringClass> inline StringClass1163Locale::getUnicodeKeywordValue(StringPiece keywordName, UErrorCode& status) const1164{1165StringClass result;1166StringByteSink<StringClass> sink(&result);1167getUnicodeKeywordValue(keywordName, sink, status);1168return result;1169}11701171#endif // U_HIDE_DRAFT_API11721173inline UBool1174Locale::isBogus(void) const {1175return fIsBogus;1176}11771178U_NAMESPACE_END11791180#endif118111821183