ICU 50.2 50.2
locid.h
Go to the documentation of this file.
1/*
2******************************************************************************
3*
4* Copyright (C) 1996-2012, 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
43
45
183public:
185 static const Locale &U_EXPORT2 getRoot(void);
187 static const Locale &U_EXPORT2 getEnglish(void);
189 static const Locale &U_EXPORT2 getFrench(void);
191 static const Locale &U_EXPORT2 getGerman(void);
193 static const Locale &U_EXPORT2 getItalian(void);
195 static const Locale &U_EXPORT2 getJapanese(void);
197 static const Locale &U_EXPORT2 getKorean(void);
199 static const Locale &U_EXPORT2 getChinese(void);
201 static const Locale &U_EXPORT2 getSimplifiedChinese(void);
203 static const Locale &U_EXPORT2 getTraditionalChinese(void);
204
206 static const Locale &U_EXPORT2 getFrance(void);
208 static const Locale &U_EXPORT2 getGermany(void);
210 static const Locale &U_EXPORT2 getItaly(void);
212 static const Locale &U_EXPORT2 getJapan(void);
214 static const Locale &U_EXPORT2 getKorea(void);
216 static const Locale &U_EXPORT2 getChina(void);
218 static const Locale &U_EXPORT2 getPRC(void);
220 static const Locale &U_EXPORT2 getTaiwan(void);
222 static const Locale &U_EXPORT2 getUK(void);
224 static const Locale &U_EXPORT2 getUS(void);
226 static const Locale &U_EXPORT2 getCanada(void);
228 static const Locale &U_EXPORT2 getCanadaFrench(void);
229
230
239
264 Locale( const char * language,
265 const char * country = 0,
266 const char * variant = 0,
267 const char * keywordsAndValues = 0);
268
275 Locale(const Locale& other);
276
277
282 virtual ~Locale() ;
283
291 Locale& operator=(const Locale& other);
292
300 UBool operator==(const Locale& other) const;
301
310 UBool operator!=(const Locale& other) const;
311
323 Locale *clone() const;
324
325#ifndef U_HIDE_SYSTEM_API
341 static const Locale& U_EXPORT2 getDefault(void);
342
355 static void U_EXPORT2 setDefault(const Locale& newLocale,
356 UErrorCode& success);
357#endif /* U_HIDE_SYSTEM_API */
358
368 static Locale U_EXPORT2 createFromName(const char *name);
369
378 static Locale U_EXPORT2 createCanonical(const char* name);
379
385 inline const char * getLanguage( ) const;
386
394 inline const char * getScript( ) const;
395
401 inline const char * getCountry( ) const;
402
408 inline const char * getVariant( ) const;
409
418 inline const char * getName() const;
419
427 const char * getBaseName() const;
428
429
439
451 int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
452
453#ifndef U_HIDE_DRAFT_API
465 void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
466#endif /* U_HIDE_DRAFT_API */
467
474 const char * getISO3Language() const;
475
481 const char * getISO3Country() const;
482
490 uint32_t getLCID(void) const;
491
502
517 UnicodeString& dispLang) const;
518
529
544 UnicodeString& getDisplayScript( const Locale& displayLocale,
545 UnicodeString& dispScript) const;
546
557
572 UnicodeString& getDisplayCountry( const Locale& displayLocale,
573 UnicodeString& dispCountry) const;
574
583
592 UnicodeString& getDisplayVariant( const Locale& displayLocale,
593 UnicodeString& dispVar) const;
594
607
620 UnicodeString& getDisplayName( const Locale& displayLocale,
621 UnicodeString& name) const;
622
627 int32_t hashCode(void) const;
628
638
644 UBool isBogus(void) const;
645
654 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
655
664 static const char* const* U_EXPORT2 getISOCountries();
665
674 static const char* const* U_EXPORT2 getISOLanguages();
675
681 static UClassID U_EXPORT2 getStaticClassID();
682
689
690protected: /* only protected for testing purposes. DO NOT USE. */
691#ifndef U_HIDE_INTERNAL_API
696 void setFromPOSIXID(const char *posixID);
697#endif /* U_HIDE_INTERNAL_API */
698
699private:
707 Locale& init(const char* cLocaleID, UBool canonicalize);
708
709 /*
710 * Internal constructor to allow construction of a locale object with
711 * NO side effects. (Default constructor tries to get
712 * the default locale.)
713 */
714 enum ELocaleType {
715 eBOGUS
716 };
717 Locale(ELocaleType);
718
722 static Locale *getLocaleCache(void);
723
724 char language[ULOC_LANG_CAPACITY];
725 char script[ULOC_SCRIPT_CAPACITY];
726 char country[ULOC_COUNTRY_CAPACITY];
727 int32_t variantBegin;
728 char* fullName;
729 char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
730 // name without keywords
731 char* baseName;
732 char baseNameBuffer[ULOC_FULLNAME_CAPACITY];
733
734 UBool fIsBogus;
735
736 static const Locale &getLocale(int locid);
737
742 friend Locale *locale_set_default_internal(const char *, UErrorCode& status);
743};
744
745inline UBool
746Locale::operator!=(const Locale& other) const
747{
748 return !operator==(other);
749}
750
751inline const char *
753{
754 return country;
755}
756
757inline const char *
759{
760 return language;
761}
762
763inline const char *
765{
766 return script;
767}
768
769inline const char *
771{
772 getBaseName(); // lazy init
773 return &baseName[variantBegin];
774}
775
776inline const char *
778{
779 return fullName;
780}
781
782inline UBool
783Locale::isBogus(void) const {
784 return fIsBogus;
785}
786
788
789#endif
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:182
const char * getScript() const
Returns the locale's ISO-15924 abbreviation script code.
Definition locid.h:764
const char * getISO3Country() const
Fills in "name" with the locale's three-letter ISO-3166 country code.
UnicodeString & getDisplayCountry(UnicodeString &dispCountry) const
Fills in "dispCountry" with the name of this locale's country in a format suitable for user display i...
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
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.
void setFromPOSIXID(const char *posixID)
Set this from a single POSIX style locale string.
static const Locale & getEnglish(void)
Useful constant for this language.
static const Locale & getJapan(void)
Useful constant for this country/region.
static const Locale & getFrench(void)
Useful constant for this language.
Locale(const char *language, const char *country=0, const char *variant=0, const char *keywordsAndValues=0)
Construct a locale from language, country, variant.
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...
int32_t hashCode(void) const
Generates a hash code for the locale.
static const Locale & getKorean(void)
Useful constant for this language.
const char * getCountry() const
Returns the locale's ISO-3166 country code.
Definition locid.h:752
void setKeywordValue(const char *keywordName, const char *keywordValue, UErrorCode &status)
Sets the value for a keyword.
static const Locale & getJapanese(void)
Useful constant for this language.
void setToBogus()
Sets the locale to bogus A bogus locale represents a non-existing locale associated with services tha...
Locale()
Construct a default locale object, a Locale for the default locale ID.
UnicodeString & getDisplayLanguage(UnicodeString &dispLang) const
Fills in "dispLang" with the name of this locale's language in a format suitable for user display in ...
UBool operator!=(const Locale &other) const
Checks if two locale keys are not the same.
Definition locid.h:746
static const Locale & getFrance(void)
Useful constant for this country/region.
virtual ~Locale()
Destructor.
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...
const char * getVariant() const
Returns the locale's variant code.
Definition locid.h:770
static const Locale & getUK(void)
Useful constant for this country/region.
static const Locale & getChina(void)
Useful constant for this country/region.
static const Locale & getRoot(void)
Useful constant for the Root locale.
static Locale createCanonical(const char *name)
Creates a locale from the given string after canonicalizing the string by calling uloc_canonicalize()...
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...
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 ...
const char * getBaseName() const
Returns the programmatic name of the entire locale as getName would return, but without keywords.
UBool isBogus(void) const
Gets the bogus state.
Definition locid.h:783
static void setDefault(const Locale &newLocale, UErrorCode &success)
Sets the default.
const char * getLanguage() const
Returns the locale's ISO-639 language code.
Definition locid.h:758
static const Locale & getUS(void)
Useful constant for this country/region.
Locale & operator=(const Locale &other)
Replaces the entire contents of *this with the specified value.
static Locale createFromName(const char *name)
Creates a locale which has had minimal canonicalization as per uloc_getName().
static const Locale & getDefault(void)
Common methods of getting the current default Locale.
static const Locale & getCanada(void)
Useful constant for this country/region.
static const Locale & getChinese(void)
Useful constant for this language.
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 ...
static const Locale & getItaly(void)
Useful constant for this country/region.
static const Locale & getKorea(void)
Useful constant for this country/region.
Locale(const Locale &other)
Initializes a Locale object from another Locale object.
static const Locale & getGermany(void)
Useful constant for this country/region.
static const Locale & getCanadaFrench(void)
Useful constant for this country/region.
const char * getISO3Language() const
returns the locale's three-letter language code, as specified in ISO draft standard ISO-639-2.
UnicodeString & getDisplayVariant(UnicodeString &dispVar) const
Fills in "dispVar" with the name of this locale's variant code in a format suitable for user display ...
static const char *const * getISOLanguages()
Gets a list of all available language codes defined in ISO 639.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
static const Locale & getGerman(void)
Useful constant for this language.
UnicodeString & getDisplayScript(UnicodeString &dispScript) const
Fills in "dispScript" with the name of this locale's script in a format suitable for user display in ...
static const Locale & getTraditionalChinese(void)
Useful constant for this language.
static const Locale * getAvailableLocales(int32_t &count)
Returns a list of all installed locales.
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...
static const Locale & getTaiwan(void)
Useful constant for this country/region.
StringEnumeration * createKeywords(UErrorCode &status) const
Gets the list of keywords for the specified locale.
uint32_t getLCID(void) const
Returns the Windows LCID value corresponding to this locale.
UBool operator==(const Locale &other) const
Checks if two locale keys are the same.
static const Locale & getSimplifiedChinese(void)
Useful constant for this language.
Locale * clone() const
Clone this object.
int32_t getKeywordValue(const char *keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const
Gets the value for a keyword.
static const char *const * getISOCountries()
Gets a list of all available 2-letter country codes defined in ISO 3166.
const char * getName() const
Returns the programmatic name of the entire locale, with the language, country and variant separated ...
Definition locid.h:777
static const Locale & getPRC(void)
Useful constant for this country/region.
static const Locale & getItalian(void)
Useful constant for this language.
Base class for 'pure' C++ implementations of uenum api.
Definition strenum.h:55
UObject is the common ICU "boilerplate" class.
Definition uobject.h:229
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:247
C API: Platform Utilities.
C++ API: String Enumeration.
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
C API: Locale.
#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
#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
#define ULOC_LANG_CAPACITY
Useful constant for the maximum size of the language part of a locale ID.
Definition uloc.h:249
#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
int8_t UBool
The ICU boolean type.
Definition umachine.h:200
C++ API: Unicode String.
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:476
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition utypes.h:357
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129