ICU 58.2  58.2
locid.h
Go to the documentation of this file.
1 // Copyright (C) 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/unistr.h"
37 #include "unicode/putil.h"
38 #include "unicode/uloc.h"
39 #include "unicode/strenum.h"
40 
47 
48 // Forward Declarations
187 class U_COMMON_API Locale : public UObject {
188 public:
190  static const Locale &U_EXPORT2 getRoot(void);
192  static const Locale &U_EXPORT2 getEnglish(void);
194  static const Locale &U_EXPORT2 getFrench(void);
196  static const Locale &U_EXPORT2 getGerman(void);
198  static const Locale &U_EXPORT2 getItalian(void);
200  static const Locale &U_EXPORT2 getJapanese(void);
202  static const Locale &U_EXPORT2 getKorean(void);
204  static const Locale &U_EXPORT2 getChinese(void);
206  static const Locale &U_EXPORT2 getSimplifiedChinese(void);
208  static const Locale &U_EXPORT2 getTraditionalChinese(void);
209 
211  static const Locale &U_EXPORT2 getFrance(void);
213  static const Locale &U_EXPORT2 getGermany(void);
215  static const Locale &U_EXPORT2 getItaly(void);
217  static const Locale &U_EXPORT2 getJapan(void);
219  static const Locale &U_EXPORT2 getKorea(void);
221  static const Locale &U_EXPORT2 getChina(void);
223  static const Locale &U_EXPORT2 getPRC(void);
225  static const Locale &U_EXPORT2 getTaiwan(void);
227  static const Locale &U_EXPORT2 getUK(void);
229  static const Locale &U_EXPORT2 getUS(void);
231  static const Locale &U_EXPORT2 getCanada(void);
233  static const Locale &U_EXPORT2 getCanadaFrench(void);
234 
235 
243  Locale();
244 
269  Locale( const char * language,
270  const char * country = 0,
271  const char * variant = 0,
272  const char * keywordsAndValues = 0);
273 
280  Locale(const Locale& other);
281 
282 
287  virtual ~Locale() ;
288 
296  Locale& operator=(const Locale& other);
297 
305  UBool operator==(const Locale& other) const;
306 
315  UBool operator!=(const Locale& other) const;
316 
328  Locale *clone() const;
329 
330 #ifndef U_HIDE_SYSTEM_API
331 
346  static const Locale& U_EXPORT2 getDefault(void);
347 
360  static void U_EXPORT2 setDefault(const Locale& newLocale,
361  UErrorCode& success);
362 #endif /* U_HIDE_SYSTEM_API */
363 
373  static Locale U_EXPORT2 createFromName(const char *name);
374 
383  static Locale U_EXPORT2 createCanonical(const char* name);
384 
390  inline const char * getLanguage( ) const;
391 
399  inline const char * getScript( ) const;
400 
406  inline const char * getCountry( ) const;
407 
413  inline const char * getVariant( ) const;
414 
423  inline const char * getName() const;
424 
432  const char * getBaseName() const;
433 
434 
443  StringEnumeration * createKeywords(UErrorCode &status) const;
444 
456  int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
457 
472  void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
473 
480  const char * getISO3Language() const;
481 
487  const char * getISO3Country() const;
488 
496  uint32_t getLCID(void) const;
497 
511  UBool isRightToLeft() const;
512 
522  UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const;
523 
537  UnicodeString& getDisplayLanguage( const Locale& displayLocale,
538  UnicodeString& dispLang) const;
539 
549  UnicodeString& getDisplayScript( UnicodeString& dispScript) const;
550 
565  UnicodeString& getDisplayScript( const Locale& displayLocale,
566  UnicodeString& dispScript) const;
567 
577  UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const;
578 
593  UnicodeString& getDisplayCountry( const Locale& displayLocale,
594  UnicodeString& dispCountry) const;
595 
603  UnicodeString& getDisplayVariant( UnicodeString& dispVar) const;
604 
613  UnicodeString& getDisplayVariant( const Locale& displayLocale,
614  UnicodeString& dispVar) const;
615 
627  UnicodeString& getDisplayName( UnicodeString& name) const;
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 
768  friend void U_CALLCONV locale_available_init();
769 };
770 
771 inline UBool
772 Locale::operator!=(const Locale& other) const
773 {
774  return !operator==(other);
775 }
776 
777 inline const char *
779 {
780  return country;
781 }
782 
783 inline const char *
785 {
786  return language;
787 }
788 
789 inline const char *
791 {
792  return script;
793 }
794 
795 inline const char *
797 {
798  return &baseName[variantBegin];
799 }
800 
801 inline const char *
803 {
804  return fullName;
805 }
806 
807 inline UBool
808 Locale::isBogus(void) const {
809  return fIsBogus;
810 }
811 
813 
814 #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
C++ API: Unicode String.
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:784
#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:857
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:778
UBool operator!=(const Locale &other) const
Checks if two locale keys are not the same.
Definition: locid.h:772
void locale_available_init()
const char * getScript() const
Returns the locale's ISO-15924 abbreviation script code.
Definition: locid.h:790
#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:796
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:220
const char * getName() const
Returns the programmatic name of the entire locale, with the language, country and variant separated ...
Definition: locid.h:802
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
C++ API: String Enumeration.
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:295
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UBool isBogus(void) const
Gets the bogus state.
Definition: locid.h:808
int8_t UBool
The ICU boolean type.
Definition: umachine.h:259
C API: Locale.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:187