ICU 62.1 62.1
locid.h
Go to the documentation of this file.
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4******************************************************************************
5*
6* Copyright (C) 1996-2015, International Business Machines
7* Corporation and others. All Rights Reserved.
8*
9******************************************************************************
10*
11* File locid.h
12*
13* Created by: Helena Shih
14*
15* Modification History:
16*
17* Date Name Description
18* 02/11/97 aliu Changed gLocPath to fgLocPath and added methods to
19* get and set it.
20* 04/02/97 aliu Made operator!= inline; fixed return value of getName().
21* 04/15/97 aliu Cleanup for AIX/Win32.
22* 04/24/97 aliu Numerous changes per code review.
23* 08/18/98 stephen Added tokenizeString(),changed getDisplayName()
24* 09/08/98 stephen Moved definition of kEmptyString for Mac Port
25* 11/09/99 weiv Added const char * getName() const;
26* 04/12/00 srl removing unicodestring api's and cached hash code
27* 08/10/01 grhoten Change the static Locales to accessor functions
28******************************************************************************
29*/
30
31#ifndef LOCID_H
32#define LOCID_H
33
34#include "unicode/utypes.h"
35#include "unicode/uobject.h"
36#include "unicode/putil.h"
37#include "unicode/uloc.h"
38
45
46// Forward Declarations
50class UnicodeString;
51
189public:
191 static const Locale &U_EXPORT2 getRoot(void);
193 static const Locale &U_EXPORT2 getEnglish(void);
195 static const Locale &U_EXPORT2 getFrench(void);
197 static const Locale &U_EXPORT2 getGerman(void);
199 static const Locale &U_EXPORT2 getItalian(void);
201 static const Locale &U_EXPORT2 getJapanese(void);
203 static const Locale &U_EXPORT2 getKorean(void);
205 static const Locale &U_EXPORT2 getChinese(void);
210
212 static const Locale &U_EXPORT2 getFrance(void);
214 static const Locale &U_EXPORT2 getGermany(void);
216 static const Locale &U_EXPORT2 getItaly(void);
218 static const Locale &U_EXPORT2 getJapan(void);
220 static const Locale &U_EXPORT2 getKorea(void);
222 static const Locale &U_EXPORT2 getChina(void);
224 static const Locale &U_EXPORT2 getPRC(void);
226 static const Locale &U_EXPORT2 getTaiwan(void);
228 static const Locale &U_EXPORT2 getUK(void);
230 static const Locale &U_EXPORT2 getUS(void);
232 static const Locale &U_EXPORT2 getCanada(void);
234 static const Locale &U_EXPORT2 getCanadaFrench(void);
235
236
245
270 Locale( const char * language,
271 const char * country = 0,
272 const char * variant = 0,
273 const char * keywordsAndValues = 0);
274
282
283
288 virtual ~Locale() ;
289
298
307
316 UBool operator!=(const Locale& other) const;
317
329 Locale *clone() const;
330
331#ifndef U_HIDE_SYSTEM_API
347 static const Locale& U_EXPORT2 getDefault(void);
348
363#endif /* U_HIDE_SYSTEM_API */
364
374 static Locale U_EXPORT2 createFromName(const char *name);
375
384 static Locale U_EXPORT2 createCanonical(const char* name);
385
391 inline const char * getLanguage( ) const;
392
400 inline const char * getScript( ) const;
401
407 inline const char * getCountry( ) const;
408
414 inline const char * getVariant( ) const;
415
424 inline const char * getName() const;
425
433 const char * getBaseName() const;
434
435
445
457 int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
458
473 void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
474
481 const char * getISO3Language() const;
482
488 const char * getISO3Country() const;
489
497 uint32_t getLCID(void) const;
498
513
524
539 UnicodeString& dispLang) const;
540
551
568
579
596
605
615 UnicodeString& dispVar) const;
616
629
643 UnicodeString& name) const;
644
649 int32_t hashCode(void) const;
650
660
666 UBool isBogus(void) const;
667
676 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
677
686 static const char* const* U_EXPORT2 getISOCountries();
687
696 static const char* const* U_EXPORT2 getISOLanguages();
697
704
711
712protected: /* only protected for testing purposes. DO NOT USE. */
713#ifndef U_HIDE_INTERNAL_API
718 void setFromPOSIXID(const char *posixID);
719#endif /* U_HIDE_INTERNAL_API */
720
721private:
729 Locale& init(const char* cLocaleID, UBool canonicalize);
730
731 /*
732 * Internal constructor to allow construction of a locale object with
733 * NO side effects. (Default constructor tries to get
734 * the default locale.)
735 */
736 enum ELocaleType {
737 eBOGUS
738 };
739 Locale(ELocaleType);
740
744 static Locale *getLocaleCache(void);
745
746 char language[ULOC_LANG_CAPACITY];
747 char script[ULOC_SCRIPT_CAPACITY];
748 char country[ULOC_COUNTRY_CAPACITY];
749 int32_t variantBegin;
750 char* fullName;
751 char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
752 // name without keywords
753 char* baseName;
754 void initBaseName(UErrorCode& status);
755
756 UBool fIsBogus;
757
758 static const Locale &getLocale(int locid);
759
765
770};
771
772inline UBool
773Locale::operator!=(const Locale& other) const
774{
775 return !operator==(other);
776}
777
778inline const char *
779Locale::getCountry() const
780{
781 return country;
782}
783
784inline const char *
785Locale::getLanguage() const
786{
787 return language;
788}
789
790inline const char *
791Locale::getScript() const
792{
793 return script;
794}
795
796inline const char *
797Locale::getVariant() const
798{
799 return &baseName[variantBegin];
800}
801
802inline const char *
803Locale::getName() const
804{
805 return fullName;
806}
807
808inline UBool
809Locale::isBogus(void) const {
810 return fIsBogus;
811}
812
814
815#endif
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:188
static const Locale & getGermany(void)
Useful constant for this country/region.
static const Locale & getTraditionalChinese(void)
Useful constant for this language.
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
static const char *const * getISOLanguages()
Gets a list of all available language codes defined in ISO 639.
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.
static Locale createFromName(const char *name)
Creates a locale which has had minimal canonicalization as per uloc_getName().
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 ...
static const Locale & getCanadaFrench(void)
Useful constant for this country/region.
static const Locale & getJapanese(void)
Useful constant for this language.
friend void locale_available_init()
static Locale createCanonical(const char *name)
Creates a locale from the given string after canonicalizing the string by calling uloc_canonicalize()...
static const Locale & getUS(void)
Useful constant for this country/region.
static const Locale & getGerman(void)
Useful constant for this language.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
Locale()
Construct a default locale object, a Locale for the default locale ID.
static const Locale & getItaly(void)
Useful constant for this country/region.
static const Locale & getChinese(void)
Useful constant for this language.
void setKeywordValue(const char *keywordName, const char *keywordValue, UErrorCode &status)
Sets or removes the value for a keyword.
uint32_t getLCID(void) const
Returns the Windows LCID value corresponding to this locale.
const char * getBaseName() const
Returns the programmatic name of the entire locale as getName() would return, but without keywords.
Locale & operator=(const Locale &other)
Replaces the entire contents of *this with the specified value.
Locale(const char *language, const char *country=0, const char *variant=0, const char *keywordsAndValues=0)
Construct a locale from language, country, variant.
static const Locale & getTaiwan(void)
Useful constant for this country/region.
static const Locale & getKorea(void)
Useful constant for this country/region.
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...
virtual ~Locale()
Destructor.
const char * getISO3Language() const
returns the locale's three-letter language code, as specified in ISO draft standard ISO-639-2.
static const Locale & getRoot(void)
Useful constant for the Root locale.
int32_t getKeywordValue(const char *keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const
Gets the value for a keyword.
static void setDefault(const Locale &newLocale, UErrorCode &success)
Sets the default.
static const Locale & getUK(void)
Useful constant for this country/region.
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 ...
StringEnumeration * createKeywords(UErrorCode &status) const
Gets the list of keywords for the specified locale.
static const Locale & getItalian(void)
Useful constant for this language.
static const Locale & getCanada(void)
Useful constant for this country/region.
static const Locale * getAvailableLocales(int32_t &count)
Returns a list of all installed locales.
static const Locale & getPRC(void)
Useful constant for this country/region.
static const Locale & getKorean(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...
UnicodeString & getDisplayVariant(UnicodeString &dispVar) const
Fills in "dispVar" with the name of this locale's variant code in a format suitable for user display ...
UBool operator==(const Locale &other) const
Checks if two locale keys are the same.
static const Locale & getFrance(void)
Useful constant for this country/region.
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...
const char * getISO3Country() const
Fills in "name" with the locale's three-letter ISO-3166 country code.
static const Locale & getFrench(void)
Useful constant for this language.
UnicodeString & getDisplayCountry(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 & getEnglish(void)
Useful constant for this language.
int32_t hashCode(void) const
Generates a hash code for the locale.
Locale(const Locale &other)
Initializes a Locale object from another Locale object.
static const Locale & getSimplifiedChinese(void)
Useful constant for this language.
static const char *const * getISOCountries()
Gets a list of all available 2-letter country codes defined in ISO 3166.
static const Locale & getChina(void)
Useful constant for this country/region.
UnicodeString & getDisplayScript(UnicodeString &dispScript) const
Fills in "dispScript" with the name of this locale's script in a format suitable for user display in ...
UBool isRightToLeft() const
Returns whether this locale's script is written right-to-left.
UnicodeString & getDisplayLanguage(UnicodeString &dispLang) const
Fills in "dispLang" with the name of this locale's language in a format suitable for user display in ...
void setFromPOSIXID(const char *posixID)
Set this from a single POSIX style locale string.
static const Locale & getJapan(void)
Useful constant for this country/region.
static const Locale & getDefault(void)
Common methods of getting the current default Locale.
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...
Locale * clone() const
Clone this object.
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...
Base class for 'pure' C++ implementations of uenum api.
Definition strenum.h:57
UObject is the common ICU "boilerplate" class.
Definition uobject.h:223
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:287
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
void locale_available_init()
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition platform.h:835
C API: Platform Utilities.
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:271
#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:258
#define ULOC_LANG_CAPACITY
Useful constant for the maximum size of the language part of a locale ID.
Definition uloc.h:251
#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:264
int8_t UBool
The ICU boolean type.
Definition umachine.h:236
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:93
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:396
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition utypes.h:359
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:138
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:137