ICU 4.8.1.1
4.8.1.1
|
00001 /* 00002 ****************************************************************************** 00003 * 00004 * Copyright (C) 1996-2011, International Business Machines 00005 * Corporation and others. All Rights Reserved. 00006 * 00007 ****************************************************************************** 00008 * 00009 * File locid.h 00010 * 00011 * Created by: Helena Shih 00012 * 00013 * Modification History: 00014 * 00015 * Date Name Description 00016 * 02/11/97 aliu Changed gLocPath to fgLocPath and added methods to 00017 * get and set it. 00018 * 04/02/97 aliu Made operator!= inline; fixed return value of getName(). 00019 * 04/15/97 aliu Cleanup for AIX/Win32. 00020 * 04/24/97 aliu Numerous changes per code review. 00021 * 08/18/98 stephen Added tokenizeString(),changed getDisplayName() 00022 * 09/08/98 stephen Moved definition of kEmptyString for Mac Port 00023 * 11/09/99 weiv Added const char * getName() const; 00024 * 04/12/00 srl removing unicodestring api's and cached hash code 00025 * 08/10/01 grhoten Change the static Locales to accessor functions 00026 ****************************************************************************** 00027 */ 00028 00029 #ifndef LOCID_H 00030 #define LOCID_H 00031 00032 #include "unicode/utypes.h" 00033 #include "unicode/uobject.h" 00034 #include "unicode/unistr.h" 00035 #include "unicode/putil.h" 00036 #include "unicode/uloc.h" 00037 #include "unicode/strenum.h" 00038 00180 U_NAMESPACE_BEGIN 00181 class U_COMMON_API Locale : public UObject { 00182 public: 00184 static const Locale &U_EXPORT2 getRoot(void); 00186 static const Locale &U_EXPORT2 getEnglish(void); 00188 static const Locale &U_EXPORT2 getFrench(void); 00190 static const Locale &U_EXPORT2 getGerman(void); 00192 static const Locale &U_EXPORT2 getItalian(void); 00194 static const Locale &U_EXPORT2 getJapanese(void); 00196 static const Locale &U_EXPORT2 getKorean(void); 00198 static const Locale &U_EXPORT2 getChinese(void); 00200 static const Locale &U_EXPORT2 getSimplifiedChinese(void); 00202 static const Locale &U_EXPORT2 getTraditionalChinese(void); 00203 00205 static const Locale &U_EXPORT2 getFrance(void); 00207 static const Locale &U_EXPORT2 getGermany(void); 00209 static const Locale &U_EXPORT2 getItaly(void); 00211 static const Locale &U_EXPORT2 getJapan(void); 00213 static const Locale &U_EXPORT2 getKorea(void); 00215 static const Locale &U_EXPORT2 getChina(void); 00217 static const Locale &U_EXPORT2 getPRC(void); 00219 static const Locale &U_EXPORT2 getTaiwan(void); 00221 static const Locale &U_EXPORT2 getUK(void); 00223 static const Locale &U_EXPORT2 getUS(void); 00225 static const Locale &U_EXPORT2 getCanada(void); 00227 static const Locale &U_EXPORT2 getCanadaFrench(void); 00228 00229 00237 Locale(); 00238 00263 Locale( const char * language, 00264 const char * country = 0, 00265 const char * variant = 0, 00266 const char * keywordsAndValues = 0); 00267 00274 Locale(const Locale& other); 00275 00276 00281 virtual ~Locale() ; 00282 00290 Locale& operator=(const Locale& other); 00291 00299 UBool operator==(const Locale& other) const; 00300 00309 UBool operator!=(const Locale& other) const; 00310 00322 Locale *clone() const; 00323 00339 static const Locale& U_EXPORT2 getDefault(void); 00340 00353 static void U_EXPORT2 setDefault(const Locale& newLocale, 00354 UErrorCode& success); 00355 00365 static Locale U_EXPORT2 createFromName(const char *name); 00366 00375 static Locale U_EXPORT2 createCanonical(const char* name); 00376 00382 inline const char * getLanguage( ) const; 00383 00391 inline const char * getScript( ) const; 00392 00398 inline const char * getCountry( ) const; 00399 00405 inline const char * getVariant( ) const; 00406 00415 inline const char * getName() const; 00416 00424 const char * getBaseName() const; 00425 00426 00435 StringEnumeration * createKeywords(UErrorCode &status) const; 00436 00448 int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const; 00449 00461 void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status); 00462 00469 const char * getISO3Language() const; 00470 00476 const char * getISO3Country() const; 00477 00485 uint32_t getLCID(void) const; 00486 00496 UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const; 00497 00511 UnicodeString& getDisplayLanguage( const Locale& displayLocale, 00512 UnicodeString& dispLang) const; 00513 00523 UnicodeString& getDisplayScript( UnicodeString& dispScript) const; 00524 00539 UnicodeString& getDisplayScript( const Locale& displayLocale, 00540 UnicodeString& dispScript) const; 00541 00551 UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const; 00552 00567 UnicodeString& getDisplayCountry( const Locale& displayLocale, 00568 UnicodeString& dispCountry) const; 00569 00577 UnicodeString& getDisplayVariant( UnicodeString& dispVar) const; 00578 00587 UnicodeString& getDisplayVariant( const Locale& displayLocale, 00588 UnicodeString& dispVar) const; 00589 00601 UnicodeString& getDisplayName( UnicodeString& name) const; 00602 00615 UnicodeString& getDisplayName( const Locale& displayLocale, 00616 UnicodeString& name) const; 00617 00622 int32_t hashCode(void) const; 00623 00632 void setToBogus(); 00633 00639 UBool isBogus(void) const; 00640 00649 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count); 00650 00659 static const char* const* U_EXPORT2 getISOCountries(); 00660 00669 static const char* const* U_EXPORT2 getISOLanguages(); 00670 00676 static UClassID U_EXPORT2 getStaticClassID(); 00677 00683 virtual UClassID getDynamicClassID() const; 00684 00685 protected: /* only protected for testing purposes. DO NOT USE. */ 00690 void setFromPOSIXID(const char *posixID); 00691 00692 private: 00700 Locale& init(const char* cLocaleID, UBool canonicalize); 00701 00702 /* 00703 * Internal constructor to allow construction of a locale object with 00704 * NO side effects. (Default constructor tries to get 00705 * the default locale.) 00706 */ 00707 enum ELocaleType { 00708 eBOGUS 00709 }; 00710 Locale(ELocaleType); 00711 00715 static Locale *getLocaleCache(void); 00716 00717 char language[ULOC_LANG_CAPACITY]; 00718 char script[ULOC_SCRIPT_CAPACITY]; 00719 char country[ULOC_COUNTRY_CAPACITY]; 00720 int32_t variantBegin; 00721 char* fullName; 00722 char fullNameBuffer[ULOC_FULLNAME_CAPACITY]; 00723 // name without keywords 00724 char* baseName; 00725 char baseNameBuffer[ULOC_FULLNAME_CAPACITY]; 00726 00727 UBool fIsBogus; 00728 00729 static const Locale &getLocale(int locid); 00730 00735 friend void locale_set_default_internal(const char *); 00736 }; 00737 00738 inline UBool 00739 Locale::operator!=(const Locale& other) const 00740 { 00741 return !operator==(other); 00742 } 00743 00744 inline const char * 00745 Locale::getCountry() const 00746 { 00747 return country; 00748 } 00749 00750 inline const char * 00751 Locale::getLanguage() const 00752 { 00753 return language; 00754 } 00755 00756 inline const char * 00757 Locale::getScript() const 00758 { 00759 return script; 00760 } 00761 00762 inline const char * 00763 Locale::getVariant() const 00764 { 00765 getBaseName(); // lazy init 00766 return &baseName[variantBegin]; 00767 } 00768 00769 inline const char * 00770 Locale::getName() const 00771 { 00772 return fullName; 00773 } 00774 00775 inline UBool 00776 Locale::isBogus(void) const { 00777 return fIsBogus; 00778 } 00779 00780 U_NAMESPACE_END 00781 00782 #endif