ICU 49.1.1  49.1.1
locid.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 *
4 * Copyright (C) 1996-2012, 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 
181 class U_COMMON_API Locale : public UObject {
182 public:
184  static const Locale &U_EXPORT2 getRoot(void);
186  static const Locale &U_EXPORT2 getEnglish(void);
188  static const Locale &U_EXPORT2 getFrench(void);
190  static const Locale &U_EXPORT2 getGerman(void);
192  static const Locale &U_EXPORT2 getItalian(void);
194  static const Locale &U_EXPORT2 getJapanese(void);
196  static const Locale &U_EXPORT2 getKorean(void);
198  static const Locale &U_EXPORT2 getChinese(void);
200  static const Locale &U_EXPORT2 getSimplifiedChinese(void);
202  static const Locale &U_EXPORT2 getTraditionalChinese(void);
203 
205  static const Locale &U_EXPORT2 getFrance(void);
207  static const Locale &U_EXPORT2 getGermany(void);
209  static const Locale &U_EXPORT2 getItaly(void);
211  static const Locale &U_EXPORT2 getJapan(void);
213  static const Locale &U_EXPORT2 getKorea(void);
215  static const Locale &U_EXPORT2 getChina(void);
217  static const Locale &U_EXPORT2 getPRC(void);
219  static const Locale &U_EXPORT2 getTaiwan(void);
221  static const Locale &U_EXPORT2 getUK(void);
223  static const Locale &U_EXPORT2 getUS(void);
225  static const Locale &U_EXPORT2 getCanada(void);
227  static const Locale &U_EXPORT2 getCanadaFrench(void);
228 
229 
237  Locale();
238 
263  Locale( const char * language,
264  const char * country = 0,
265  const char * variant = 0,
266  const char * keywordsAndValues = 0);
267 
274  Locale(const Locale& other);
275 
276 
281  virtual ~Locale() ;
282 
290  Locale& operator=(const Locale& other);
291 
299  UBool operator==(const Locale& other) const;
300 
309  UBool operator!=(const Locale& other) const;
310 
322  Locale *clone() const;
323 
324 #ifndef U_HIDE_SYSTEM_API
325 
340  static const Locale& U_EXPORT2 getDefault(void);
341 
354  static void U_EXPORT2 setDefault(const Locale& newLocale,
355  UErrorCode& success);
356 #endif /* U_HIDE_SYSTEM_API */
357 
367  static Locale U_EXPORT2 createFromName(const char *name);
368 
377  static Locale U_EXPORT2 createCanonical(const char* name);
378 
384  inline const char * getLanguage( ) const;
385 
393  inline const char * getScript( ) const;
394 
400  inline const char * getCountry( ) const;
401 
407  inline const char * getVariant( ) const;
408 
417  inline const char * getName() const;
418 
426  const char * getBaseName() const;
427 
428 
437  StringEnumeration * createKeywords(UErrorCode &status) const;
438 
450  int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
451 
452 #ifndef U_HIDE_DRAFT_API
453 
464  void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
465 #endif /* U_HIDE_DRAFT_API */
466 
473  const char * getISO3Language() const;
474 
480  const char * getISO3Country() const;
481 
489  uint32_t getLCID(void) const;
490 
500  UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const;
501 
515  UnicodeString& getDisplayLanguage( const Locale& displayLocale,
516  UnicodeString& dispLang) const;
517 
527  UnicodeString& getDisplayScript( UnicodeString& dispScript) const;
528 
543  UnicodeString& getDisplayScript( const Locale& displayLocale,
544  UnicodeString& dispScript) const;
545 
555  UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const;
556 
571  UnicodeString& getDisplayCountry( const Locale& displayLocale,
572  UnicodeString& dispCountry) const;
573 
581  UnicodeString& getDisplayVariant( UnicodeString& dispVar) const;
582 
591  UnicodeString& getDisplayVariant( const Locale& displayLocale,
592  UnicodeString& dispVar) const;
593 
605  UnicodeString& getDisplayName( UnicodeString& name) const;
606 
619  UnicodeString& getDisplayName( const Locale& displayLocale,
620  UnicodeString& name) const;
621 
626  int32_t hashCode(void) const;
627 
636  void setToBogus();
637 
643  UBool isBogus(void) const;
644 
653  static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
654 
663  static const char* const* U_EXPORT2 getISOCountries();
664 
673  static const char* const* U_EXPORT2 getISOLanguages();
674 
680  static UClassID U_EXPORT2 getStaticClassID();
681 
687  virtual UClassID getDynamicClassID() const;
688 
689 protected: /* only protected for testing purposes. DO NOT USE. */
690 #ifndef U_HIDE_INTERNAL_API
691 
695  void setFromPOSIXID(const char *posixID);
696 #endif /* U_HIDE_INTERNAL_API */
697 
698 private:
706  Locale& init(const char* cLocaleID, UBool canonicalize);
707 
708  /*
709  * Internal constructor to allow construction of a locale object with
710  * NO side effects. (Default constructor tries to get
711  * the default locale.)
712  */
713  enum ELocaleType {
714  eBOGUS
715  };
716  Locale(ELocaleType);
717 
721  static Locale *getLocaleCache(void);
722 
723  char language[ULOC_LANG_CAPACITY];
724  char script[ULOC_SCRIPT_CAPACITY];
725  char country[ULOC_COUNTRY_CAPACITY];
726  int32_t variantBegin;
727  char* fullName;
728  char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
729  // name without keywords
730  char* baseName;
731  char baseNameBuffer[ULOC_FULLNAME_CAPACITY];
732 
733  UBool fIsBogus;
734 
735  static const Locale &getLocale(int locid);
736 
741  friend Locale *locale_set_default_internal(const char *, UErrorCode& status);
742 };
743 
744 inline UBool
745 Locale::operator!=(const Locale& other) const
746 {
747  return !operator==(other);
748 }
749 
750 inline const char *
752 {
753  return country;
754 }
755 
756 inline const char *
758 {
759  return language;
760 }
761 
762 inline const char *
764 {
765  return script;
766 }
767 
768 inline const char *
770 {
771  getBaseName(); // lazy init
772  return &baseName[variantBegin];
773 }
774 
775 inline const char *
777 {
778  return fullName;
779 }
780 
781 inline UBool
782 Locale::isBogus(void) const {
783  return fIsBogus;
784 }
785 
787 
788 #endif