00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00044 U_NAMESPACE_BEGIN
00045
00182 class U_COMMON_API Locale : public UObject {
00183 public:
00185 static const Locale &U_EXPORT2 getRoot(void);
00187 static const Locale &U_EXPORT2 getEnglish(void);
00189 static const Locale &U_EXPORT2 getFrench(void);
00191 static const Locale &U_EXPORT2 getGerman(void);
00193 static const Locale &U_EXPORT2 getItalian(void);
00195 static const Locale &U_EXPORT2 getJapanese(void);
00197 static const Locale &U_EXPORT2 getKorean(void);
00199 static const Locale &U_EXPORT2 getChinese(void);
00201 static const Locale &U_EXPORT2 getSimplifiedChinese(void);
00203 static const Locale &U_EXPORT2 getTraditionalChinese(void);
00204
00206 static const Locale &U_EXPORT2 getFrance(void);
00208 static const Locale &U_EXPORT2 getGermany(void);
00210 static const Locale &U_EXPORT2 getItaly(void);
00212 static const Locale &U_EXPORT2 getJapan(void);
00214 static const Locale &U_EXPORT2 getKorea(void);
00216 static const Locale &U_EXPORT2 getChina(void);
00218 static const Locale &U_EXPORT2 getPRC(void);
00220 static const Locale &U_EXPORT2 getTaiwan(void);
00222 static const Locale &U_EXPORT2 getUK(void);
00224 static const Locale &U_EXPORT2 getUS(void);
00226 static const Locale &U_EXPORT2 getCanada(void);
00228 static const Locale &U_EXPORT2 getCanadaFrench(void);
00229
00230
00238 Locale();
00239
00264 Locale( const char * language,
00265 const char * country = 0,
00266 const char * variant = 0,
00267 const char * keywordsAndValues = 0);
00268
00275 Locale(const Locale& other);
00276
00277
00282 virtual ~Locale() ;
00283
00291 Locale& operator=(const Locale& other);
00292
00300 UBool operator==(const Locale& other) const;
00301
00310 UBool operator!=(const Locale& other) const;
00311
00323 Locale *clone() const;
00324
00325 #ifndef U_HIDE_SYSTEM_API
00326
00341 static const Locale& U_EXPORT2 getDefault(void);
00342
00355 static void U_EXPORT2 setDefault(const Locale& newLocale,
00356 UErrorCode& success);
00357 #endif
00358
00368 static Locale U_EXPORT2 createFromName(const char *name);
00369
00378 static Locale U_EXPORT2 createCanonical(const char* name);
00379
00385 inline const char * getLanguage( ) const;
00386
00394 inline const char * getScript( ) const;
00395
00401 inline const char * getCountry( ) const;
00402
00408 inline const char * getVariant( ) const;
00409
00418 inline const char * getName() const;
00419
00427 const char * getBaseName() const;
00428
00429
00438 StringEnumeration * createKeywords(UErrorCode &status) const;
00439
00451 int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
00452
00453 #ifndef U_HIDE_DRAFT_API
00454
00465 void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
00466 #endif
00467
00474 const char * getISO3Language() const;
00475
00481 const char * getISO3Country() const;
00482
00490 uint32_t getLCID(void) const;
00491
00501 UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const;
00502
00516 UnicodeString& getDisplayLanguage( const Locale& displayLocale,
00517 UnicodeString& dispLang) const;
00518
00528 UnicodeString& getDisplayScript( UnicodeString& dispScript) const;
00529
00544 UnicodeString& getDisplayScript( const Locale& displayLocale,
00545 UnicodeString& dispScript) const;
00546
00556 UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const;
00557
00572 UnicodeString& getDisplayCountry( const Locale& displayLocale,
00573 UnicodeString& dispCountry) const;
00574
00582 UnicodeString& getDisplayVariant( UnicodeString& dispVar) const;
00583
00592 UnicodeString& getDisplayVariant( const Locale& displayLocale,
00593 UnicodeString& dispVar) const;
00594
00606 UnicodeString& getDisplayName( UnicodeString& name) const;
00607
00620 UnicodeString& getDisplayName( const Locale& displayLocale,
00621 UnicodeString& name) const;
00622
00627 int32_t hashCode(void) const;
00628
00637 void setToBogus();
00638
00644 UBool isBogus(void) const;
00645
00654 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
00655
00664 static const char* const* U_EXPORT2 getISOCountries();
00665
00674 static const char* const* U_EXPORT2 getISOLanguages();
00675
00681 static UClassID U_EXPORT2 getStaticClassID();
00682
00688 virtual UClassID getDynamicClassID() const;
00689
00690 protected:
00691 #ifndef U_HIDE_INTERNAL_API
00692
00696 void setFromPOSIXID(const char *posixID);
00697 #endif
00698
00699 private:
00707 Locale& init(const char* cLocaleID, UBool canonicalize);
00708
00709
00710
00711
00712
00713
00714 enum ELocaleType {
00715 eBOGUS
00716 };
00717 Locale(ELocaleType);
00718
00722 static Locale *getLocaleCache(void);
00723
00724 char language[ULOC_LANG_CAPACITY];
00725 char script[ULOC_SCRIPT_CAPACITY];
00726 char country[ULOC_COUNTRY_CAPACITY];
00727 int32_t variantBegin;
00728 char* fullName;
00729 char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
00730
00731 char* baseName;
00732 char baseNameBuffer[ULOC_FULLNAME_CAPACITY];
00733
00734 UBool fIsBogus;
00735
00736 static const Locale &getLocale(int locid);
00737
00742 friend Locale *locale_set_default_internal(const char *, UErrorCode& status);
00743 };
00744
00745 inline UBool
00746 Locale::operator!=(const Locale& other) const
00747 {
00748 return !operator==(other);
00749 }
00750
00751 inline const char *
00752 Locale::getCountry() const
00753 {
00754 return country;
00755 }
00756
00757 inline const char *
00758 Locale::getLanguage() const
00759 {
00760 return language;
00761 }
00762
00763 inline const char *
00764 Locale::getScript() const
00765 {
00766 return script;
00767 }
00768
00769 inline const char *
00770 Locale::getVariant() const
00771 {
00772 getBaseName();
00773 return &baseName[variantBegin];
00774 }
00775
00776 inline const char *
00777 Locale::getName() const
00778 {
00779 return fullName;
00780 }
00781
00782 inline UBool
00783 Locale::isBogus(void) const {
00784 return fIsBogus;
00785 }
00786
00787 U_NAMESPACE_END
00788
00789 #endif