ICU 60.2 60.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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
44 U_NAMESPACE_BEGIN
45
46 // Forward Declarations
47 void U_CALLCONV locale_available_init();
49 class StringEnumeration;
50 class UnicodeString;
51
188 class U_COMMON_API Locale : public UObject {
189 public:
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);
207 static const Locale &U_EXPORT2 getSimplifiedChinese(void);
209 static const Locale &U_EXPORT2 getTraditionalChinese(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
244 Locale();
245
270 Locale( const char * language,
271 const char * country = 0,
272 const char * variant = 0,
273 const char * keywordsAndValues = 0);
274
281 Locale(const Locale& other);
282
283
288 virtual ~Locale() ;
289
297 Locale& operator=(const Locale& other);
298
306 UBool operator==(const Locale& other) const;
307
316 UBool operator!=(const Locale& other) const;
317
329 Locale *clone() const;
330
331 #ifndef U_HIDE_SYSTEM_API
332
347 static const Locale& U_EXPORT2 getDefault(void);
348
361 static void U_EXPORT2 setDefault(const Locale& newLocale,
362 UErrorCode& success);
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
444 StringEnumeration * createKeywords(UErrorCode &status) const;
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
512 UBool isRightToLeft() const;
513
523 UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const;
524
538 UnicodeString& getDisplayLanguage( const Locale& displayLocale,
539 UnicodeString& dispLang) const;
540
550 UnicodeString& getDisplayScript( UnicodeString& dispScript) const;
551
566 UnicodeString& getDisplayScript( const Locale& displayLocale,
567 UnicodeString& dispScript) const;
568
578 UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const;
579
594 UnicodeString& getDisplayCountry( const Locale& displayLocale,
595 UnicodeString& dispCountry) const;
596
604 UnicodeString& getDisplayVariant( UnicodeString& dispVar) const;
605
614 UnicodeString& getDisplayVariant( const Locale& displayLocale,
615 UnicodeString& dispVar) const;
616
628 UnicodeString& getDisplayName( UnicodeString& name) const;
629
642 UnicodeString& getDisplayName( const Locale& displayLocale,
643 UnicodeString& name) const;
644
649 int32_t hashCode(void) const;
650
659 void setToBogus();
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
703 static UClassID U_EXPORT2 getStaticClassID();
704
710 virtual UClassID getDynamicClassID() const;
711
712 protected: /* only protected for testing purposes. DO NOT USE. */
713 #ifndef U_HIDE_INTERNAL_API
714
718 void setFromPOSIXID(const char *posixID);
719 #endif /* U_HIDE_INTERNAL_API */
720
721 private:
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
764 friend Locale *locale_set_default_internal(const char *, UErrorCode& status);
765
769 friend void U_CALLCONV locale_available_init();
770 };
771
772 inline UBool
773 Locale::operator!=(const Locale& other) const
774 {
775 return !operator==(other);
776 }
777
778 inline const char *
779 Locale::getCountry() const
780 {
781 return country;
782 }
783
784 inline const char *
785 Locale::getLanguage() const
786 {
787 return language;
788 }
789
790 inline const char *
791 Locale::getScript() const
792 {
793 return script;
794 }
795
796 inline const char *
797 Locale::getVariant() const
798 {
799 return &baseName[variantBegin];
800 }
801
802 inline const char *
803 Locale::getName() const
804 {
805 return fullName;
806 }
807
808 inline UBool
809 Locale::isBogus(void) const {
810 return fIsBogus;
811 }
812
813 U_NAMESPACE_END
814
815 #endif
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
ULOC_LANG_CAPACITY
#define ULOC_LANG_CAPACITY
Useful constant for the maximum size of the language part of a locale ID.
Definition: uloc.h:251
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::Locale::getLanguage
const char * getLanguage() const
Returns the locale&#39;s ISO-639 language code.
Definition: locid.h:785
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:258
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:848
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:93
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:264
icu::StringEnumeration
Base class for &#39;pure&#39; C++ implementations of uenum api.
Definition: strenum.h:57
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:271
icu::Locale::getCountry
const char * getCountry() const
Returns the locale&#39;s ISO-3166 country code.
Definition: locid.h:779
icu::Locale::operator!=
UBool operator!=(const Locale &other) const
Checks if two locale keys are not the same.
Definition: locid.h:773
icu::locale_available_init
void locale_available_init()
icu::Locale::getScript
const char * getScript() const
Returns the locale&#39;s ISO-15924 abbreviation script code.
Definition: locid.h:791
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
icu::Locale::getVariant
const char * getVariant() const
Returns the locale&#39;s variant code.
Definition: locid.h:797
icu::operator!=
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
icu::Locale::getName
const char * getName() const
Returns the programmatic name of the entire locale, with the language, country and variant separated ...
Definition: locid.h:803
putil.h
C API: Platform Utilities.
uobject.h
C++ API: Common ICU base class UObject.
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
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:359
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:286
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
icu::Locale::isBogus
UBool isBogus(void) const
Gets the bogus state.
Definition: locid.h:809
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:236
uloc.h
C API: Locale.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:188