ICU 50.1.2  50.1.2
coll.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 * Copyright (C) 1996-2012, International Business Machines *
4 * Corporation and others. All Rights Reserved. *
5 ******************************************************************************
6 */
7 
49 #ifndef COLL_H
50 #define COLL_H
51 
52 #include "unicode/utypes.h"
53 
54 #if !UCONFIG_NO_COLLATION
55 
56 #include "unicode/uobject.h"
57 #include "unicode/ucol.h"
58 #include "unicode/normlzr.h"
59 #include "unicode/locid.h"
60 #include "unicode/uniset.h"
61 #include "unicode/umisc.h"
62 #include "unicode/uiter.h"
63 #include "unicode/stringpiece.h"
64 
66 
67 class StringEnumeration;
68 
69 #if !UCONFIG_NO_SERVICE
70 
73 class CollatorFactory;
74 #endif
75 
79 class CollationKey;
80 
177 class U_I18N_API Collator : public UObject {
178 public:
179 
180  // Collator public enums -----------------------------------------------
181 
208  {
209  PRIMARY = UCOL_PRIMARY, // 0
210  SECONDARY = UCOL_SECONDARY, // 1
211  TERTIARY = UCOL_TERTIARY, // 2
212  QUATERNARY = UCOL_QUATERNARY, // 3
213  IDENTICAL = UCOL_IDENTICAL // 15
214  };
215 
227  {
228  LESS = UCOL_LESS, // -1
229  EQUAL = UCOL_EQUAL, // 0
230  GREATER = UCOL_GREATER // 1
231  };
232 
233  // Collator public destructor -----------------------------------------
234 
239  virtual ~Collator();
240 
241  // Collator public methods --------------------------------------------
242 
261  virtual UBool operator==(const Collator& other) const;
262 
270  virtual UBool operator!=(const Collator& other) const;
271 
277  virtual Collator* clone(void) const = 0;
278 
298  static Collator* U_EXPORT2 createInstance(UErrorCode& err);
299 
323  static Collator* U_EXPORT2 createInstance(const Locale& loc, UErrorCode& err);
324 
325 #ifdef U_USE_COLLATION_OBSOLETE_2_6
326 
349  static Collator *createInstance(const Locale &loc, UVersionInfo version, UErrorCode &err);
350 #endif
351 
363  virtual EComparisonResult compare(const UnicodeString& source,
364  const UnicodeString& target) const;
365 
378  virtual UCollationResult compare(const UnicodeString& source,
379  const UnicodeString& target,
380  UErrorCode &status) const = 0;
381 
394  virtual EComparisonResult compare(const UnicodeString& source,
395  const UnicodeString& target,
396  int32_t length) const;
397 
411  virtual UCollationResult compare(const UnicodeString& source,
412  const UnicodeString& target,
413  int32_t length,
414  UErrorCode &status) const = 0;
415 
449  virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
450  const UChar* target, int32_t targetLength)
451  const;
452 
469  virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
470  const UChar* target, int32_t targetLength,
471  UErrorCode &status) const = 0;
472 
484  virtual UCollationResult compare(UCharIterator &sIter,
485  UCharIterator &tIter,
486  UErrorCode &status) const;
487 
501  virtual UCollationResult compareUTF8(const StringPiece &source,
502  const StringPiece &target,
503  UErrorCode &status) const;
504 
520  virtual CollationKey& getCollationKey(const UnicodeString& source,
521  CollationKey& key,
522  UErrorCode& status) const = 0;
523 
540  virtual CollationKey& getCollationKey(const UChar*source,
541  int32_t sourceLength,
542  CollationKey& key,
543  UErrorCode& status) const = 0;
548  virtual int32_t hashCode(void) const = 0;
549 
562  virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0;
563 
573  UBool greater(const UnicodeString& source, const UnicodeString& target)
574  const;
575 
585  UBool greaterOrEqual(const UnicodeString& source,
586  const UnicodeString& target) const;
587 
597  UBool equals(const UnicodeString& source, const UnicodeString& target) const;
598 
609  virtual ECollationStrength getStrength(void) const;
610 
629  virtual void setStrength(ECollationStrength newStrength);
630 
646  virtual int32_t getReorderCodes(int32_t *dest,
647  int32_t destCapacity,
648  UErrorCode& status) const;
649 
664  virtual void setReorderCodes(const int32_t* reorderCodes,
665  int32_t reorderCodesLength,
666  UErrorCode& status) ;
667 
686  static int32_t U_EXPORT2 getEquivalentReorderCodes(int32_t reorderCode,
687  int32_t* dest,
688  int32_t destCapacity,
689  UErrorCode& status);
690 
700  static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
701  const Locale& displayLocale,
702  UnicodeString& name);
703 
712  static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
713  UnicodeString& name);
714 
726  static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
727 
736  static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
737 
747  static StringEnumeration* U_EXPORT2 getKeywords(UErrorCode& status);
748 
760  static StringEnumeration* U_EXPORT2 getKeywordValues(const char *keyword, UErrorCode& status);
761 
778  static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* keyword, const Locale& locale,
779  UBool commonlyUsed, UErrorCode& status);
780 
808  static Locale U_EXPORT2 getFunctionalEquivalent(const char* keyword, const Locale& locale,
809  UBool& isAvailable, UErrorCode& status);
810 
811 #if !UCONFIG_NO_SERVICE
812 
820  static URegistryKey U_EXPORT2 registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status);
821 
829  static URegistryKey U_EXPORT2 registerFactory(CollatorFactory* toAdopt, UErrorCode& status);
830 
841  static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
842 #endif /* UCONFIG_NO_SERVICE */
843 
849  virtual void getVersion(UVersionInfo info) const = 0;
850 
861  virtual UClassID getDynamicClassID(void) const = 0;
862 
871  virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
872  UErrorCode &status) = 0;
873 
882  virtual UColAttributeValue getAttribute(UColAttribute attr,
883  UErrorCode &status) const = 0;
884 
895  virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status) = 0;
896 
906  virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) = 0;
907 
915  virtual void setVariableTop(uint32_t varTop, UErrorCode &status) = 0;
916 
923  virtual uint32_t getVariableTop(UErrorCode &status) const = 0;
924 
934  virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
935 
943  virtual Collator* safeClone(void) const;
944 
957  virtual int32_t getSortKey(const UnicodeString& source,
958  uint8_t* result,
959  int32_t resultLength) const = 0;
960 
976  virtual int32_t getSortKey(const UChar*source, int32_t sourceLength,
977  uint8_t*result, int32_t resultLength) const = 0;
978 
1016  static int32_t U_EXPORT2 getBound(const uint8_t *source,
1017  int32_t sourceLength,
1018  UColBoundMode boundType,
1019  uint32_t noOfLevels,
1020  uint8_t *result,
1021  int32_t resultLength,
1022  UErrorCode &status);
1023 
1024 
1025 protected:
1026 
1027  // Collator protected constructors -------------------------------------
1028 
1036  Collator();
1037 
1038 #ifndef U_HIDE_DEPRECATED_API
1039 
1050  Collator(UCollationStrength collationStrength,
1051  UNormalizationMode decompositionMode);
1052 #endif /* U_HIDE_DEPRECATED_API */
1053 
1059  Collator(const Collator& other);
1060 
1061  // Collator protected methods -----------------------------------------
1062 
1063 
1071  virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
1072 
1073 public:
1074 #if !UCONFIG_NO_SERVICE
1075 #ifndef U_HIDE_INTERNAL_API
1076 
1080  static UCollator* createUCollator(const char* loc, UErrorCode* status);
1081 #endif /* U_HIDE_INTERNAL_API */
1082 #endif
1083 
1107  virtual int32_t internalGetShortDefinitionString(const char *locale,
1108  char *buffer,
1109  int32_t capacity,
1110  UErrorCode &status) const;
1111 private:
1116  Collator& operator=(const Collator& other);
1117 
1118  friend class CFactory;
1119  friend class SimpleCFactory;
1120  friend class ICUCollatorFactory;
1121  friend class ICUCollatorService;
1122  static Collator* makeInstance(const Locale& desiredLocale,
1123  UErrorCode& status);
1124 
1125  // Collator private data members ---------------------------------------
1126 
1127  /*
1128  synwee : removed as attributes to be handled by child class
1129  UCollationStrength strength;
1130  Normalizer::EMode decmp;
1131  */
1132  /* This is useless information */
1133 /* static const UVersionInfo fVersion;*/
1134 };
1135 
1136 #if !UCONFIG_NO_SERVICE
1137 
1154 public:
1155 
1160  virtual ~CollatorFactory();
1161 
1169  virtual UBool visible(void) const;
1170 
1178  virtual Collator* createCollator(const Locale& loc) = 0;
1179 
1190  virtual UnicodeString& getDisplayName(const Locale& objectLocale,
1191  const Locale& displayLocale,
1192  UnicodeString& result);
1193 
1203  virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
1204 };
1205 #endif /* UCONFIG_NO_SERVICE */
1206 
1207 // Collator inline methods -----------------------------------------------
1208 
1210 
1211 #endif /* #if !UCONFIG_NO_COLLATION */
1212 
1213 #endif
uint8_t UVersionInfo[U_MAX_VERSION_LENGTH]
The binary form of a version on ICU APIs is an array of 4 uint8_t.
Definition: uversion.h:57
string a < string b
Definition: ucol.h:83
The Collator class performs locale-sensitive string comparison.
Definition: coll.h:177
UCollationResult
UCOL_LESS is returned if source string is compared to be less than target string in the u_strcoll() m...
Definition: ucol.h:77
UNormalizationMode
Constants for normalization modes.
Definition: unorm.h:133
C++ API: Unicode Normalization.
virtual UClassID getDynamicClassID() const =0
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
A factory, used with registerFactory, the creates multiple collators and provides display names for t...
Definition: coll.h:1153
C API:misc definitions.
C API for code unit iteration.
Definition: uiter.h:339
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:55
string a == string b
Definition: ucol.h:79
ECollationStrength
Base letter represents a primary difference.
Definition: coll.h:207
UColAttribute
Attributes that collation service understands.
Definition: ucol.h:240
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:358
C++ API: StringPiece: Read-only byte string wrapper class.
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
Secondary collation strength.
Definition: ucol.h:100
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
EComparisonResult
LESS is returned if source string is compared to be less than target string in the compare() method...
Definition: coll.h:226
C API: Collator.
Collation keys are generated by the Collator class.
Definition: sortkey.h:97
Tertiary collation strength.
Definition: ucol.h:102
A mutable set of Unicode characters and multicharacter strings.
Definition: uniset.h:273
C API: Unicode Character Iteration.
C++ API: Common ICU base class UObject.
const void * URegistryKey
Opaque type returned by registerInstance, registerFactory and unregister for service registration...
Definition: umisc.h:55
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition: umachine.h:278
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
string a > string b
Definition: ucol.h:81
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested...
Definition: uloc.h:336
UColBoundMode
enum that is taken by ucol_getBound API See below for explanation do not change the values assigned t...
Definition: ucol.h:1013
C++ API: Locale ID object.
struct UCollator UCollator
structure representing a collator object instance
Definition: ucol.h:62
Basic definitions for ICU, for both C and C++ APIs.
Identical collation strength.
Definition: ucol.h:109
Quaternary collation strength.
Definition: ucol.h:107
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:246
UColAttributeValue
Enum containing attribute values for controling collation behavior.
Definition: ucol.h:93
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:52
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:229
Primary collation strength.
Definition: ucol.h:98
int8_t UBool
The ICU boolean type.
Definition: umachine.h:200
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:182
C++ API: Unicode Set.