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
00030
00031 #ifndef LOCID_H
00032 #define LOCID_H
00033
00034 #include "unicode/bytestream.h"
00035 #include "unicode/localpointer.h"
00036 #include "unicode/strenum.h"
00037 #include "unicode/stringpiece.h"
00038 #include "unicode/utypes.h"
00039 #include "unicode/uobject.h"
00040 #include "unicode/putil.h"
00041 #include "unicode/uloc.h"
00042
00048 U_NAMESPACE_BEGIN
00049
00050
00051 void U_CALLCONV locale_available_init();
00053 class StringEnumeration;
00054 class UnicodeString;
00055
00192 class U_COMMON_API Locale : public UObject {
00193 public:
00195 static const Locale &U_EXPORT2 getRoot(void);
00197 static const Locale &U_EXPORT2 getEnglish(void);
00199 static const Locale &U_EXPORT2 getFrench(void);
00201 static const Locale &U_EXPORT2 getGerman(void);
00203 static const Locale &U_EXPORT2 getItalian(void);
00205 static const Locale &U_EXPORT2 getJapanese(void);
00207 static const Locale &U_EXPORT2 getKorean(void);
00209 static const Locale &U_EXPORT2 getChinese(void);
00211 static const Locale &U_EXPORT2 getSimplifiedChinese(void);
00213 static const Locale &U_EXPORT2 getTraditionalChinese(void);
00214
00216 static const Locale &U_EXPORT2 getFrance(void);
00218 static const Locale &U_EXPORT2 getGermany(void);
00220 static const Locale &U_EXPORT2 getItaly(void);
00222 static const Locale &U_EXPORT2 getJapan(void);
00224 static const Locale &U_EXPORT2 getKorea(void);
00226 static const Locale &U_EXPORT2 getChina(void);
00228 static const Locale &U_EXPORT2 getPRC(void);
00230 static const Locale &U_EXPORT2 getTaiwan(void);
00232 static const Locale &U_EXPORT2 getUK(void);
00234 static const Locale &U_EXPORT2 getUS(void);
00236 static const Locale &U_EXPORT2 getCanada(void);
00238 static const Locale &U_EXPORT2 getCanadaFrench(void);
00239
00240
00248 Locale();
00249
00274 Locale( const char * language,
00275 const char * country = 0,
00276 const char * variant = 0,
00277 const char * keywordsAndValues = 0);
00278
00285 Locale(const Locale& other);
00286
00287 #ifndef U_HIDE_DRAFT_API
00288
00295 Locale(Locale&& other) U_NOEXCEPT;
00296 #endif // U_HIDE_DRAFT_API
00297
00302 virtual ~Locale() ;
00303
00311 Locale& operator=(const Locale& other);
00312
00313 #ifndef U_HIDE_DRAFT_API
00314
00323 Locale& operator=(Locale&& other) U_NOEXCEPT;
00324 #endif // U_HIDE_DRAFT_API
00325
00333 UBool operator==(const Locale& other) const;
00334
00343 inline UBool operator!=(const Locale& other) const;
00344
00356 Locale *clone() const;
00357
00358 #ifndef U_HIDE_SYSTEM_API
00359
00374 static const Locale& U_EXPORT2 getDefault(void);
00375
00388 static void U_EXPORT2 setDefault(const Locale& newLocale,
00389 UErrorCode& success);
00390 #endif
00391
00392 #ifndef U_HIDE_DRAFT_API
00393
00410 static Locale U_EXPORT2 forLanguageTag(StringPiece tag, UErrorCode& status);
00411
00425 void toLanguageTag(ByteSink& sink, UErrorCode& status) const;
00426
00437 template<typename StringClass>
00438 inline StringClass toLanguageTag(UErrorCode& status) const;
00439 #endif // U_HIDE_DRAFT_API
00440
00450 static Locale U_EXPORT2 createFromName(const char *name);
00451
00460 static Locale U_EXPORT2 createCanonical(const char* name);
00461
00467 inline const char * getLanguage( ) const;
00468
00476 inline const char * getScript( ) const;
00477
00483 inline const char * getCountry( ) const;
00484
00490 inline const char * getVariant( ) const;
00491
00500 inline const char * getName() const;
00501
00509 const char * getBaseName() const;
00510
00511 #ifndef U_HIDE_DRAFT_API
00512
00541 void addLikelySubtags(UErrorCode& status);
00542
00572 void minimizeSubtags(UErrorCode& status);
00573 #endif // U_HIDE_DRAFT_API
00574
00584 StringEnumeration * createKeywords(UErrorCode &status) const;
00585
00586 #ifndef U_HIDE_DRAFT_API
00587
00597 StringEnumeration * createUnicodeKeywords(UErrorCode &status) const;
00598
00610 template<typename StringClass, typename OutputIterator>
00611 inline void getKeywords(OutputIterator iterator, UErrorCode& status) const;
00612
00624 template<typename StringClass, typename OutputIterator>
00625 inline void getUnicodeKeywords(OutputIterator iterator, UErrorCode& status) const;
00626
00627 #endif // U_HIDE_DRAFT_API
00628
00645 int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
00646
00647 #ifndef U_HIDE_DRAFT_API
00648
00661 void getKeywordValue(StringPiece keywordName, ByteSink& sink, UErrorCode& status) const;
00662
00676 template<typename StringClass>
00677 inline StringClass getKeywordValue(StringPiece keywordName, UErrorCode& status) const;
00678
00692 void getUnicodeKeywordValue(StringPiece keywordName, ByteSink& sink, UErrorCode& status) const;
00693
00707 template<typename StringClass>
00708 inline StringClass getUnicodeKeywordValue(StringPiece keywordName, UErrorCode& status) const;
00709 #endif // U_HIDE_DRAFT_API
00710
00730 void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
00731
00732 #ifndef U_HIDE_DRAFT_API
00733
00751 void setKeywordValue(StringPiece keywordName, StringPiece keywordValue, UErrorCode& status);
00752
00771 void setUnicodeKeywordValue(StringPiece keywordName, StringPiece keywordValue, UErrorCode& status);
00772 #endif // U_HIDE_DRAFT_API
00773
00780 const char * getISO3Language() const;
00781
00787 const char * getISO3Country() const;
00788
00796 uint32_t getLCID(void) const;
00797
00811 UBool isRightToLeft() const;
00812
00822 UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const;
00823
00837 UnicodeString& getDisplayLanguage( const Locale& displayLocale,
00838 UnicodeString& dispLang) const;
00839
00849 UnicodeString& getDisplayScript( UnicodeString& dispScript) const;
00850
00865 UnicodeString& getDisplayScript( const Locale& displayLocale,
00866 UnicodeString& dispScript) const;
00867
00877 UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const;
00878
00893 UnicodeString& getDisplayCountry( const Locale& displayLocale,
00894 UnicodeString& dispCountry) const;
00895
00903 UnicodeString& getDisplayVariant( UnicodeString& dispVar) const;
00904
00913 UnicodeString& getDisplayVariant( const Locale& displayLocale,
00914 UnicodeString& dispVar) const;
00915
00927 UnicodeString& getDisplayName( UnicodeString& name) const;
00928
00941 UnicodeString& getDisplayName( const Locale& displayLocale,
00942 UnicodeString& name) const;
00943
00948 int32_t hashCode(void) const;
00949
00958 void setToBogus();
00959
00965 inline UBool isBogus(void) const;
00966
00975 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
00976
00985 static const char* const* U_EXPORT2 getISOCountries();
00986
00995 static const char* const* U_EXPORT2 getISOLanguages();
00996
01002 static UClassID U_EXPORT2 getStaticClassID();
01003
01009 virtual UClassID getDynamicClassID() const;
01010
01011 protected:
01012 #ifndef U_HIDE_INTERNAL_API
01013
01017 void setFromPOSIXID(const char *posixID);
01018 #endif
01019
01020 private:
01028 Locale& init(const char* cLocaleID, UBool canonicalize);
01029
01030
01031
01032
01033
01034
01035 enum ELocaleType {
01036 eBOGUS
01037 };
01038 Locale(ELocaleType);
01039
01043 static Locale *getLocaleCache(void);
01044
01045 char language[ULOC_LANG_CAPACITY];
01046 char script[ULOC_SCRIPT_CAPACITY];
01047 char country[ULOC_COUNTRY_CAPACITY];
01048 int32_t variantBegin;
01049 char* fullName;
01050 char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
01051
01052 char* baseName;
01053 void initBaseName(UErrorCode& status);
01054
01055 UBool fIsBogus;
01056
01057 static const Locale &getLocale(int locid);
01058
01063 friend Locale *locale_set_default_internal(const char *, UErrorCode& status);
01064
01068 friend void U_CALLCONV locale_available_init();
01069 };
01070
01071 inline UBool
01072 Locale::operator!=(const Locale& other) const
01073 {
01074 return !operator==(other);
01075 }
01076
01077 #ifndef U_HIDE_DRAFT_API
01078 template<typename StringClass> inline StringClass
01079 Locale::toLanguageTag(UErrorCode& status) const
01080 {
01081 StringClass result;
01082 StringByteSink<StringClass> sink(&result);
01083 toLanguageTag(sink, status);
01084 return result;
01085 }
01086 #endif // U_HIDE_DRAFT_API
01087
01088 inline const char *
01089 Locale::getCountry() const
01090 {
01091 return country;
01092 }
01093
01094 inline const char *
01095 Locale::getLanguage() const
01096 {
01097 return language;
01098 }
01099
01100 inline const char *
01101 Locale::getScript() const
01102 {
01103 return script;
01104 }
01105
01106 inline const char *
01107 Locale::getVariant() const
01108 {
01109 return &baseName[variantBegin];
01110 }
01111
01112 inline const char *
01113 Locale::getName() const
01114 {
01115 return fullName;
01116 }
01117
01118 #ifndef U_HIDE_DRAFT_API
01119
01120 template<typename StringClass, typename OutputIterator> inline void
01121 Locale::getKeywords(OutputIterator iterator, UErrorCode& status) const
01122 {
01123 LocalPointer<StringEnumeration> keys(createKeywords(status));
01124 if (U_FAILURE(status)) {
01125 return;
01126 }
01127 for (;;) {
01128 int32_t resultLength;
01129 const char* buffer = keys->next(&resultLength, status);
01130 if (U_FAILURE(status) || buffer == nullptr) {
01131 return;
01132 }
01133 *iterator++ = StringClass(buffer, resultLength);
01134 }
01135 }
01136
01137 template<typename StringClass, typename OutputIterator> inline void
01138 Locale::getUnicodeKeywords(OutputIterator iterator, UErrorCode& status) const
01139 {
01140 LocalPointer<StringEnumeration> keys(createUnicodeKeywords(status));
01141 if (U_FAILURE(status)) {
01142 return;
01143 }
01144 for (;;) {
01145 int32_t resultLength;
01146 const char* buffer = keys->next(&resultLength, status);
01147 if (U_FAILURE(status) || buffer == nullptr) {
01148 return;
01149 }
01150 *iterator++ = StringClass(buffer, resultLength);
01151 }
01152 }
01153
01154 template<typename StringClass> inline StringClass
01155 Locale::getKeywordValue(StringPiece keywordName, UErrorCode& status) const
01156 {
01157 StringClass result;
01158 StringByteSink<StringClass> sink(&result);
01159 getKeywordValue(keywordName, sink, status);
01160 return result;
01161 }
01162
01163 template<typename StringClass> inline StringClass
01164 Locale::getUnicodeKeywordValue(StringPiece keywordName, UErrorCode& status) const
01165 {
01166 StringClass result;
01167 StringByteSink<StringClass> sink(&result);
01168 getUnicodeKeywordValue(keywordName, sink, status);
01169 return result;
01170 }
01171
01172 #endif // U_HIDE_DRAFT_API
01173
01174 inline UBool
01175 Locale::isBogus(void) const {
01176 return fIsBogus;
01177 }
01178
01179 U_NAMESPACE_END
01180
01181 #endif