/*
******************************************************************************
*
-* Copyright (C) 1996-2004, International Business Machines
+* Copyright (C) 1996-2015, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
* \brief C++ API: Locale ID object.
*/
+U_NAMESPACE_BEGIN
+
+// Forward Declarations
+void U_CALLCONV locale_available_init(); /**< @internal */
+
/**
* A <code>Locale</code> object represents a specific geographical, political,
* or cultural region. An operation that requires a <code>Locale</code> to perform
* this class:
* \htmlonly<blockquote>\endhtmlonly
* <pre>
- * . Locale( const char* language,
- * . const char* country,
- * . const char* variant);
+ * Locale( const char* language,
+ * const char* country,
+ * const char* variant);
* </pre>
* \htmlonly</blockquote>\endhtmlonly
* The first argument to the constructors is a valid <STRONG>ISO
* Code.</STRONG> These codes are the upper-case two-letter codes
* as defined by ISO-3166.
* You can find a full list of these codes at a number of sites, such as:
- * <BR><a href="http://www.iso.ch/iso/en/prods-services/iso3166ma/index.html">
- * http://www.iso.ch/iso/en/prods-services/iso3166ma/index.html</a>
+ * <BR><a href="http://www.iso.org/iso/en/prods-services/iso3166ma/index.html">
+ * http://www.iso.org/iso/en/prods-services/iso3166ma/index.html</a>
*
* <P>
* The third constructor requires a third argument--the <STRONG>Variant.</STRONG>
* The Variant codes are vendor and browser-specific.
- * For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX.
+ * For example, use REVISED for a langauge's revised script orthography, and POSIX for POSIX.
* Where there are two variants, separate them with an underscore, and
* put the most important one first. For
* example, a Traditional Spanish collation might be referenced, with
- * "ES", "ES", "Traditional_WIN".
+ * "ES", "ES", "Traditional_POSIX".
*
* <P>
* Because a <code>Locale</code> object is just an identifier for a region,
* @stable ICU 2.0
* @see ResourceBundle
*/
-U_NAMESPACE_BEGIN
class U_COMMON_API Locale : public UObject {
public:
+ /** Useful constant for the Root locale. @stable ICU 4.4 */
+ static const Locale &U_EXPORT2 getRoot(void);
/** Useful constant for this language. @stable ICU 2.0 */
static const Locale &U_EXPORT2 getEnglish(void);
/** Useful constant for this language. @stable ICU 2.0 */
* @return a clone of this object
*
* @see getDynamicClassID
- * @draft ICU 2.8
+ * @stable ICU 2.8
*/
Locale *clone() const;
+#ifndef U_HIDE_SYSTEM_API
/**
* Common methods of getting the current default Locale. Used for the
* presentation: menus, dialogs, etc. Generally set once when your applet or
*/
static void U_EXPORT2 setDefault(const Locale& newLocale,
UErrorCode& success);
+#endif /* U_HIDE_SYSTEM_API */
/**
* Creates a locale which has had minimal canonicalization
* the string by calling uloc_canonicalize().
* @param name the locale ID to create from. Must not be NULL.
* @return a new locale object corresponding to the given name
- * @draft ICU 3.0
+ * @stable ICU 3.0
* @see uloc_canonicalize
*/
static Locale U_EXPORT2 createCanonical(const char* name);
* @return An alias to the code
* @see uscript_getShortName
* @see uscript_getCode
- * @draft ICU 2.8
+ * @stable ICU 2.8
*/
inline const char * getScript( ) const;
inline const char * getName() const;
/**
- * Returns the programmatic name of the entire locale as getName would return,
+ * Returns the programmatic name of the entire locale as getName() would return,
* but without keywords.
* @return A pointer to "name".
* @see getName
- * @draft ICU 2.8
+ * @stable ICU 2.8
*/
const char * getBaseName() const;
/**
* Gets the list of keywords for the specified locale.
*
- * @return pointer to StringEnumeration class. Client must dispose of it by calling delete.
- * @param status Returns any error information while performing this operation.
- * @draft ICU 2.8
+ * @param status the status code
+ * @return pointer to StringEnumeration class, or NULL if there are no keywords.
+ * Client must dispose of it by calling delete.
+ * @stable ICU 2.8
*/
StringEnumeration * createKeywords(UErrorCode &status) const;
/**
- * Get the value for a keyword.
+ * Gets the value for a keyword.
*
* @param keywordName name of the keyword for which we want the value. Case insensitive.
- * @param status Returns any error information while performing this operation.
* @param buffer The buffer to receive the keyword value.
* @param bufferCapacity The capacity of receiving buffer
- * @return the length of keyword value
+ * @param status Returns any error information while performing this operation.
+ * @return the length of the keyword value
*
- * @draft ICU 2.8
+ * @stable ICU 2.8
*/
int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
+ /**
+ * Sets or removes the value for a keyword.
+ *
+ * For removing all keywords, use getBaseName(),
+ * and construct a new Locale if it differs from getName().
+ *
+ * @param keywordName name of the keyword to be set. Case insensitive.
+ * @param keywordValue value of the keyword to be set. If 0-length or
+ * NULL, will result in the keyword being removed. No error is given if
+ * that keyword does not exist.
+ * @param status Returns any error information while performing this operation.
+ *
+ * @stable ICU 49
+ */
+ void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
+
/**
* returns the locale's three-letter language code, as specified
- * in ISO draft standard ISO-639-2..
- * @return An alias to the code, or NULL
+ * in ISO draft standard ISO-639-2.
+ * @return An alias to the code, or an empty string
* @stable ICU 2.0
*/
const char * getISO3Language() const;
/**
* Fills in "name" with the locale's three-letter ISO-3166 country code.
- * @return An alias to the code, or NULL
+ * @return An alias to the code, or an empty string
* @stable ICU 2.0
*/
const char * getISO3Country() const;
*/
uint32_t getLCID(void) const;
+#ifndef U_HIDE_DRAFT_API
+ /**
+ * Returns whether this locale's script is written right-to-left.
+ * If there is no script subtag, then the likely script is used, see uloc_addLikelySubtags().
+ * If no likely script is known, then FALSE is returned.
+ *
+ * A script is right-to-left according to the CLDR script metadata
+ * which corresponds to whether the script's letters have Bidi_Class=R or AL.
+ *
+ * Returns TRUE for "ar" and "en-Hebr", FALSE for "zh" and "fa-Cyrl".
+ *
+ * @return TRUE if the locale's script is written right-to-left
+ * @draft ICU 54
+ */
+ UBool isRightToLeft() const;
+#endif /* U_HIDE_DRAFT_API */
+
/**
* Fills in "dispLang" with the name of this locale's language in a format suitable for
* user display in the default locale. For example, if the locale's language code is
* dispScript to "Latin".
* @param dispScript Receives the scripts's display name.
* @return A reference to "dispScript".
- * @draft ICU 2.8
+ * @stable ICU 2.8
*/
UnicodeString& getDisplayScript( UnicodeString& dispScript) const;
* "".
* @param dispScript Receives the scripts's display name.
* @return A reference to "dispScript".
- * @draft ICU 2.8
+ * @stable ICU 2.8
*/
UnicodeString& getDisplayScript( const Locale& displayLocale,
UnicodeString& dispScript) const;
* Fills in "dispCountry" with the name of this locale's country in a format suitable
* for user display in the locale specified by "displayLocale". For example, if the locale's
* country code is "US" and displayLocale's language code is "fr", this function would set
- * dispCountry to "Etats-Unis".
+ * dispCountry to "États-Unis".
* @param displayLocale Specifies the locale to be used to display the name. In other
* words, if the locale's country code is "US", passing
- * Locale::getFrench() for displayLocale would result in "États-Unis", while
+ * Locale::getFrench() for displayLocale would result in "États-Unis", while
* passing Locale::getGerman() for displayLocale would result in
* "Vereinigte Staaten".
* @param dispCountry Receives the country's display name.
* in the locale specfied by "displayLocale". This function uses getDisplayLanguage(),
* getDisplayCountry(), and getDisplayVariant() to do its work, and outputs the display
* name in the format "language (country[,variant])". For example, if displayLocale is
- * fr_FR, then en_US's display name would be "Anglais (États-Unis)", and no_NO_NY's
- * display name would be "norvégien (Norvège,NY)".
+ * fr_FR, then en_US's display name would be "Anglais (États-Unis)", and no_NO_NY's
+ * display name would be "norvégien (Norvège,NY)".
* @param displayLocale Specifies the locale to be used to display the name.
* @param name Receives the locale's display name.
* @return A reference to "name".
static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
/**
- * Gets a list of all available 2-letter country codes defined in ISO 639. This is a
+ * Gets a list of all available 2-letter country codes defined in ISO 3166. This is a
* pointer to an array of pointers to arrays of char. All of these pointers are
* owned by ICU-- do not delete them, and do not write through them. The array is
* terminated with a null pointer.
virtual UClassID getDynamicClassID() const;
protected: /* only protected for testing purposes. DO NOT USE. */
+#ifndef U_HIDE_INTERNAL_API
/**
* Set this from a single POSIX style locale string.
* @internal
*/
void setFromPOSIXID(const char *posixID);
+#endif /* U_HIDE_INTERNAL_API */
private:
/**
* Was deprecated - used in implementation - moved internal
*
* @param cLocaleID The new locale name.
+ * @param canonicalize whether to call uloc_canonicalize on cLocaleID
*/
Locale& init(const char* cLocaleID, UBool canonicalize);
char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
// name without keywords
char* baseName;
- char baseNameBuffer[ULOC_FULLNAME_CAPACITY];
+ void initBaseName(UErrorCode& status);
UBool fIsBogus;
* A friend to allow the default locale to be set by either the C or C++ API.
* @internal
*/
- friend void locale_set_default_internal(const char *);
+ friend Locale *locale_set_default_internal(const char *, UErrorCode& status);
+
+ /**
+ * @internal
+ */
+ friend void U_CALLCONV locale_available_init();
};
inline UBool
inline const char *
Locale::getVariant() const
{
- return &fullName[variantBegin];
+ return &baseName[variantBegin];
}
inline const char *
U_NAMESPACE_END
#endif
-