ICU 56.1  56.1
locid.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 *
4 * Copyright (C) 1996-2015, 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 
46 // Forward Declarations
185 class U_COMMON_API Locale : public UObject {
186 public:
188  static const Locale &U_EXPORT2 getRoot(void);
190  static const Locale &U_EXPORT2 getEnglish(void);
192  static const Locale &U_EXPORT2 getFrench(void);
194  static const Locale &U_EXPORT2 getGerman(void);
196  static const Locale &U_EXPORT2 getItalian(void);
198  static const Locale &U_EXPORT2 getJapanese(void);
200  static const Locale &U_EXPORT2 getKorean(void);
202  static const Locale &U_EXPORT2 getChinese(void);
204  static const Locale &U_EXPORT2 getSimplifiedChinese(void);
206  static const Locale &U_EXPORT2 getTraditionalChinese(void);
207 
209  static const Locale &U_EXPORT2 getFrance(void);
211  static const Locale &U_EXPORT2 getGermany(void);
213  static const Locale &U_EXPORT2 getItaly(void);
215  static const Locale &U_EXPORT2 getJapan(void);
217  static const Locale &U_EXPORT2 getKorea(void);
219  static const Locale &U_EXPORT2 getChina(void);
221  static const Locale &U_EXPORT2 getPRC(void);
223  static const Locale &U_EXPORT2 getTaiwan(void);
225  static const Locale &U_EXPORT2 getUK(void);
227  static const Locale &U_EXPORT2 getUS(void);
229  static const Locale &U_EXPORT2 getCanada(void);
231  static const Locale &U_EXPORT2 getCanadaFrench(void);
232 
233 
241  Locale();
242 
267  Locale( const char * language,
268  const char * country = 0,
269  const char * variant = 0,
270  const char * keywordsAndValues = 0);
271 
278  Locale(const Locale& other);
279 
280 
285  virtual ~Locale() ;
286 
294  Locale& operator=(const Locale& other);
295 
303  UBool operator==(const Locale& other) const;
304 
313  UBool operator!=(const Locale& other) const;
314 
326  Locale *clone() const;
327 
328 #ifndef U_HIDE_SYSTEM_API
329 
344  static const Locale& U_EXPORT2 getDefault(void);
345 
358  static void U_EXPORT2 setDefault(const Locale& newLocale,
359  UErrorCode& success);
360 #endif /* U_HIDE_SYSTEM_API */
361 
371  static Locale U_EXPORT2 createFromName(const char *name);
372 
381  static Locale U_EXPORT2 createCanonical(const char* name);
382 
388  inline const char * getLanguage( ) const;
389 
397  inline const char * getScript( ) const;
398 
404  inline const char * getCountry( ) const;
405 
411  inline const char * getVariant( ) const;
412 
421  inline const char * getName() const;
422 
430  const char * getBaseName() const;
431 
432 
441  StringEnumeration * createKeywords(UErrorCode &status) const;
442 
454  int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
455 
470  void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
471 
478  const char * getISO3Language() const;
479 
485  const char * getISO3Country() const;
486 
494  uint32_t getLCID(void) const;
495 
509  UBool isRightToLeft() const;
510 
520  UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const;
521 
535  UnicodeString& getDisplayLanguage( const Locale& displayLocale,
536  UnicodeString& dispLang) const;
537 
547  UnicodeString& getDisplayScript( UnicodeString& dispScript) const;
548 
563  UnicodeString& getDisplayScript( const Locale& displayLocale,
564  UnicodeString& dispScript) const;
565 
575  UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const;
576 
591  UnicodeString& getDisplayCountry( const Locale& displayLocale,
592  UnicodeString& dispCountry) const;
593 
601  UnicodeString& getDisplayVariant( UnicodeString& dispVar) const;
602 
611  UnicodeString& getDisplayVariant( const Locale& displayLocale,
612  UnicodeString& dispVar) const;
613 
625  UnicodeString& getDisplayName( UnicodeString& name) const;
626 
639  UnicodeString& getDisplayName( const Locale& displayLocale,
640  UnicodeString& name) const;
641 
646  int32_t hashCode(void) const;
647 
656  void setToBogus();
657 
663  UBool isBogus(void) const;
664 
673  static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
674 
683  static const char* const* U_EXPORT2 getISOCountries();
684 
693  static const char* const* U_EXPORT2 getISOLanguages();
694 
700  static UClassID U_EXPORT2 getStaticClassID();
701 
707  virtual UClassID getDynamicClassID() const;
708 
709 protected: /* only protected for testing purposes. DO NOT USE. */
710 #ifndef U_HIDE_INTERNAL_API
711 
715  void setFromPOSIXID(const char *posixID);
716 #endif /* U_HIDE_INTERNAL_API */
717 
718 private:
726  Locale& init(const char* cLocaleID, UBool canonicalize);
727 
728  /*
729  * Internal constructor to allow construction of a locale object with
730  * NO side effects. (Default constructor tries to get
731  * the default locale.)
732  */
733  enum ELocaleType {
734  eBOGUS
735  };
736  Locale(ELocaleType);
737 
741  static Locale *getLocaleCache(void);
742 
743  char language[ULOC_LANG_CAPACITY];
744  char script[ULOC_SCRIPT_CAPACITY];
745  char country[ULOC_COUNTRY_CAPACITY];
746  int32_t variantBegin;
747  char* fullName;
748  char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
749  // name without keywords
750  char* baseName;
751  void initBaseName(UErrorCode& status);
752 
753  UBool fIsBogus;
754 
755  static const Locale &getLocale(int locid);
756 
761  friend Locale *locale_set_default_internal(const char *, UErrorCode& status);
762 
766  friend void U_CALLCONV locale_available_init();
767 };
768 
769 inline UBool
770 Locale::operator!=(const Locale& other) const
771 {
772  return !operator==(other);
773 }
774 
775 inline const char *
777 {
778  return country;
779 }
780 
781 inline const char *
783 {
784  return language;
785 }
786 
787 inline const char *
789 {
790  return script;
791 }
792 
793 inline const char *
795 {
796  return &baseName[variantBegin];
797 }
798 
799 inline const char *
801 {
802  return fullName;
803 }
804 
805 inline UBool
806 Locale::isBogus(void) const {
807  return fIsBogus;
808 }
809 
811 
812 #endif
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
#define ULOC_LANG_CAPACITY
Useful constant for the maximum size of the language part of a locale ID.
Definition: uloc.h:249
C++ API: Unicode String.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
const char * getLanguage() const
Returns the locale's ISO-639 language code.
Definition: locid.h:782
#define ULOC_COUNTRY_CAPACITY
Useful constant for the maximum size of the country part of a locale ID (including the terminating NU...
Definition: uloc.h:256
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition: platform.h:823
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
#define ULOC_FULLNAME_CAPACITY
Useful constant for the maximum size of the whole locale ID (including the terminating NULL and all k...
Definition: uloc.h:262
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:55
#define ULOC_SCRIPT_CAPACITY
Useful constant for the maximum size of the script part of a locale ID (including the terminating NUL...
Definition: uloc.h:269
const char * getCountry() const
Returns the locale's ISO-3166 country code.
Definition: locid.h:776
UBool operator!=(const Locale &other) const
Checks if two locale keys are not the same.
Definition: locid.h:770
void locale_available_init()
const char * getScript() const
Returns the locale's ISO-15924 abbreviation script code.
Definition: locid.h:788
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
const char * getVariant() const
Returns the locale's variant code.
Definition: locid.h:794
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
const char * getName() const
Returns the programmatic name of the entire locale, with the language, country and variant separated ...
Definition: locid.h:800
C API: Platform Utilities.
C++ API: Common ICU base class UObject.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
C++ API: String Enumeration.
Basic definitions for ICU, for both C and C++ APIs.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
Definition: utypes.h:357
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:293
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:221
UBool isBogus(void) const
Gets the bogus state.
Definition: locid.h:806
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
C API: Locale.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185