ICU 60.2  60.2
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
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 *
780 {
781  return country;
782 }
783 
784 inline const char *
786 {
787  return language;
788 }
789 
790 inline const char *
792 {
793  return script;
794 }
795 
796 inline const char *
798 {
799  return &baseName[variantBegin];
800 }
801 
802 inline const char *
804 {
805  return fullName;
806 }
807 
808 inline UBool
809 Locale::isBogus(void) const {
810  return fIsBogus;
811 }
812 
814 
815 #endif
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
#define ULOC_LANG_CAPACITY
Useful constant for the maximum size of the language part of a locale ID.
Definition: uloc.h:251
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
const char * getLanguage() const
Returns the locale's ISO-639 language code.
Definition: locid.h:785
#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 U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition: platform.h:848
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:93
#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
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:57
#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
const char * getCountry() const
Returns the locale's ISO-3166 country code.
Definition: locid.h:779
UBool operator!=(const Locale &other) const
Checks if two locale keys are not the same.
Definition: locid.h:773
void locale_available_init()
const char * getScript() const
Returns the locale's ISO-15924 abbreviation script code.
Definition: locid.h:791
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
const char * getVariant() const
Returns the locale's variant code.
Definition: locid.h:797
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
const char * getName() const
Returns the programmatic name of the entire locale, with the language, country and variant separated ...
Definition: locid.h:803
C API: Platform Utilities.
C++ API: Common ICU base class UObject.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
Basic definitions for ICU, for both C and C++ APIs.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
Definition: utypes.h:359
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:286
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UBool isBogus(void) const
Gets the bogus state.
Definition: locid.h:809
int8_t UBool
The ICU boolean type.
Definition: umachine.h:236
C API: Locale.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:188