ICU 4.8.1.1  4.8.1.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
locid.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 *
4 * Copyright (C) 1996-2011, 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 
181 class U_COMMON_API Locale : public UObject {
182 public:
184  static const Locale &U_EXPORT2 getRoot(void);
186  static const Locale &U_EXPORT2 getEnglish(void);
188  static const Locale &U_EXPORT2 getFrench(void);
190  static const Locale &U_EXPORT2 getGerman(void);
192  static const Locale &U_EXPORT2 getItalian(void);
194  static const Locale &U_EXPORT2 getJapanese(void);
196  static const Locale &U_EXPORT2 getKorean(void);
198  static const Locale &U_EXPORT2 getChinese(void);
200  static const Locale &U_EXPORT2 getSimplifiedChinese(void);
202  static const Locale &U_EXPORT2 getTraditionalChinese(void);
203 
205  static const Locale &U_EXPORT2 getFrance(void);
207  static const Locale &U_EXPORT2 getGermany(void);
209  static const Locale &U_EXPORT2 getItaly(void);
211  static const Locale &U_EXPORT2 getJapan(void);
213  static const Locale &U_EXPORT2 getKorea(void);
215  static const Locale &U_EXPORT2 getChina(void);
217  static const Locale &U_EXPORT2 getPRC(void);
219  static const Locale &U_EXPORT2 getTaiwan(void);
221  static const Locale &U_EXPORT2 getUK(void);
223  static const Locale &U_EXPORT2 getUS(void);
225  static const Locale &U_EXPORT2 getCanada(void);
227  static const Locale &U_EXPORT2 getCanadaFrench(void);
228 
229 
237  Locale();
238 
263  Locale( const char * language,
264  const char * country = 0,
265  const char * variant = 0,
266  const char * keywordsAndValues = 0);
267 
274  Locale(const Locale& other);
275 
276 
281  virtual ~Locale() ;
282 
290  Locale& operator=(const Locale& other);
291 
299  UBool operator==(const Locale& other) const;
300 
309  UBool operator!=(const Locale& other) const;
310 
322  Locale *clone() const;
323 
339  static const Locale& U_EXPORT2 getDefault(void);
340 
353  static void U_EXPORT2 setDefault(const Locale& newLocale,
354  UErrorCode& success);
355 
365  static Locale U_EXPORT2 createFromName(const char *name);
366 
375  static Locale U_EXPORT2 createCanonical(const char* name);
376 
382  inline const char * getLanguage( ) const;
383 
391  inline const char * getScript( ) const;
392 
398  inline const char * getCountry( ) const;
399 
405  inline const char * getVariant( ) const;
406 
415  inline const char * getName() const;
416 
424  const char * getBaseName() const;
425 
426 
435  StringEnumeration * createKeywords(UErrorCode &status) const;
436 
448  int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
449 
461  void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
462 
469  const char * getISO3Language() const;
470 
476  const char * getISO3Country() const;
477 
485  uint32_t getLCID(void) const;
486 
496  UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const;
497 
511  UnicodeString& getDisplayLanguage( const Locale& displayLocale,
512  UnicodeString& dispLang) const;
513 
523  UnicodeString& getDisplayScript( UnicodeString& dispScript) const;
524 
539  UnicodeString& getDisplayScript( const Locale& displayLocale,
540  UnicodeString& dispScript) const;
541 
551  UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const;
552 
567  UnicodeString& getDisplayCountry( const Locale& displayLocale,
568  UnicodeString& dispCountry) const;
569 
577  UnicodeString& getDisplayVariant( UnicodeString& dispVar) const;
578 
587  UnicodeString& getDisplayVariant( const Locale& displayLocale,
588  UnicodeString& dispVar) const;
589 
601  UnicodeString& getDisplayName( UnicodeString& name) const;
602 
615  UnicodeString& getDisplayName( const Locale& displayLocale,
616  UnicodeString& name) const;
617 
622  int32_t hashCode(void) const;
623 
632  void setToBogus();
633 
639  UBool isBogus(void) const;
640 
649  static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
650 
659  static const char* const* U_EXPORT2 getISOCountries();
660 
669  static const char* const* U_EXPORT2 getISOLanguages();
670 
676  static UClassID U_EXPORT2 getStaticClassID();
677 
683  virtual UClassID getDynamicClassID() const;
684 
685 protected: /* only protected for testing purposes. DO NOT USE. */
690  void setFromPOSIXID(const char *posixID);
691 
692 private:
700  Locale& init(const char* cLocaleID, UBool canonicalize);
701 
702  /*
703  * Internal constructor to allow construction of a locale object with
704  * NO side effects. (Default constructor tries to get
705  * the default locale.)
706  */
707  enum ELocaleType {
708  eBOGUS
709  };
710  Locale(ELocaleType);
711 
715  static Locale *getLocaleCache(void);
716 
717  char language[ULOC_LANG_CAPACITY];
718  char script[ULOC_SCRIPT_CAPACITY];
719  char country[ULOC_COUNTRY_CAPACITY];
720  int32_t variantBegin;
721  char* fullName;
722  char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
723  // name without keywords
724  char* baseName;
725  char baseNameBuffer[ULOC_FULLNAME_CAPACITY];
726 
727  UBool fIsBogus;
728 
729  static const Locale &getLocale(int locid);
730 
735  friend Locale *locale_set_default_internal(const char *, UErrorCode& status);
736 };
737 
738 inline UBool
739 Locale::operator!=(const Locale& other) const
740 {
741  return !operator==(other);
742 }
743 
744 inline const char *
746 {
747  return country;
748 }
749 
750 inline const char *
752 {
753  return language;
754 }
755 
756 inline const char *
758 {
759  return script;
760 }
761 
762 inline const char *
764 {
765  getBaseName(); // lazy init
766  return &baseName[variantBegin];
767 }
768 
769 inline const char *
771 {
772  return fullName;
773 }
774 
775 inline UBool
776 Locale::isBogus(void) const {
777  return fIsBogus;
778 }
779 
781 
782 #endif
const char * getVariant() const
Returns the locale's variant code.
Definition: locid.h:763
UBool isBogus(void) const
Gets the bogus state.
Definition: locid.h:776
#define ULOC_LANG_CAPACITY
Useful constant for the maximum size of the language part of a locale ID.
Definition: uloc.h:249
const char * getLanguage() const
Returns the locale's ISO-639 language code.
Definition: locid.h:751
const char * getScript() const
Returns the locale's ISO-15924 abbreviation script code.
Definition: locid.h:757
C++ API: Unicode String.
#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
const char * getName() const
Returns the programmatic name of the entire locale, with the language, country and variant separated ...
Definition: locid.h:770
#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
#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
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
C API: Platform Utilities.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:188
#define U_EXPORT2
Definition: platform.h:314
UBool operator!=(const Locale &other) const
Checks if two locale keys are not the same.
Definition: locid.h:739
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
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
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:215
UBool operator==(const Locale &other) const
Checks if two locale keys are the same.
void * UClassID
UClassID is used to identify classes without using RTTI, since RTTI is not yet supported by all C++ c...
Definition: utypes.h:385
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:639
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:55
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:520
const char * getBaseName() const
Returns the programmatic name of the entire locale as getName would return, but without keywords...
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:181
const char * getCountry() const
Returns the locale's ISO-3166 country code.
Definition: locid.h:745
virtual UClassID getDynamicClassID() const =0
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:228
C API: Locale.