jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ****************************************************************************** jpayne@69: * jpayne@69: * Copyright (C) 1996-2015, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: * jpayne@69: ****************************************************************************** jpayne@69: * jpayne@69: * File locid.h jpayne@69: * jpayne@69: * Created by: Helena Shih jpayne@69: * jpayne@69: * Modification History: jpayne@69: * jpayne@69: * Date Name Description jpayne@69: * 02/11/97 aliu Changed gLocPath to fgLocPath and added methods to jpayne@69: * get and set it. jpayne@69: * 04/02/97 aliu Made operator!= inline; fixed return value of getName(). jpayne@69: * 04/15/97 aliu Cleanup for AIX/Win32. jpayne@69: * 04/24/97 aliu Numerous changes per code review. jpayne@69: * 08/18/98 stephen Added tokenizeString(),changed getDisplayName() jpayne@69: * 09/08/98 stephen Moved definition of kEmptyString for Mac Port jpayne@69: * 11/09/99 weiv Added const char * getName() const; jpayne@69: * 04/12/00 srl removing unicodestring api's and cached hash code jpayne@69: * 08/10/01 grhoten Change the static Locales to accessor functions jpayne@69: ****************************************************************************** jpayne@69: */ jpayne@69: jpayne@69: #ifndef LOCID_H jpayne@69: #define LOCID_H jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: #include "unicode/bytestream.h" jpayne@69: #include "unicode/localpointer.h" jpayne@69: #include "unicode/strenum.h" jpayne@69: #include "unicode/stringpiece.h" jpayne@69: #include "unicode/uobject.h" jpayne@69: #include "unicode/putil.h" jpayne@69: #include "unicode/uloc.h" jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C++ API: Locale ID object. jpayne@69: */ jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: // Forward Declarations jpayne@69: void U_CALLCONV locale_available_init(); /**< @internal */ jpayne@69: jpayne@69: class StringEnumeration; jpayne@69: class UnicodeString; jpayne@69: jpayne@69: /** jpayne@69: * A Locale object represents a specific geographical, political, jpayne@69: * or cultural region. An operation that requires a Locale to perform jpayne@69: * its task is called locale-sensitive and uses the Locale jpayne@69: * to tailor information for the user. For example, displaying a number jpayne@69: * is a locale-sensitive operation--the number should be formatted jpayne@69: * according to the customs/conventions of the user's native country, jpayne@69: * region, or culture. jpayne@69: * jpayne@69: * The Locale class is not suitable for subclassing. jpayne@69: * jpayne@69: *

jpayne@69: * You can create a Locale object using the constructor in jpayne@69: * this class: jpayne@69: * \htmlonly

\endhtmlonly jpayne@69: *
jpayne@69:  *       Locale( const   char*  language,
jpayne@69:  *               const   char*  country,
jpayne@69:  *               const   char*  variant);
jpayne@69:  * 
jpayne@69: * \htmlonly
\endhtmlonly jpayne@69: * The first argument to the constructors is a valid ISO jpayne@69: * Language Code. These codes are the lower-case two-letter jpayne@69: * codes as defined by ISO-639. jpayne@69: * You can find a full list of these codes at: jpayne@69: *
jpayne@69: * http://www.loc.gov/standards/iso639-2/ jpayne@69: * jpayne@69: *

jpayne@69: * The second argument to the constructors is a valid ISO Country jpayne@69: * Code. These codes are the upper-case two-letter codes jpayne@69: * as defined by ISO-3166. jpayne@69: * You can find a full list of these codes at a number of sites, such as: jpayne@69: *
jpayne@69: * http://www.iso.org/iso/en/prods-services/iso3166ma/index.html jpayne@69: * jpayne@69: *

jpayne@69: * The third constructor requires a third argument--the Variant. jpayne@69: * The Variant codes are vendor and browser-specific. jpayne@69: * For example, use REVISED for a language's revised script orthography, and POSIX for POSIX. jpayne@69: * Where there are two variants, separate them with an underscore, and jpayne@69: * put the most important one first. For jpayne@69: * example, a Traditional Spanish collation might be referenced, with jpayne@69: * "ES", "ES", "Traditional_POSIX". jpayne@69: * jpayne@69: *

jpayne@69: * Because a Locale object is just an identifier for a region, jpayne@69: * no validity check is performed when you construct a Locale. jpayne@69: * If you want to see whether particular resources are available for the jpayne@69: * Locale you construct, you must query those resources. For jpayne@69: * example, ask the NumberFormat for the locales it supports jpayne@69: * using its getAvailableLocales method. jpayne@69: *
Note: When you ask for a resource for a particular jpayne@69: * locale, you get back the best available match, not necessarily jpayne@69: * precisely what you asked for. For more information, look at jpayne@69: * ResourceBundle. jpayne@69: * jpayne@69: *

jpayne@69: * The Locale class provides a number of convenient constants jpayne@69: * that you can use to create Locale objects for commonly used jpayne@69: * locales. For example, the following refers to a Locale object jpayne@69: * for the United States: jpayne@69: * \htmlonly

\endhtmlonly jpayne@69: *
jpayne@69:  *       Locale::getUS()
jpayne@69:  * 
jpayne@69: * \htmlonly
\endhtmlonly jpayne@69: * jpayne@69: *

jpayne@69: * Once you've created a Locale you can query it for information about jpayne@69: * itself. Use getCountry to get the ISO Country Code and jpayne@69: * getLanguage to get the ISO Language Code. You can jpayne@69: * use getDisplayCountry to get the jpayne@69: * name of the country suitable for displaying to the user. Similarly, jpayne@69: * you can use getDisplayLanguage to get the name of jpayne@69: * the language suitable for displaying to the user. Interestingly, jpayne@69: * the getDisplayXXX methods are themselves locale-sensitive jpayne@69: * and have two versions: one that uses the default locale and one jpayne@69: * that takes a locale as an argument and displays the name or country in jpayne@69: * a language appropriate to that locale. jpayne@69: * jpayne@69: *

jpayne@69: * ICU provides a number of classes that perform locale-sensitive jpayne@69: * operations. For example, the NumberFormat class formats jpayne@69: * numbers, currency, or percentages in a locale-sensitive manner. Classes jpayne@69: * such as NumberFormat have a number of convenience methods jpayne@69: * for creating a default object of that type. For example, the jpayne@69: * NumberFormat class provides these three convenience methods jpayne@69: * for creating a default NumberFormat object: jpayne@69: * \htmlonly

