ICU 49.1.1  49.1.1
locid.h
Go to the documentation of this file.
00001 /*
00002 ******************************************************************************
00003 *
00004 *   Copyright (C) 1996-2012, 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 
00324 #ifndef U_HIDE_SYSTEM_API
00325 
00340     static const Locale& U_EXPORT2 getDefault(void);
00341 
00354     static void U_EXPORT2 setDefault(const Locale& newLocale,
00355                                      UErrorCode&   success);
00356 #endif  /* U_HIDE_SYSTEM_API */
00357 
00367     static Locale U_EXPORT2 createFromName(const char *name);
00368 
00377     static Locale U_EXPORT2 createCanonical(const char* name);
00378 
00384     inline const char *  getLanguage( ) const;
00385 
00393     inline const char *  getScript( ) const;
00394 
00400     inline const char *  getCountry( ) const;
00401 
00407     inline const char *  getVariant( ) const;
00408 
00417     inline const char * getName() const;
00418 
00426     const char * getBaseName() const;
00427 
00428 
00437     StringEnumeration * createKeywords(UErrorCode &status) const;
00438 
00450     int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
00451 
00452 #ifndef U_HIDE_DRAFT_API
00453 
00464     void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
00465 #endif  /* U_HIDE_DRAFT_API */
00466 
00473     const char * getISO3Language() const;
00474 
00480     const char * getISO3Country() const;
00481 
00489     uint32_t        getLCID(void) const;
00490 
00500     UnicodeString&  getDisplayLanguage(UnicodeString&   dispLang) const;
00501 
00515     UnicodeString&  getDisplayLanguage( const   Locale&         displayLocale,
00516                                                 UnicodeString&  dispLang) const;
00517 
00527     UnicodeString&  getDisplayScript(          UnicodeString& dispScript) const;
00528 
00543     UnicodeString&  getDisplayScript(  const   Locale&         displayLocale,
00544                                                UnicodeString&  dispScript) const;
00545 
00555     UnicodeString&  getDisplayCountry(          UnicodeString& dispCountry) const;
00556 
00571     UnicodeString&  getDisplayCountry(  const   Locale&         displayLocale,
00572                                                 UnicodeString&  dispCountry) const;
00573 
00581     UnicodeString&  getDisplayVariant(      UnicodeString& dispVar) const;
00582 
00591     UnicodeString&  getDisplayVariant(  const   Locale&         displayLocale,
00592                                                 UnicodeString&  dispVar) const;
00593 
00605     UnicodeString&  getDisplayName(         UnicodeString&  name) const;
00606 
00619     UnicodeString&  getDisplayName( const   Locale&         displayLocale,
00620                                             UnicodeString&  name) const;
00621 
00626     int32_t         hashCode(void) const;
00627 
00636     void setToBogus();
00637 
00643     UBool isBogus(void) const;
00644 
00653     static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
00654 
00663     static const char* const* U_EXPORT2 getISOCountries();
00664 
00673     static const char* const* U_EXPORT2 getISOLanguages();
00674 
00680     static UClassID U_EXPORT2 getStaticClassID();
00681 
00687     virtual UClassID getDynamicClassID() const;
00688 
00689 protected: /* only protected for testing purposes. DO NOT USE. */
00690 #ifndef U_HIDE_INTERNAL_API
00691 
00695     void setFromPOSIXID(const char *posixID);
00696 #endif  /* U_HIDE_INTERNAL_API */
00697 
00698 private:
00706     Locale& init(const char* cLocaleID, UBool canonicalize);
00707 
00708     /*
00709      * Internal constructor to allow construction of a locale object with
00710      *   NO side effects.   (Default constructor tries to get
00711      *   the default locale.)
00712      */
00713     enum ELocaleType {
00714         eBOGUS
00715     };
00716     Locale(ELocaleType);
00717 
00721     static Locale *getLocaleCache(void);
00722 
00723     char language[ULOC_LANG_CAPACITY];
00724     char script[ULOC_SCRIPT_CAPACITY];
00725     char country[ULOC_COUNTRY_CAPACITY];
00726     int32_t variantBegin;
00727     char* fullName;
00728     char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
00729     // name without keywords
00730     char* baseName;
00731     char baseNameBuffer[ULOC_FULLNAME_CAPACITY];
00732 
00733     UBool fIsBogus;
00734 
00735     static const Locale &getLocale(int locid);
00736 
00741     friend void locale_set_default_internal(const char *);
00742 };
00743 
00744 inline UBool
00745 Locale::operator!=(const    Locale&     other) const
00746 {
00747     return !operator==(other);
00748 }
00749 
00750 inline const char *
00751 Locale::getCountry() const
00752 {
00753     return country;
00754 }
00755 
00756 inline const char *
00757 Locale::getLanguage() const
00758 {
00759     return language;
00760 }
00761 
00762 inline const char *
00763 Locale::getScript() const
00764 {
00765     return script;
00766 }
00767 
00768 inline const char *
00769 Locale::getVariant() const
00770 {
00771     getBaseName(); // lazy init
00772     return &baseName[variantBegin];
00773 }
00774 
00775 inline const char *
00776 Locale::getName() const
00777 {
00778     return fullName;
00779 }
00780 
00781 inline UBool
00782 Locale::isBogus(void) const {
00783     return fIsBogus;
00784 }
00785 
00786 U_NAMESPACE_END
00787 
00788 #endif