ICU 55.1  55.1
locid.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 *
4 * Copyright (C) 1996-2015, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 ******************************************************************************
8 *
9 * File locid.h
10 *
11 * Created by: Helena Shih
12 *
13 * Modification History:
14 *
15 * Date Name Description
16 * 02/11/97 aliu Changed gLocPath to fgLocPath and added methods to
17 * get and set it.
18 * 04/02/97 aliu Made operator!= inline; fixed return value of getName().
19 * 04/15/97 aliu Cleanup for AIX/Win32.
20 * 04/24/97 aliu Numerous changes per code review.
21 * 08/18/98 stephen Added tokenizeString(),changed getDisplayName()
22 * 09/08/98 stephen Moved definition of kEmptyString for Mac Port
23 * 11/09/99 weiv Added const char * getName() const;
24 * 04/12/00 srl removing unicodestring api's and cached hash code
25 * 08/10/01 grhoten Change the static Locales to accessor functions
26 ******************************************************************************
27 */
28 
29 #ifndef LOCID_H
30 #define LOCID_H
31 
32 #include "unicode/utypes.h"
33 #include "unicode/uobject.h"
34 #include "unicode/unistr.h"
35 #include "unicode/putil.h"
36 #include "unicode/uloc.h"
37 #include "unicode/strenum.h"
38 
45 
46 // Forward Declarations
185 class U_COMMON_API Locale : public UObject {
186 public:
188  static const Locale &U_EXPORT2 getRoot(void);
190  static const Locale &U_EXPORT2 getEnglish(void);
192  static const Locale &U_EXPORT2 getFrench(void);
194  static const Locale &U_EXPORT2 getGerman(void);
196  static const Locale &U_EXPORT2 getItalian(void);
198  static const Locale &U_EXPORT2 getJapanese(void);
200  static const Locale &U_EXPORT2 getKorean(void);
202  static const Locale &U_EXPORT2 getChinese(void);
204  static const Locale &U_EXPORT2 getSimplifiedChinese(void);
206  static const Locale &U_EXPORT2 getTraditionalChinese(void);
207 
209  static const Locale &U_EXPORT2 getFrance(void);
211  static const Locale &U_EXPORT2 getGermany(void);
213  static const Locale &U_EXPORT2 getItaly(void);
215  static const Locale &U_EXPORT2 getJapan(void);
217  static const Locale &U_EXPORT2 getKorea(void);
219  static const Locale &U_EXPORT2 getChina(void);
221  static const Locale &U_EXPORT2 getPRC(void);
223  static const Locale &U_EXPORT2 getTaiwan(void);
225  static const Locale &U_EXPORT2 getUK(void);
227  static const Locale &U_EXPORT2 getUS(void);
229  static const Locale &U_EXPORT2 getCanada(void);
231  static const Locale &U_EXPORT2 getCanadaFrench(void);
232 
233 
242 
267  Locale( const char * language,
268  const char * country = 0,
269  const char * variant = 0,
270  const char * keywordsAndValues = 0);
271 
278  Locale(const Locale& other);
279 
280 
285  virtual ~Locale() ;
286 
294  Locale& operator=(const Locale& other);
295 
303  UBool operator==(const Locale& other) const;
304 
313  UBool operator!=(const Locale& other) const;
314 
326  Locale *clone() const;
327 
328 #ifndef U_HIDE_SYSTEM_API
329 
344  static const Locale& U_EXPORT2 getDefault(void);
345 
358  static void U_EXPORT2 setDefault(const Locale& newLocale,
359  UErrorCode& success);
360 #endif /* U_HIDE_SYSTEM_API */
361 
371  static Locale U_EXPORT2 createFromName(const char *name);
372 
381  static Locale U_EXPORT2 createCanonical(const char* name);
382 
388  inline const char * getLanguage( ) const;
389 
397  inline const char * getScript( ) const;
398 
404  inline const char * getCountry( ) const;
405 
411  inline const char * getVariant( ) const;
412 
421  inline const char * getName() const;
422 
430  const char * getBaseName() const;
431 
432 
442 
454  int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
455 
470  void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
471 
478  const char * getISO3Language() const;
479 
485  const char * getISO3Country() const;
486 
494  uint32_t getLCID(void) const;
495 
496 #ifndef U_HIDE_DRAFT_API
497 
511 #endif /* U_HIDE_DRAFT_API */
512 
523 
537  UnicodeString& getDisplayLanguage( const Locale& displayLocale,
538  UnicodeString& dispLang) const;
539 
550 
565  UnicodeString& getDisplayScript( const Locale& displayLocale,
566  UnicodeString& dispScript) const;
567 
578 
593  UnicodeString& getDisplayCountry( const Locale& displayLocale,
594  UnicodeString& dispCountry) const;
595 
604 
613  UnicodeString& getDisplayVariant( const Locale& displayLocale,
614  UnicodeString& dispVar) const;
615 
628 
641  UnicodeString& getDisplayName( const Locale& displayLocale,
642  UnicodeString& name) const;
643 
648  int32_t hashCode(void) const;
649 
658  void setToBogus();
659 
665  UBool isBogus(void) const;
666 
675  static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
676 
685  static const char* const* U_EXPORT2 getISOCountries();
686 
695  static const char* const* U_EXPORT2 getISOLanguages();
696 
702  static UClassID U_EXPORT2 getStaticClassID();
703 
709  virtual UClassID getDynamicClassID() const;
710 
711 protected: /* only protected for testing purposes. DO NOT USE. */
712 #ifndef U_HIDE_INTERNAL_API
713 
717  void setFromPOSIXID(const char *posixID);
718 #endif /* U_HIDE_INTERNAL_API */
719 
720 private:
728  Locale& init(const char* cLocaleID, UBool canonicalize);
729 
730  /*
731  * Internal constructor to allow construction of a locale object with
732  * NO side effects. (Default constructor tries to get
733  * the default locale.)
734  */
735  enum ELocaleType {
736  eBOGUS
737  };
738  Locale(ELocaleType);
739 
743  static Locale *getLocaleCache(void);
744 
745  char language[ULOC_LANG_CAPACITY];
746  char script[ULOC_SCRIPT_CAPACITY];
747  char country[ULOC_COUNTRY_CAPACITY];
748  int32_t variantBegin;
749  char* fullName;
750  char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
751  // name without keywords
752  char* baseName;
753  void initBaseName(UErrorCode& status);
754 
755  UBool fIsBogus;
756 
757  static const Locale &getLocale(int locid);
758 
763  friend Locale *locale_set_default_internal(const char *, UErrorCode& status);
764 
769 };
770 
771 inline UBool
772 Locale::operator!=(const Locale& other) const
773 {
774  return !operator==(other);
775 }
776 
777 inline const char *
778 Locale::getCountry() const
779 {
780  return country;
781 }
782 
783 inline const char *
784 Locale::getLanguage() const
785 {
786  return language;
787 }
788 
789 inline const char *
790 Locale::getScript() const
791 {
792  return script;
793 }
794 
795 inline const char *
796 Locale::getVariant() const
797 {
798  return &baseName[variantBegin];
799 }
800 
801 inline const char *
802 Locale::getName() const
803 {
804  return fullName;
805 }
806 
807 inline UBool
808 Locale::isBogus(void) const {
809  return fIsBogus;
810 }
811 
813 
814 #endif
icu::Locale::setDefault
static void setDefault(const Locale &newLocale, UErrorCode &success)
Sets the default.
icu::Locale::getUS
static const Locale & getUS(void)
Useful constant for this country/region.
icu::Locale::getJapan
static const Locale & getJapan(void)
Useful constant for this country/region.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::Locale::getTraditionalChinese
static const Locale & getTraditionalChinese(void)
Useful constant for this language.
icu::Locale::getLCID
uint32_t getLCID(void) const
Returns the Windows LCID value corresponding to this locale.
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
icu::Locale::getGerman
static const Locale & getGerman(void)
Useful constant for this language.
ULOC_SCRIPT_CAPACITY
#define ULOC_SCRIPT_CAPACITY
Useful constant for the maximum size of the script part of a locale ID (including the terminating NUL...
Definition: uloc.h:269
U_CALLCONV
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition: platform.h:756
icu::Locale::operator==
UBool operator==(const Locale &other) const
Checks if two locale keys are the same.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::Locale::setKeywordValue
void setKeywordValue(const char *keywordName, const char *keywordValue, UErrorCode &status)
Sets or removes the value for a keyword.
icu::Locale::getChinese
static const Locale & getChinese(void)
Useful constant for this language.
U_COMMON_API
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition: utypes.h:357
icu::Locale::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
icu::Locale::getGermany
static const Locale & getGermany(void)
Useful constant for this country/region.
icu::Locale::Locale
Locale(const Locale &other)
Initializes a Locale object from another Locale object.
icu::Locale::createCanonical
static Locale createCanonical(const char *name)
Creates a locale from the given string after canonicalizing the string by calling uloc_canonicalize()...
icu::Locale::getDisplayCountry
UnicodeString & getDisplayCountry(const Locale &displayLocale, UnicodeString &dispCountry) const
Fills in "dispCountry" with the name of this locale's country in a format suitable for user display i...
icu::Locale::setFromPOSIXID
void setFromPOSIXID(const char *posixID)
Set this from a single POSIX style locale string.
icu::Locale::getDisplayLanguage
UnicodeString & getDisplayLanguage(UnicodeString &dispLang) const
Fills in "dispLang" with the name of this locale's language in a format suitable for user display in ...
icu::Locale::getEnglish
static const Locale & getEnglish(void)
Useful constant for this language.
icu::Locale::getCanadaFrench
static const Locale & getCanadaFrench(void)
Useful constant for this country/region.
icu::Locale::getDisplayVariant
UnicodeString & getDisplayVariant(UnicodeString &dispVar) const
Fills in "dispVar" with the name of this locale's variant code in a format suitable for user display ...
icu::Locale::locale_available_init
friend void locale_available_init()
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:246
uloc.h
C API: Locale.
icu::Locale::getDisplayLanguage
UnicodeString & getDisplayLanguage(const Locale &displayLocale, UnicodeString &dispLang) const
Fills in "dispLang" with the name of this locale's language in a format suitable for user display in ...
icu::Locale::createFromName
static Locale createFromName(const char *name)
Creates a locale which has had minimal canonicalization as per uloc_getName().
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:221
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition: utypes.h:476
putil.h
C API: Platform Utilities.
icu::StringEnumeration
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:55
icu::Locale::getBaseName
const char * getBaseName() const
Returns the programmatic name of the entire locale as getName() would return, but without keywords.
icu::Locale::getSimplifiedChinese
static const Locale & getSimplifiedChinese(void)
Useful constant for this language.
icu::Locale::Locale
Locale(const char *language, const char *country=0, const char *variant=0, const char *keywordsAndValues=0)
Construct a locale from language, country, variant.
icu::Locale::isRightToLeft
UBool isRightToLeft() const
Returns whether this locale's script is written right-to-left.
icu::Locale::getTaiwan
static const Locale & getTaiwan(void)
Useful constant for this country/region.
icu::Locale::hashCode
int32_t hashCode(void) const
Generates a hash code for the locale.
icu::Locale::getPRC
static const Locale & getPRC(void)
Useful constant for this country/region.
icu::Locale::getKorea
static const Locale & getKorea(void)
Useful constant for this country/region.
icu::Locale::clone
Locale * clone() const
Clone this object.
icu::operator!=
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
icu::Locale::getDisplayName
UnicodeString & getDisplayName(const Locale &displayLocale, UnicodeString &name) const
Fills in "name" with the name of this locale in a format suitable for user display in the locale spec...
icu::Locale::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
icu::Locale::getFrance
static const Locale & getFrance(void)
Useful constant for this country/region.
icu::Locale::getDisplayScript
UnicodeString & getDisplayScript(UnicodeString &dispScript) const
Fills in "dispScript" with the name of this locale's script in a format suitable for user display in ...
icu::Locale::Locale
Locale()
Construct a default locale object, a Locale for the default locale ID.
icu::Locale::setToBogus
void setToBogus()
Sets the locale to bogus A bogus locale represents a non-existing locale associated with services tha...
icu::Locale::getDefault
static const Locale & getDefault(void)
Common methods of getting the current default Locale.
ULOC_FULLNAME_CAPACITY
#define ULOC_FULLNAME_CAPACITY
Useful constant for the maximum size of the whole locale ID (including the terminating NULL and all k...
Definition: uloc.h:262
icu::Locale::locale_set_default_internal
friend Locale * locale_set_default_internal(const char *, UErrorCode &status)
A friend to allow the default locale to be set by either the C or C++ API.
icu::Locale::getRoot
static const Locale & getRoot(void)
Useful constant for the Root locale.
icu::locale_available_init
void locale_available_init()
icu::Locale::getDisplayCountry
UnicodeString & getDisplayCountry(UnicodeString &dispCountry) const
Fills in "dispCountry" with the name of this locale's country in a format suitable for user display i...
icu::Locale::getAvailableLocales
static const Locale * getAvailableLocales(int32_t &count)
Returns a list of all installed locales.
icu::Locale::getChina
static const Locale & getChina(void)
Useful constant for this country/region.
icu::Locale::getDisplayName
UnicodeString & getDisplayName(UnicodeString &name) const
Fills in "name" with the name of this locale in a format suitable for user display in the default loc...
strenum.h
C++ API: String Enumeration.
icu::Locale::getUK
static const Locale & getUK(void)
Useful constant for this country/region.
icu::Locale::operator=
Locale & operator=(const Locale &other)
Replaces the entire contents of *this with the specified value.
icu::Locale::~Locale
virtual ~Locale()
Destructor.
icu::Locale::createKeywords
StringEnumeration * createKeywords(UErrorCode &status) const
Gets the list of keywords for the specified locale.
icu::Locale::getISO3Country
const char * getISO3Country() const
Fills in "name" with the locale's three-letter ISO-3166 country code.
icu::Locale::getJapanese
static const Locale & getJapanese(void)
Useful constant for this language.
icu::Locale::getCanada
static const Locale & getCanada(void)
Useful constant for this country/region.
ULOC_LANG_CAPACITY
#define ULOC_LANG_CAPACITY
Useful constant for the maximum size of the language part of a locale ID.
Definition: uloc.h:249
uobject.h
C++ API: Common ICU base class UObject.
icu::Locale::getDisplayScript
UnicodeString & getDisplayScript(const Locale &displayLocale, UnicodeString &dispScript) const
Fills in "dispScript" with the name of this locale's country in a format suitable for user display in...
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
icu::Locale::getDisplayVariant
UnicodeString & getDisplayVariant(const Locale &displayLocale, UnicodeString &dispVar) const
Fills in "dispVar" with the name of this locale's variant code in a format suitable for user display ...
icu::Locale::getISO3Language
const char * getISO3Language() const
returns the locale's three-letter language code, as specified in ISO draft standard ISO-639-2.
icu::Locale::getKorean
static const Locale & getKorean(void)
Useful constant for this language.
icu::Locale::getItalian
static const Locale & getItalian(void)
Useful constant for this language.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185
icu::Locale::getKeywordValue
int32_t getKeywordValue(const char *keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const
Gets the value for a keyword.
icu::Locale::getISOCountries
static const char *const * getISOCountries()
Gets a list of all available 2-letter country codes defined in ISO 3166.
icu::Locale::getFrench
static const Locale & getFrench(void)
Useful constant for this language.
unistr.h
C++ API: Unicode String.
icu::Locale::getISOLanguages
static const char *const * getISOLanguages()
Gets a list of all available language codes defined in ISO 639.
ULOC_COUNTRY_CAPACITY
#define ULOC_COUNTRY_CAPACITY
Useful constant for the maximum size of the country part of a locale ID (including the terminating NU...
Definition: uloc.h:256
icu::Locale::getItaly
static const Locale & getItaly(void)
Useful constant for this country/region.