\endhtmlonly jpayne@69: *
jpayne@69:  *     UErrorCode success = U_ZERO_ERROR;
jpayne@69:  *     Locale myLocale;
jpayne@69:  *     NumberFormat *nf;
jpayne@69:  *
jpayne@69:  *     nf = NumberFormat::createInstance( success );          delete nf;
jpayne@69:  *     nf = NumberFormat::createCurrencyInstance( success );  delete nf;
jpayne@69:  *     nf = NumberFormat::createPercentInstance( success );   delete nf;
jpayne@69:  * 
jpayne@69: * \htmlonly
\endhtmlonly jpayne@69: * Each of these methods has two variants; one with an explicit locale jpayne@69: * and one without; the latter using the default locale. jpayne@69: * \htmlonly
\endhtmlonly jpayne@69: *
jpayne@69:  *     nf = NumberFormat::createInstance( myLocale, success );          delete nf;
jpayne@69:  *     nf = NumberFormat::createCurrencyInstance( myLocale, success );  delete nf;
jpayne@69:  *     nf = NumberFormat::createPercentInstance( myLocale, success );   delete nf;
jpayne@69:  * 
jpayne@69: * \htmlonly
\endhtmlonly jpayne@69: * A Locale is the mechanism for identifying the kind of object jpayne@69: * (NumberFormat) that you would like to get. The locale is jpayne@69: * just a mechanism for identifying objects, jpayne@69: * not a container for the objects themselves. jpayne@69: * jpayne@69: *

jpayne@69: * Each class that performs locale-sensitive operations allows you jpayne@69: * to get all the available objects of that type. You can sift jpayne@69: * through these objects by language, country, or variant, jpayne@69: * and use the display names to present a menu to the user. jpayne@69: * For example, you can create a menu of all the collation objects jpayne@69: * suitable for a given language. Such classes implement these jpayne@69: * three class methods: jpayne@69: * \htmlonly

