ICU 51.2  51.2
locid.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 *
4 * Copyright (C) 1996-2013, 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 
45 
182 class U_COMMON_API Locale : public UObject {
183 public:
185  static const Locale &U_EXPORT2 getRoot(void);
187  static const Locale &U_EXPORT2 getEnglish(void);
189  static const Locale &U_EXPORT2 getFrench(void);
191  static const Locale &U_EXPORT2 getGerman(void);
193  static const Locale &U_EXPORT2 getItalian(void);
195  static const Locale &U_EXPORT2 getJapanese(void);
197  static const Locale &U_EXPORT2 getKorean(void);
199  static const Locale &U_EXPORT2 getChinese(void);
201  static const Locale &U_EXPORT2 getSimplifiedChinese(void);
203  static const Locale &U_EXPORT2 getTraditionalChinese(void);
204 
206  static const Locale &U_EXPORT2 getFrance(void);
208  static const Locale &U_EXPORT2 getGermany(void);
210  static const Locale &U_EXPORT2 getItaly(void);
212  static const Locale &U_EXPORT2 getJapan(void);
214  static const Locale &U_EXPORT2 getKorea(void);
216  static const Locale &U_EXPORT2 getChina(void);
218  static const Locale &U_EXPORT2 getPRC(void);
220  static const Locale &U_EXPORT2 getTaiwan(void);
222  static const Locale &U_EXPORT2 getUK(void);
224  static const Locale &U_EXPORT2 getUS(void);
226  static const Locale &U_EXPORT2 getCanada(void);
228  static const Locale &U_EXPORT2 getCanadaFrench(void);
229 
230 
238  Locale();
239 
264  Locale( const char * language,
265  const char * country = 0,
266  const char * variant = 0,
267  const char * keywordsAndValues = 0);
268 
275  Locale(const Locale& other);
276 
277 
282  virtual ~Locale() ;
283 
291  Locale& operator=(const Locale& other);
292 
300  UBool operator==(const Locale& other) const;
301 
310  UBool operator!=(const Locale& other) const;
311 
323  Locale *clone() const;
324 
325 #ifndef U_HIDE_SYSTEM_API
326 
341  static const Locale& U_EXPORT2 getDefault(void);
342 
355  static void U_EXPORT2 setDefault(const Locale& newLocale,
356  UErrorCode& success);
357 #endif /* U_HIDE_SYSTEM_API */
358 
368  static Locale U_EXPORT2 createFromName(const char *name);
369 
378  static Locale U_EXPORT2 createCanonical(const char* name);
379 
385  inline const char * getLanguage( ) const;
386 
394  inline const char * getScript( ) const;
395 
401  inline const char * getCountry( ) const;
402 
408  inline const char * getVariant( ) const;
409 
418  inline const char * getName() const;
419 
427  const char * getBaseName() const;
428 
429 
438  StringEnumeration * createKeywords(UErrorCode &status) const;
439 
451  int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
452 
464  void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
465 
472  const char * getISO3Language() const;
473 
479  const char * getISO3Country() const;
480 
488  uint32_t getLCID(void) const;
489 
499  UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const;
500 
514  UnicodeString& getDisplayLanguage( const Locale& displayLocale,
515  UnicodeString& dispLang) const;
516 
526  UnicodeString& getDisplayScript( UnicodeString& dispScript) const;
527 
542  UnicodeString& getDisplayScript( const Locale& displayLocale,
543  UnicodeString& dispScript) const;
544 
554  UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const;
555 
570  UnicodeString& getDisplayCountry( const Locale& displayLocale,
571  UnicodeString& dispCountry) const;
572 
580  UnicodeString& getDisplayVariant( UnicodeString& dispVar) const;
581 
590  UnicodeString& getDisplayVariant( const Locale& displayLocale,
591  UnicodeString& dispVar) const;
592 
604  UnicodeString& getDisplayName( UnicodeString& name) const;
605 
618  UnicodeString& getDisplayName( const Locale& displayLocale,
619  UnicodeString& name) const;
620 
625  int32_t hashCode(void) const;
626 
635  void setToBogus();
636 
642  UBool isBogus(void) const;
643 
652  static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
653 
662  static const char* const* U_EXPORT2 getISOCountries();
663 
672  static const char* const* U_EXPORT2 getISOLanguages();
673 
679  static UClassID U_EXPORT2 getStaticClassID();
680 
686  virtual UClassID getDynamicClassID() const;
687 
688 protected: /* only protected for testing purposes. DO NOT USE. */
689 #ifndef U_HIDE_INTERNAL_API
690 
694  void setFromPOSIXID(const char *posixID);
695 #endif /* U_HIDE_INTERNAL_API */
696 
697 private:
705  Locale& init(const char* cLocaleID, UBool canonicalize);
706 
707  /*
708  * Internal constructor to allow construction of a locale object with
709  * NO side effects. (Default constructor tries to get
710  * the default locale.)
711  */
712  enum ELocaleType {
713  eBOGUS
714  };
715  Locale(ELocaleType);
716 
720  static Locale *getLocaleCache(void);
721 
722  char language[ULOC_LANG_CAPACITY];
723  char script[ULOC_SCRIPT_CAPACITY];
724  char country[ULOC_COUNTRY_CAPACITY];
725  int32_t variantBegin;
726  char* fullName;
727  char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
728  // name without keywords
729  char* baseName;
730  char baseNameBuffer[ULOC_FULLNAME_CAPACITY];
731 
732  UBool fIsBogus;
733 
734  static const Locale &getLocale(int locid);
735 
740  friend Locale *locale_set_default_internal(const char *, UErrorCode& status);
741 };
742 
743 inline UBool
744 Locale::operator!=(const Locale& other) const
745 {
746  return !operator==(other);
747 }
748 
749 inline const char *
750 Locale::getCountry() const
751 {
752  return country;
753 }
754 
755 inline const char *
756 Locale::getLanguage() const
757 {
758  return language;
759 }
760 
761 inline const char *
762 Locale::getScript() const
763 {
764  return script;
765 }
766 
767 inline const char *
768 Locale::getVariant() const
769 {
770  getBaseName(); // lazy init
771  return &baseName[variantBegin];
772 }
773 
774 inline const char *
775 Locale::getName() const
776 {
777  return fullName;
778 }
779 
780 inline UBool
781 Locale::isBogus(void) const {
782  return fIsBogus;
783 }
784 
786 
787 #endif