ICU 4.2.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-2006, 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 getEnglish(void);
186  static const Locale &U_EXPORT2 getFrench(void);
188  static const Locale &U_EXPORT2 getGerman(void);
190  static const Locale &U_EXPORT2 getItalian(void);
192  static const Locale &U_EXPORT2 getJapanese(void);
194  static const Locale &U_EXPORT2 getKorean(void);
196  static const Locale &U_EXPORT2 getChinese(void);
198  static const Locale &U_EXPORT2 getSimplifiedChinese(void);
200  static const Locale &U_EXPORT2 getTraditionalChinese(void);
201 
203  static const Locale &U_EXPORT2 getFrance(void);
205  static const Locale &U_EXPORT2 getGermany(void);
207  static const Locale &U_EXPORT2 getItaly(void);
209  static const Locale &U_EXPORT2 getJapan(void);
211  static const Locale &U_EXPORT2 getKorea(void);
213  static const Locale &U_EXPORT2 getChina(void);
215  static const Locale &U_EXPORT2 getPRC(void);
217  static const Locale &U_EXPORT2 getTaiwan(void);
219  static const Locale &U_EXPORT2 getUK(void);
221  static const Locale &U_EXPORT2 getUS(void);
223  static const Locale &U_EXPORT2 getCanada(void);
225  static const Locale &U_EXPORT2 getCanadaFrench(void);
226 
227 
235  Locale();
236 
261  Locale( const char * language,
262  const char * country = 0,
263  const char * variant = 0,
264  const char * keywordsAndValues = 0);
265 
272  Locale(const Locale& other);
273 
274 
279  virtual ~Locale() ;
280 
288  Locale& operator=(const Locale& other);
289 
297  UBool operator==(const Locale& other) const;
298 
307  UBool operator!=(const Locale& other) const;
308 
320  Locale *clone() const;
321 
337  static const Locale& U_EXPORT2 getDefault(void);
338 
351  static void U_EXPORT2 setDefault(const Locale& newLocale,
352  UErrorCode& success);
353 
363  static Locale U_EXPORT2 createFromName(const char *name);
364 
373  static Locale U_EXPORT2 createCanonical(const char* name);
374 
380  inline const char * getLanguage( ) const;
381 
389  inline const char * getScript( ) const;
390 
396  inline const char * getCountry( ) const;
397 
403  inline const char * getVariant( ) const;
404 
413  inline const char * getName() const;
414 
422  const char * getBaseName() const;
423 
424 
432  StringEnumeration * createKeywords(UErrorCode &status) const;
433 
445  int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
446 
453  const char * getISO3Language() const;
454 
460  const char * getISO3Country() const;
461 
469  uint32_t getLCID(void) const;
470 
480  UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const;
481 
495  UnicodeString& getDisplayLanguage( const Locale& displayLocale,
496  UnicodeString& dispLang) const;
497 
507  UnicodeString& getDisplayScript( UnicodeString& dispScript) const;
508 
523  UnicodeString& getDisplayScript( const Locale& displayLocale,
524  UnicodeString& dispScript) const;
525 
535  UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const;
536 
551  UnicodeString& getDisplayCountry( const Locale& displayLocale,
552  UnicodeString& dispCountry) const;
553 
561  UnicodeString& getDisplayVariant( UnicodeString& dispVar) const;
562 
571  UnicodeString& getDisplayVariant( const Locale& displayLocale,
572  UnicodeString& dispVar) const;
573 
585  UnicodeString& getDisplayName( UnicodeString& name) const;
586 
599  UnicodeString& getDisplayName( const Locale& displayLocale,
600  UnicodeString& name) const;
601 
606  int32_t hashCode(void) const;
607 
616  void setToBogus();
617 
623  UBool isBogus(void) const;
624 
633  static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
634 
643  static const char* const* U_EXPORT2 getISOCountries();
644 
653  static const char* const* U_EXPORT2 getISOLanguages();
654 
660  static UClassID U_EXPORT2 getStaticClassID();
661 
667  virtual UClassID getDynamicClassID() const;
668 
669 protected: /* only protected for testing purposes. DO NOT USE. */
674  void setFromPOSIXID(const char *posixID);
675 
676 private:
683  Locale& init(const char* cLocaleID, UBool canonicalize);
684 
685  /*
686  * Internal constructor to allow construction of a locale object with
687  * NO side effects. (Default constructor tries to get
688  * the default locale.)
689  */
690  enum ELocaleType {
691  eBOGUS
692  };
693  Locale(ELocaleType);
694 
698  static Locale *getLocaleCache(void);
699 
700  char language[ULOC_LANG_CAPACITY];
701  char script[ULOC_SCRIPT_CAPACITY];
702  char country[ULOC_COUNTRY_CAPACITY];
703  int32_t variantBegin;
704  char* fullName;
705  char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
706  // name without keywords
707  char* baseName;
708  char baseNameBuffer[ULOC_FULLNAME_CAPACITY];
709 
710  UBool fIsBogus;
711 
712  static const Locale &getLocale(int locid);
713 
718  friend void locale_set_default_internal(const char *);
719 };
720 
721 inline UBool
722 Locale::operator!=(const Locale& other) const
723 {
724  return !operator==(other);
725 }
726 
727 inline const char *
729 {
730  return country;
731 }
732 
733 inline const char *
735 {
736  return language;
737 }
738 
739 inline const char *
741 {
742  return script;
743 }
744 
745 inline const char *
747 {
748  return &fullName[variantBegin];
749 }
750 
751 inline const char *
753 {
754  return fullName;
755 }
756 
757 inline UBool
758 Locale::isBogus(void) const {
759  return fIsBogus;
760 }
761 
763 
764 #endif
765 
const char * getVariant() const
Returns the locale's variant code.
Definition: locid.h:746
UBool isBogus(void) const
Gets the bogus state.
Definition: locid.h:758
#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:734
const char * getScript() const
Returns the locale's ISO-15924 abbreviation script code.
Definition: locid.h:740
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:752
#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
unsigned int uint32_t
Define 64 bit limits.
Definition: pwin32.h:147
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:183
C API: Platform Utilities.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:187
#define U_EXPORT2
Definition: platform.h:338
UBool operator!=(const Locale &other) const
Checks if two locale keys are not the same.
Definition: locid.h:722
C++ API: Common ICU base class UObject.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API If the compiler doesn't support namespaces...
Definition: uversion.h:184
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:212
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:339
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:593
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:474
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:728
virtual UClassID getDynamicClassID() const =0
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
signed int int32_t
Define 64 bit limits.
Definition: pwin32.h:143
int8_t UBool
The ICU boolean type.
Definition: umachine.h:208
C API: Locale.