\endhtmlonly jpayne@69: *
jpayne@69:  *       static Locale* getAvailableLocales(int32_t& numLocales)
jpayne@69:  *       static UnicodeString& getDisplayName(const Locale&  objectLocale,
jpayne@69:  *                                            const Locale&  displayLocale,
jpayne@69:  *                                            UnicodeString& displayName)
jpayne@69:  *       static UnicodeString& getDisplayName(const Locale&  objectLocale,
jpayne@69:  *                                            UnicodeString& displayName)
jpayne@69:  * 
jpayne@69: * \htmlonly
\endhtmlonly jpayne@69: * jpayne@69: * @stable ICU 2.0 jpayne@69: * @see ResourceBundle jpayne@69: */ jpayne@69: class U_COMMON_API Locale : public UObject { jpayne@69: public: jpayne@69: /** Useful constant for the Root locale. @stable ICU 4.4 */ jpayne@69: static const Locale &U_EXPORT2 getRoot(void); jpayne@69: /** Useful constant for this language. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getEnglish(void); jpayne@69: /** Useful constant for this language. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getFrench(void); jpayne@69: /** Useful constant for this language. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getGerman(void); jpayne@69: /** Useful constant for this language. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getItalian(void); jpayne@69: /** Useful constant for this language. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getJapanese(void); jpayne@69: /** Useful constant for this language. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getKorean(void); jpayne@69: /** Useful constant for this language. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getChinese(void); jpayne@69: /** Useful constant for this language. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getSimplifiedChinese(void); jpayne@69: /** Useful constant for this language. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getTraditionalChinese(void); jpayne@69: jpayne@69: /** Useful constant for this country/region. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getFrance(void); jpayne@69: /** Useful constant for this country/region. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getGermany(void); jpayne@69: /** Useful constant for this country/region. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getItaly(void); jpayne@69: /** Useful constant for this country/region. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getJapan(void); jpayne@69: /** Useful constant for this country/region. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getKorea(void); jpayne@69: /** Useful constant for this country/region. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getChina(void); jpayne@69: /** Useful constant for this country/region. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getPRC(void); jpayne@69: /** Useful constant for this country/region. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getTaiwan(void); jpayne@69: /** Useful constant for this country/region. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getUK(void); jpayne@69: /** Useful constant for this country/region. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getUS(void); jpayne@69: /** Useful constant for this country/region. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getCanada(void); jpayne@69: /** Useful constant for this country/region. @stable ICU 2.0 */ jpayne@69: static const Locale &U_EXPORT2 getCanadaFrench(void); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Construct a default locale object, a Locale for the default locale ID. jpayne@69: * jpayne@69: * @see getDefault jpayne@69: * @see uloc_getDefault jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: Locale(); jpayne@69: jpayne@69: /** jpayne@69: * Construct a locale from language, country, variant. jpayne@69: * If an error occurs, then the constructed object will be "bogus" jpayne@69: * (isBogus() will return TRUE). jpayne@69: * jpayne@69: * @param language Lowercase two-letter or three-letter ISO-639 code. jpayne@69: * This parameter can instead be an ICU style C locale (e.g. "en_US"), jpayne@69: * but the other parameters must not be used. jpayne@69: * This parameter can be NULL; if so, jpayne@69: * the locale is initialized to match the current default locale. jpayne@69: * (This is the same as using the default constructor.) jpayne@69: * Please note: The Java Locale class does NOT accept the form jpayne@69: * 'new Locale("en_US")' but only 'new Locale("en","US")' jpayne@69: * jpayne@69: * @param country Uppercase two-letter ISO-3166 code. (optional) jpayne@69: * @param variant Uppercase vendor and browser specific code. See class jpayne@69: * description. (optional) jpayne@69: * @param keywordsAndValues A string consisting of keyword/values pairs, such as jpayne@69: * "collation=phonebook;currency=euro" jpayne@69: * jpayne@69: * @see getDefault jpayne@69: * @see uloc_getDefault jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: Locale( const char * language, jpayne@69: const char * country = 0, jpayne@69: const char * variant = 0, jpayne@69: const char * keywordsAndValues = 0); jpayne@69: jpayne@69: /** jpayne@69: * Initializes a Locale object from another Locale object. jpayne@69: * jpayne@69: * @param other The Locale object being copied in. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: Locale(const Locale& other); jpayne@69: jpayne@69: /** jpayne@69: * Move constructor; might leave source in bogus state. jpayne@69: * This locale will have the same contents that the source locale had. jpayne@69: * jpayne@69: * @param other The Locale object being moved in. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: Locale(Locale&& other) U_NOEXCEPT; jpayne@69: jpayne@69: /** jpayne@69: * Destructor jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual ~Locale() ; jpayne@69: jpayne@69: /** jpayne@69: * Replaces the entire contents of *this with the specified value. jpayne@69: * jpayne@69: * @param other The Locale object being copied in. jpayne@69: * @return *this jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: Locale& operator=(const Locale& other); jpayne@69: jpayne@69: /** jpayne@69: * Move assignment operator; might leave source in bogus state. jpayne@69: * This locale will have the same contents that the source locale had. jpayne@69: * The behavior is undefined if *this and the source are the same object. jpayne@69: * jpayne@69: * @param other The Locale object being moved in. jpayne@69: * @return *this jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: Locale& operator=(Locale&& other) U_NOEXCEPT; jpayne@69: jpayne@69: /** jpayne@69: * Checks if two locale keys are the same. jpayne@69: * jpayne@69: * @param other The locale key object to be compared with this. jpayne@69: * @return True if the two locale keys are the same, false otherwise. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UBool operator==(const Locale& other) const; jpayne@69: jpayne@69: /** jpayne@69: * Checks if two locale keys are not the same. jpayne@69: * jpayne@69: * @param other The locale key object to be compared with this. jpayne@69: * @return True if the two locale keys are not the same, false jpayne@69: * otherwise. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: inline UBool operator!=(const Locale& other) const; jpayne@69: jpayne@69: /** jpayne@69: * Clone this object. jpayne@69: * Clones can be used concurrently in multiple threads. jpayne@69: * If an error occurs, then NULL is returned. jpayne@69: * The caller must delete the clone. jpayne@69: * jpayne@69: * @return a clone of this object jpayne@69: * jpayne@69: * @see getDynamicClassID jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: Locale *clone() const; jpayne@69: jpayne@69: #ifndef U_HIDE_SYSTEM_API jpayne@69: /** jpayne@69: * Common methods of getting the current default Locale. Used for the jpayne@69: * presentation: menus, dialogs, etc. Generally set once when your applet or jpayne@69: * application is initialized, then never reset. (If you do reset the jpayne@69: * default locale, you probably want to reload your GUI, so that the change jpayne@69: * is reflected in your interface.) jpayne@69: * jpayne@69: * More advanced programs will allow users to use different locales for jpayne@69: * different fields, e.g. in a spreadsheet. jpayne@69: * jpayne@69: * Note that the initial setting will match the host system. jpayne@69: * @return a reference to the Locale object for the default locale ID jpayne@69: * @system jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static const Locale& U_EXPORT2 getDefault(void); jpayne@69: jpayne@69: /** jpayne@69: * Sets the default. Normally set once at the beginning of a process, jpayne@69: * then never reset. jpayne@69: * setDefault() only changes ICU's default locale ID, not jpayne@69: * the default locale ID of the runtime environment. jpayne@69: * jpayne@69: * @param newLocale Locale to set to. If NULL, set to the value obtained jpayne@69: * from the runtime environment. jpayne@69: * @param success The error code. jpayne@69: * @system jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static void U_EXPORT2 setDefault(const Locale& newLocale, jpayne@69: UErrorCode& success); jpayne@69: #endif /* U_HIDE_SYSTEM_API */ jpayne@69: jpayne@69: /** jpayne@69: * Returns a Locale for the specified BCP47 language tag string. jpayne@69: * If the specified language tag contains any ill-formed subtags, jpayne@69: * the first such subtag and all following subtags are ignored. jpayne@69: *

jpayne@69: * This implements the 'Language-Tag' production of BCP47, and so jpayne@69: * supports grandfathered (regular and irregular) as well as private jpayne@69: * use language tags. Private use tags are represented as 'x-whatever', jpayne@69: * and grandfathered tags are converted to their canonical replacements jpayne@69: * where they exist. Note that a few grandfathered tags have no modern jpayne@69: * replacement, these will be converted using the fallback described in jpayne@69: * the first paragraph, so some information might be lost. jpayne@69: * @param tag the input BCP47 language tag. jpayne@69: * @param status error information if creating the Locale failed. jpayne@69: * @return the Locale for the specified BCP47 language tag. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: static Locale U_EXPORT2 forLanguageTag(StringPiece tag, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Returns a well-formed language tag for this Locale. jpayne@69: *

jpayne@69: * Note: Any locale fields which do not satisfy the BCP47 syntax jpayne@69: * requirement will be silently omitted from the result. jpayne@69: * jpayne@69: * If this function fails, partial output may have been written to the sink. jpayne@69: * jpayne@69: * @param sink the output sink receiving the BCP47 language jpayne@69: * tag for this Locale. jpayne@69: * @param status error information if creating the language tag failed. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: void toLanguageTag(ByteSink& sink, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns a well-formed language tag for this Locale. jpayne@69: *

jpayne@69: * Note: Any locale fields which do not satisfy the BCP47 syntax jpayne@69: * requirement will be silently omitted from the result. jpayne@69: * jpayne@69: * @param status error information if creating the language tag failed. jpayne@69: * @return the BCP47 language tag for this Locale. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: template jpayne@69: inline StringClass toLanguageTag(UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Creates a locale which has had minimal canonicalization jpayne@69: * as per uloc_getName(). jpayne@69: * @param name The name to create from. If name is null, jpayne@69: * the default Locale is used. jpayne@69: * @return new locale object jpayne@69: * @stable ICU 2.0 jpayne@69: * @see uloc_getName jpayne@69: */ jpayne@69: static Locale U_EXPORT2 createFromName(const char *name); jpayne@69: jpayne@69: /** jpayne@69: * Creates a locale from the given string after canonicalizing jpayne@69: * the string according to CLDR by calling uloc_canonicalize(). jpayne@69: * @param name the locale ID to create from. Must not be NULL. jpayne@69: * @return a new locale object corresponding to the given name jpayne@69: * @stable ICU 3.0 jpayne@69: * @see uloc_canonicalize jpayne@69: */ jpayne@69: static Locale U_EXPORT2 createCanonical(const char* name); jpayne@69: jpayne@69: /** jpayne@69: * Returns the locale's ISO-639 language code. jpayne@69: * @return An alias to the code jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: inline const char * getLanguage( ) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the locale's ISO-15924 abbreviation script code. jpayne@69: * @return An alias to the code jpayne@69: * @see uscript_getShortName jpayne@69: * @see uscript_getCode jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: inline const char * getScript( ) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the locale's ISO-3166 country code. jpayne@69: * @return An alias to the code jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: inline const char * getCountry( ) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the locale's variant code. jpayne@69: * @return An alias to the code jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: inline const char * getVariant( ) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the programmatic name of the entire locale, with the language, jpayne@69: * country and variant separated by underbars. If a field is missing, up jpayne@69: * to two leading underbars will occur. Example: "en", "de_DE", "en_US_WIN", jpayne@69: * "de__POSIX", "fr__MAC", "__MAC", "_MT", "_FR_EURO" jpayne@69: * @return A pointer to "name". jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: inline const char * getName() const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the programmatic name of the entire locale as getName() would return, jpayne@69: * but without keywords. jpayne@69: * @return A pointer to "name". jpayne@69: * @see getName jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: const char * getBaseName() const; jpayne@69: jpayne@69: /** jpayne@69: * Add the likely subtags for this Locale, per the algorithm described jpayne@69: * in the following CLDR technical report: jpayne@69: * jpayne@69: * http://www.unicode.org/reports/tr35/#Likely_Subtags jpayne@69: * jpayne@69: * If this Locale is already in the maximal form, or not valid, or there is jpayne@69: * no data available for maximization, the Locale will be unchanged. jpayne@69: * jpayne@69: * For example, "und-Zzzz" cannot be maximized, since there is no jpayne@69: * reasonable maximization. jpayne@69: * jpayne@69: * Examples: jpayne@69: * jpayne@69: * "en" maximizes to "en_Latn_US" jpayne@69: * jpayne@69: * "de" maximizes to "de_Latn_US" jpayne@69: * jpayne@69: * "sr" maximizes to "sr_Cyrl_RS" jpayne@69: * jpayne@69: * "sh" maximizes to "sr_Latn_RS" (Note this will not reverse.) jpayne@69: * jpayne@69: * "zh_Hani" maximizes to "zh_Hans_CN" (Note this will not reverse.) jpayne@69: * jpayne@69: * @param status error information if maximizing this Locale failed. jpayne@69: * If this Locale is not well-formed, the error code is jpayne@69: * U_ILLEGAL_ARGUMENT_ERROR. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: void addLikelySubtags(UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Minimize the subtags for this Locale, per the algorithm described jpayne@69: * in the following CLDR technical report: jpayne@69: * jpayne@69: * http://www.unicode.org/reports/tr35/#Likely_Subtags jpayne@69: * jpayne@69: * If this Locale is already in the minimal form, or not valid, or there is jpayne@69: * no data available for minimization, the Locale will be unchanged. jpayne@69: * jpayne@69: * Since the minimization algorithm relies on proper maximization, see the jpayne@69: * comments for addLikelySubtags for reasons why there might not be any jpayne@69: * data. jpayne@69: * jpayne@69: * Examples: jpayne@69: * jpayne@69: * "en_Latn_US" minimizes to "en" jpayne@69: * jpayne@69: * "de_Latn_US" minimizes to "de" jpayne@69: * jpayne@69: * "sr_Cyrl_RS" minimizes to "sr" jpayne@69: * jpayne@69: * "zh_Hant_TW" minimizes to "zh_TW" (The region is preferred to the jpayne@69: * script, and minimizing to "zh" would imply "zh_Hans_CN".) jpayne@69: * jpayne@69: * @param status error information if maximizing this Locale failed. jpayne@69: * If this Locale is not well-formed, the error code is jpayne@69: * U_ILLEGAL_ARGUMENT_ERROR. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: void minimizeSubtags(UErrorCode& status); jpayne@69: jpayne@69: #ifndef U_HIDE_DRAFT_API jpayne@69: /** jpayne@69: * Canonicalize the locale ID of this object according to CLDR. jpayne@69: * @param status the status code jpayne@69: * @draft ICU 67 jpayne@69: * @see createCanonical jpayne@69: */ jpayne@69: void canonicalize(UErrorCode& status); jpayne@69: #endif // U_HIDE_DRAFT_API jpayne@69: jpayne@69: /** jpayne@69: * Gets the list of keywords for the specified locale. jpayne@69: * jpayne@69: * @param status the status code jpayne@69: * @return pointer to StringEnumeration class, or NULL if there are no keywords. jpayne@69: * Client must dispose of it by calling delete. jpayne@69: * @see getKeywords jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: StringEnumeration * createKeywords(UErrorCode &status) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the list of Unicode keywords for the specified locale. jpayne@69: * jpayne@69: * @param status the status code jpayne@69: * @return pointer to StringEnumeration class, or NULL if there are no keywords. jpayne@69: * Client must dispose of it by calling delete. jpayne@69: * @see getUnicodeKeywords jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: StringEnumeration * createUnicodeKeywords(UErrorCode &status) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the set of keywords for this Locale. jpayne@69: * jpayne@69: * A wrapper to call createKeywords() and write the resulting jpayne@69: * keywords as standard strings (or compatible objects) into any kind of jpayne@69: * container that can be written to by an STL style output iterator. jpayne@69: * jpayne@69: * @param iterator an STL style output iterator to write the keywords to. jpayne@69: * @param status error information if creating set of keywords failed. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: template jpayne@69: inline void getKeywords(OutputIterator iterator, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the set of Unicode keywords for this Locale. jpayne@69: * jpayne@69: * A wrapper to call createUnicodeKeywords() and write the resulting jpayne@69: * keywords as standard strings (or compatible objects) into any kind of jpayne@69: * container that can be written to by an STL style output iterator. jpayne@69: * jpayne@69: * @param iterator an STL style output iterator to write the keywords to. jpayne@69: * @param status error information if creating set of keywords failed. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: template jpayne@69: inline void getUnicodeKeywords(OutputIterator iterator, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the value for a keyword. jpayne@69: * jpayne@69: * This uses legacy keyword=value pairs, like "collation=phonebook". jpayne@69: * jpayne@69: * ICU4C doesn't do automatic conversion between legacy and Unicode jpayne@69: * keywords and values in getters and setters (as opposed to ICU4J). jpayne@69: * jpayne@69: * @param keywordName name of the keyword for which we want the value. Case insensitive. jpayne@69: * @param buffer The buffer to receive the keyword value. jpayne@69: * @param bufferCapacity The capacity of receiving buffer jpayne@69: * @param status Returns any error information while performing this operation. jpayne@69: * @return the length of the keyword value jpayne@69: * jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the value for a keyword. jpayne@69: * jpayne@69: * This uses legacy keyword=value pairs, like "collation=phonebook". jpayne@69: * jpayne@69: * ICU4C doesn't do automatic conversion between legacy and Unicode jpayne@69: * keywords and values in getters and setters (as opposed to ICU4J). jpayne@69: * jpayne@69: * @param keywordName name of the keyword for which we want the value. jpayne@69: * @param sink the sink to receive the keyword value. jpayne@69: * @param status error information if getting the value failed. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: void getKeywordValue(StringPiece keywordName, ByteSink& sink, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the value for a keyword. jpayne@69: * jpayne@69: * This uses legacy keyword=value pairs, like "collation=phonebook". jpayne@69: * jpayne@69: * ICU4C doesn't do automatic conversion between legacy and Unicode jpayne@69: * keywords and values in getters and setters (as opposed to ICU4J). jpayne@69: * jpayne@69: * @param keywordName name of the keyword for which we want the value. jpayne@69: * @param status error information if getting the value failed. jpayne@69: * @return the keyword value. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: template jpayne@69: inline StringClass getKeywordValue(StringPiece keywordName, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the Unicode value for a Unicode keyword. jpayne@69: * jpayne@69: * This uses Unicode key-value pairs, like "co-phonebk". jpayne@69: * jpayne@69: * ICU4C doesn't do automatic conversion between legacy and Unicode jpayne@69: * keywords and values in getters and setters (as opposed to ICU4J). jpayne@69: * jpayne@69: * @param keywordName name of the keyword for which we want the value. jpayne@69: * @param sink the sink to receive the keyword value. jpayne@69: * @param status error information if getting the value failed. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: void getUnicodeKeywordValue(StringPiece keywordName, ByteSink& sink, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the Unicode value for a Unicode keyword. jpayne@69: * jpayne@69: * This uses Unicode key-value pairs, like "co-phonebk". jpayne@69: * jpayne@69: * ICU4C doesn't do automatic conversion between legacy and Unicode jpayne@69: * keywords and values in getters and setters (as opposed to ICU4J). jpayne@69: * jpayne@69: * @param keywordName name of the keyword for which we want the value. jpayne@69: * @param status error information if getting the value failed. jpayne@69: * @return the keyword value. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: template jpayne@69: inline StringClass getUnicodeKeywordValue(StringPiece keywordName, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets or removes the value for a keyword. jpayne@69: * jpayne@69: * For removing all keywords, use getBaseName(), jpayne@69: * and construct a new Locale if it differs from getName(). jpayne@69: * jpayne@69: * This uses legacy keyword=value pairs, like "collation=phonebook". jpayne@69: * jpayne@69: * ICU4C doesn't do automatic conversion between legacy and Unicode jpayne@69: * keywords and values in getters and setters (as opposed to ICU4J). jpayne@69: * jpayne@69: * @param keywordName name of the keyword to be set. Case insensitive. jpayne@69: * @param keywordValue value of the keyword to be set. If 0-length or jpayne@69: * NULL, will result in the keyword being removed. No error is given if jpayne@69: * that keyword does not exist. jpayne@69: * @param status Returns any error information while performing this operation. jpayne@69: * jpayne@69: * @stable ICU 49 jpayne@69: */ jpayne@69: void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status); jpayne@69: jpayne@69: /** jpayne@69: * Sets or removes the value for a keyword. jpayne@69: * jpayne@69: * For removing all keywords, use getBaseName(), jpayne@69: * and construct a new Locale if it differs from getName(). jpayne@69: * jpayne@69: * This uses legacy keyword=value pairs, like "collation=phonebook". jpayne@69: * jpayne@69: * ICU4C doesn't do automatic conversion between legacy and Unicode jpayne@69: * keywords and values in getters and setters (as opposed to ICU4J). jpayne@69: * jpayne@69: * @param keywordName name of the keyword to be set. jpayne@69: * @param keywordValue value of the keyword to be set. If 0-length or jpayne@69: * NULL, will result in the keyword being removed. No error is given if jpayne@69: * that keyword does not exist. jpayne@69: * @param status Returns any error information while performing this operation. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: void setKeywordValue(StringPiece keywordName, StringPiece keywordValue, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Sets or removes the Unicode value for a Unicode keyword. jpayne@69: * jpayne@69: * For removing all keywords, use getBaseName(), jpayne@69: * and construct a new Locale if it differs from getName(). jpayne@69: * jpayne@69: * This uses Unicode key-value pairs, like "co-phonebk". jpayne@69: * jpayne@69: * ICU4C doesn't do automatic conversion between legacy and Unicode jpayne@69: * keywords and values in getters and setters (as opposed to ICU4J). jpayne@69: * jpayne@69: * @param keywordName name of the keyword to be set. jpayne@69: * @param keywordValue value of the keyword to be set. If 0-length or jpayne@69: * NULL, will result in the keyword being removed. No error is given if jpayne@69: * that keyword does not exist. jpayne@69: * @param status Returns any error information while performing this operation. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: void setUnicodeKeywordValue(StringPiece keywordName, StringPiece keywordValue, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * returns the locale's three-letter language code, as specified jpayne@69: * in ISO draft standard ISO-639-2. jpayne@69: * @return An alias to the code, or an empty string jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: const char * getISO3Language() const; jpayne@69: jpayne@69: /** jpayne@69: * Fills in "name" with the locale's three-letter ISO-3166 country code. jpayne@69: * @return An alias to the code, or an empty string jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: const char * getISO3Country() const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the Windows LCID value corresponding to this locale. jpayne@69: * This value is stored in the resource data for the locale as a one-to-four-digit jpayne@69: * hexadecimal number. If the resource is missing, in the wrong format, or jpayne@69: * there is no Windows LCID value that corresponds to this locale, returns 0. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: uint32_t getLCID(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns whether this locale's script is written right-to-left. jpayne@69: * If there is no script subtag, then the likely script is used, see uloc_addLikelySubtags(). jpayne@69: * If no likely script is known, then FALSE is returned. jpayne@69: * jpayne@69: * A script is right-to-left according to the CLDR script metadata jpayne@69: * which corresponds to whether the script's letters have Bidi_Class=R or AL. jpayne@69: * jpayne@69: * Returns TRUE for "ar" and "en-Hebr", FALSE for "zh" and "fa-Cyrl". jpayne@69: * jpayne@69: * @return TRUE if the locale's script is written right-to-left jpayne@69: * @stable ICU 54 jpayne@69: */ jpayne@69: UBool isRightToLeft() const; jpayne@69: jpayne@69: /** jpayne@69: * Fills in "dispLang" with the name of this locale's language in a format suitable for jpayne@69: * user display in the default locale. For example, if the locale's language code is jpayne@69: * "fr" and the default locale's language code is "en", this function would set jpayne@69: * dispLang to "French". jpayne@69: * @param dispLang Receives the language's display name. jpayne@69: * @return A reference to "dispLang". jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const; jpayne@69: jpayne@69: /** jpayne@69: * Fills in "dispLang" with the name of this locale's language in a format suitable for jpayne@69: * user display in the locale specified by "displayLocale". For example, if the locale's jpayne@69: * language code is "en" and displayLocale's language code is "fr", this function would set jpayne@69: * dispLang to "Anglais". jpayne@69: * @param displayLocale Specifies the locale to be used to display the name. In other words, jpayne@69: * if the locale's language code is "en", passing Locale::getFrench() for jpayne@69: * displayLocale would result in "Anglais", while passing Locale::getGerman() jpayne@69: * for displayLocale would result in "Englisch". jpayne@69: * @param dispLang Receives the language's display name. jpayne@69: * @return A reference to "dispLang". jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UnicodeString& getDisplayLanguage( const Locale& displayLocale, jpayne@69: UnicodeString& dispLang) const; jpayne@69: jpayne@69: /** jpayne@69: * Fills in "dispScript" with the name of this locale's script in a format suitable jpayne@69: * for user display in the default locale. For example, if the locale's script code jpayne@69: * is "LATN" and the default locale's language code is "en", this function would set jpayne@69: * dispScript to "Latin". jpayne@69: * @param dispScript Receives the scripts's display name. jpayne@69: * @return A reference to "dispScript". jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: UnicodeString& getDisplayScript( UnicodeString& dispScript) const; jpayne@69: jpayne@69: /** jpayne@69: * Fills in "dispScript" with the name of this locale's country in a format suitable jpayne@69: * for user display in the locale specified by "displayLocale". For example, if the locale's jpayne@69: * script code is "LATN" and displayLocale's language code is "en", this function would set jpayne@69: * dispScript to "Latin". jpayne@69: * @param displayLocale Specifies the locale to be used to display the name. In other jpayne@69: * words, if the locale's script code is "LATN", passing jpayne@69: * Locale::getFrench() for displayLocale would result in "", while jpayne@69: * passing Locale::getGerman() for displayLocale would result in jpayne@69: * "". jpayne@69: * @param dispScript Receives the scripts's display name. jpayne@69: * @return A reference to "dispScript". jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: UnicodeString& getDisplayScript( const Locale& displayLocale, jpayne@69: UnicodeString& dispScript) const; jpayne@69: jpayne@69: /** jpayne@69: * Fills in "dispCountry" with the name of this locale's country in a format suitable jpayne@69: * for user display in the default locale. For example, if the locale's country code jpayne@69: * is "FR" and the default locale's language code is "en", this function would set jpayne@69: * dispCountry to "France". jpayne@69: * @param dispCountry Receives the country's display name. jpayne@69: * @return A reference to "dispCountry". jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const; jpayne@69: jpayne@69: /** jpayne@69: * Fills in "dispCountry" with the name of this locale's country in a format suitable jpayne@69: * for user display in the locale specified by "displayLocale". For example, if the locale's jpayne@69: * country code is "US" and displayLocale's language code is "fr", this function would set jpayne@69: * dispCountry to "États-Unis". jpayne@69: * @param displayLocale Specifies the locale to be used to display the name. In other jpayne@69: * words, if the locale's country code is "US", passing jpayne@69: * Locale::getFrench() for displayLocale would result in "États-Unis", while jpayne@69: * passing Locale::getGerman() for displayLocale would result in jpayne@69: * "Vereinigte Staaten". jpayne@69: * @param dispCountry Receives the country's display name. jpayne@69: * @return A reference to "dispCountry". jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UnicodeString& getDisplayCountry( const Locale& displayLocale, jpayne@69: UnicodeString& dispCountry) const; jpayne@69: jpayne@69: /** jpayne@69: * Fills in "dispVar" with the name of this locale's variant code in a format suitable jpayne@69: * for user display in the default locale. jpayne@69: * @param dispVar Receives the variant's name. jpayne@69: * @return A reference to "dispVar". jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UnicodeString& getDisplayVariant( UnicodeString& dispVar) const; jpayne@69: jpayne@69: /** jpayne@69: * Fills in "dispVar" with the name of this locale's variant code in a format jpayne@69: * suitable for user display in the locale specified by "displayLocale". jpayne@69: * @param displayLocale Specifies the locale to be used to display the name. jpayne@69: * @param dispVar Receives the variant's display name. jpayne@69: * @return A reference to "dispVar". jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UnicodeString& getDisplayVariant( const Locale& displayLocale, jpayne@69: UnicodeString& dispVar) const; jpayne@69: jpayne@69: /** jpayne@69: * Fills in "name" with the name of this locale in a format suitable for user display jpayne@69: * in the default locale. This function uses getDisplayLanguage(), getDisplayCountry(), jpayne@69: * and getDisplayVariant() to do its work, and outputs the display name in the format jpayne@69: * "language (country[,variant])". For example, if the default locale is en_US, then jpayne@69: * fr_FR's display name would be "French (France)", and es_MX_Traditional's display name jpayne@69: * would be "Spanish (Mexico,Traditional)". jpayne@69: * @param name Receives the locale's display name. jpayne@69: * @return A reference to "name". jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UnicodeString& getDisplayName( UnicodeString& name) const; jpayne@69: jpayne@69: /** jpayne@69: * Fills in "name" with the name of this locale in a format suitable for user display jpayne@69: * in the locale specified by "displayLocale". This function uses getDisplayLanguage(), jpayne@69: * getDisplayCountry(), and getDisplayVariant() to do its work, and outputs the display jpayne@69: * name in the format "language (country[,variant])". For example, if displayLocale is jpayne@69: * fr_FR, then en_US's display name would be "Anglais (États-Unis)", and no_NO_NY's jpayne@69: * display name would be "norvégien (Norvège,NY)". jpayne@69: * @param displayLocale Specifies the locale to be used to display the name. jpayne@69: * @param name Receives the locale's display name. jpayne@69: * @return A reference to "name". jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UnicodeString& getDisplayName( const Locale& displayLocale, jpayne@69: UnicodeString& name) const; jpayne@69: jpayne@69: /** jpayne@69: * Generates a hash code for the locale. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: int32_t hashCode(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets the locale to bogus jpayne@69: * A bogus locale represents a non-existing locale associated jpayne@69: * with services that can be instantiated from non-locale data jpayne@69: * in addition to locale (for example, collation can be jpayne@69: * instantiated from a locale and from a rule set). jpayne@69: * @stable ICU 2.1 jpayne@69: */ jpayne@69: void setToBogus(); jpayne@69: jpayne@69: /** jpayne@69: * Gets the bogus state. Locale object can be bogus if it doesn't exist jpayne@69: * @return FALSE if it is a real locale, TRUE if it is a bogus locale jpayne@69: * @stable ICU 2.1 jpayne@69: */ jpayne@69: inline UBool isBogus(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns a list of all installed locales. jpayne@69: * @param count Receives the number of locales in the list. jpayne@69: * @return A pointer to an array of Locale objects. This array is the list jpayne@69: * of all locales with installed resource files. The called does NOT jpayne@69: * get ownership of this list, and must NOT delete it. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count); jpayne@69: jpayne@69: /** jpayne@69: * Gets a list of all available 2-letter country codes defined in ISO 3166. This is a jpayne@69: * pointer to an array of pointers to arrays of char. All of these pointers are jpayne@69: * owned by ICU-- do not delete them, and do not write through them. The array is jpayne@69: * terminated with a null pointer. jpayne@69: * @return a list of all available country codes jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static const char* const* U_EXPORT2 getISOCountries(); jpayne@69: jpayne@69: /** jpayne@69: * Gets a list of all available language codes defined in ISO 639. This is a pointer jpayne@69: * to an array of pointers to arrays of char. All of these pointers are owned jpayne@69: * by ICU-- do not delete them, and do not write through them. The array is jpayne@69: * terminated with a null pointer. jpayne@69: * @return a list of all available language codes jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static const char* const* U_EXPORT2 getISOLanguages(); jpayne@69: jpayne@69: /** jpayne@69: * ICU "poor man's RTTI", returns a UClassID for this class. jpayne@69: * jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(); jpayne@69: jpayne@69: /** jpayne@69: * ICU "poor man's RTTI", returns a UClassID for the actual class. jpayne@69: * jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: virtual UClassID getDynamicClassID() const; jpayne@69: jpayne@69: #ifndef U_HIDE_DRAFT_API jpayne@69: /** jpayne@69: * A Locale iterator interface similar to a Java Iterator. jpayne@69: * @draft ICU 65 jpayne@69: */ jpayne@69: class U_COMMON_API Iterator /* not : public UObject because this is an interface/mixin class */ { jpayne@69: public: jpayne@69: /** @draft ICU 65 */ jpayne@69: virtual ~Iterator(); jpayne@69: jpayne@69: /** jpayne@69: * @return TRUE if next() can be called again. jpayne@69: * @draft ICU 65 jpayne@69: */ jpayne@69: virtual UBool hasNext() const = 0; jpayne@69: jpayne@69: /** jpayne@69: * @return the next locale. jpayne@69: * @draft ICU 65 jpayne@69: */ jpayne@69: virtual const Locale &next() = 0; jpayne@69: }; jpayne@69: jpayne@69: /** jpayne@69: * A generic Locale iterator implementation over Locale input iterators. jpayne@69: * @draft ICU 65 jpayne@69: */ jpayne@69: template jpayne@69: class RangeIterator : public Iterator, public UMemory { jpayne@69: public: jpayne@69: /** jpayne@69: * Constructs an iterator from a begin/end range. jpayne@69: * Each of the iterator parameter values must be an jpayne@69: * input iterator whose value is convertible to const Locale &. jpayne@69: * jpayne@69: * @param begin Start of range. jpayne@69: * @param end Exclusive end of range. jpayne@69: * @draft ICU 65 jpayne@69: */ jpayne@69: RangeIterator(Iter begin, Iter end) : it_(begin), end_(end) {} jpayne@69: jpayne@69: /** jpayne@69: * @return TRUE if next() can be called again. jpayne@69: * @draft ICU 65 jpayne@69: */ jpayne@69: UBool hasNext() const override { return it_ != end_; } jpayne@69: jpayne@69: /** jpayne@69: * @return the next locale. jpayne@69: * @draft ICU 65 jpayne@69: */ jpayne@69: const Locale &next() override { return *it_++; } jpayne@69: jpayne@69: private: jpayne@69: Iter it_; jpayne@69: const Iter end_; jpayne@69: }; jpayne@69: jpayne@69: /** jpayne@69: * A generic Locale iterator implementation over Locale input iterators. jpayne@69: * Calls the converter to convert each *begin to a const Locale &. jpayne@69: * @draft ICU 65 jpayne@69: */ jpayne@69: template jpayne@69: class ConvertingIterator : public Iterator, public UMemory { jpayne@69: public: jpayne@69: /** jpayne@69: * Constructs an iterator from a begin/end range. jpayne@69: * Each of the iterator parameter values must be an jpayne@69: * input iterator whose value the converter converts to const Locale &. jpayne@69: * jpayne@69: * @param begin Start of range. jpayne@69: * @param end Exclusive end of range. jpayne@69: * @param converter Converter from *begin to const Locale & or compatible. jpayne@69: * @draft ICU 65 jpayne@69: */ jpayne@69: ConvertingIterator(Iter begin, Iter end, Conv converter) : jpayne@69: it_(begin), end_(end), converter_(converter) {} jpayne@69: jpayne@69: /** jpayne@69: * @return TRUE if next() can be called again. jpayne@69: * @draft ICU 65 jpayne@69: */ jpayne@69: UBool hasNext() const override { return it_ != end_; } jpayne@69: jpayne@69: /** jpayne@69: * @return the next locale. jpayne@69: * @draft ICU 65 jpayne@69: */ jpayne@69: const Locale &next() override { return converter_(*it_++); } jpayne@69: jpayne@69: private: jpayne@69: Iter it_; jpayne@69: const Iter end_; jpayne@69: Conv converter_; jpayne@69: }; jpayne@69: #endif // U_HIDE_DRAFT_API jpayne@69: jpayne@69: protected: /* only protected for testing purposes. DO NOT USE. */ jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Set this from a single POSIX style locale string. jpayne@69: * @internal jpayne@69: */ jpayne@69: void setFromPOSIXID(const char *posixID); jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: private: jpayne@69: /** jpayne@69: * Initialize the locale object with a new name. jpayne@69: * Was deprecated - used in implementation - moved internal jpayne@69: * jpayne@69: * @param cLocaleID The new locale name. jpayne@69: * @param canonicalize whether to call uloc_canonicalize on cLocaleID jpayne@69: */ jpayne@69: Locale& init(const char* cLocaleID, UBool canonicalize); jpayne@69: jpayne@69: /* jpayne@69: * Internal constructor to allow construction of a locale object with jpayne@69: * NO side effects. (Default constructor tries to get jpayne@69: * the default locale.) jpayne@69: */ jpayne@69: enum ELocaleType { jpayne@69: eBOGUS jpayne@69: }; jpayne@69: Locale(ELocaleType); jpayne@69: jpayne@69: /** jpayne@69: * Initialize the locale cache for commonly used locales jpayne@69: */ jpayne@69: static Locale *getLocaleCache(void); jpayne@69: jpayne@69: char language[ULOC_LANG_CAPACITY]; jpayne@69: char script[ULOC_SCRIPT_CAPACITY]; jpayne@69: char country[ULOC_COUNTRY_CAPACITY]; jpayne@69: int32_t variantBegin; jpayne@69: char* fullName; jpayne@69: char fullNameBuffer[ULOC_FULLNAME_CAPACITY]; jpayne@69: // name without keywords jpayne@69: char* baseName; jpayne@69: void initBaseName(UErrorCode& status); jpayne@69: jpayne@69: UBool fIsBogus; jpayne@69: jpayne@69: static const Locale &getLocale(int locid); jpayne@69: jpayne@69: /** jpayne@69: * A friend to allow the default locale to be set by either the C or C++ API. jpayne@69: * @internal (private) jpayne@69: */ jpayne@69: friend Locale *locale_set_default_internal(const char *, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * @internal (private) jpayne@69: */ jpayne@69: friend void U_CALLCONV locale_available_init(); jpayne@69: }; jpayne@69: jpayne@69: inline UBool jpayne@69: Locale::operator!=(const Locale& other) const jpayne@69: { jpayne@69: return !operator==(other); jpayne@69: } jpayne@69: jpayne@69: template inline StringClass jpayne@69: Locale::toLanguageTag(UErrorCode& status) const jpayne@69: { jpayne@69: StringClass result; jpayne@69: StringByteSink sink(&result); jpayne@69: toLanguageTag(sink, status); jpayne@69: return result; jpayne@69: } jpayne@69: jpayne@69: inline const char * jpayne@69: Locale::getCountry() const jpayne@69: { jpayne@69: return country; jpayne@69: } jpayne@69: jpayne@69: inline const char * jpayne@69: Locale::getLanguage() const jpayne@69: { jpayne@69: return language; jpayne@69: } jpayne@69: jpayne@69: inline const char * jpayne@69: Locale::getScript() const jpayne@69: { jpayne@69: return script; jpayne@69: } jpayne@69: jpayne@69: inline const char * jpayne@69: Locale::getVariant() const jpayne@69: { jpayne@69: return &baseName[variantBegin]; jpayne@69: } jpayne@69: jpayne@69: inline const char * jpayne@69: Locale::getName() const jpayne@69: { jpayne@69: return fullName; jpayne@69: } jpayne@69: jpayne@69: template inline void jpayne@69: Locale::getKeywords(OutputIterator iterator, UErrorCode& status) const jpayne@69: { jpayne@69: LocalPointer keys(createKeywords(status)); jpayne@69: if (U_FAILURE(status) || keys.isNull()) { jpayne@69: return; jpayne@69: } jpayne@69: for (;;) { jpayne@69: int32_t resultLength; jpayne@69: const char* buffer = keys->next(&resultLength, status); jpayne@69: if (U_FAILURE(status) || buffer == nullptr) { jpayne@69: return; jpayne@69: } jpayne@69: *iterator++ = StringClass(buffer, resultLength); jpayne@69: } jpayne@69: } jpayne@69: jpayne@69: template inline void jpayne@69: Locale::getUnicodeKeywords(OutputIterator iterator, UErrorCode& status) const jpayne@69: { jpayne@69: LocalPointer keys(createUnicodeKeywords(status)); jpayne@69: if (U_FAILURE(status) || keys.isNull()) { jpayne@69: return; jpayne@69: } jpayne@69: for (;;) { jpayne@69: int32_t resultLength; jpayne@69: const char* buffer = keys->next(&resultLength, status); jpayne@69: if (U_FAILURE(status) || buffer == nullptr) { jpayne@69: return; jpayne@69: } jpayne@69: *iterator++ = StringClass(buffer, resultLength); jpayne@69: } jpayne@69: } jpayne@69: jpayne@69: template inline StringClass jpayne@69: Locale::getKeywordValue(StringPiece keywordName, UErrorCode& status) const jpayne@69: { jpayne@69: StringClass result; jpayne@69: StringByteSink sink(&result); jpayne@69: getKeywordValue(keywordName, sink, status); jpayne@69: return result; jpayne@69: } jpayne@69: jpayne@69: template inline StringClass jpayne@69: Locale::getUnicodeKeywordValue(StringPiece keywordName, UErrorCode& status) const jpayne@69: { jpayne@69: StringClass result; jpayne@69: StringByteSink sink(&result); jpayne@69: getUnicodeKeywordValue(keywordName, sink, status); jpayne@69: return result; jpayne@69: } jpayne@69: jpayne@69: inline UBool jpayne@69: Locale::isBogus(void) const { jpayne@69: return fIsBogus; jpayne@69: } jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif