ICU 54.1  54.1
coll.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 * Copyright (C) 1996-2014, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ******************************************************************************
6 */
7 
50 #ifndef COLL_H
51 #define COLL_H
52 
53 #include "unicode/utypes.h"
54 
55 #if !UCONFIG_NO_COLLATION
56 
57 #include "unicode/uobject.h"
58 #include "unicode/ucol.h"
59 #include "unicode/normlzr.h"
60 #include "unicode/locid.h"
61 #include "unicode/uniset.h"
62 #include "unicode/umisc.h"
63 #include "unicode/uiter.h"
64 #include "unicode/stringpiece.h"
65 
67 
68 class StringEnumeration;
69 
70 #if !UCONFIG_NO_SERVICE
71 
74 class CollatorFactory;
75 #endif
76 
80 class CollationKey;
81 
163 class U_I18N_API Collator : public UObject {
164 public:
165 
166  // Collator public enums -----------------------------------------------
167 
194  {
195  PRIMARY = UCOL_PRIMARY, // 0
196  SECONDARY = UCOL_SECONDARY, // 1
197  TERTIARY = UCOL_TERTIARY, // 2
198  QUATERNARY = UCOL_QUATERNARY, // 3
199  IDENTICAL = UCOL_IDENTICAL // 15
200  };
201 
213  {
214  LESS = UCOL_LESS, // -1
215  EQUAL = UCOL_EQUAL, // 0
216  GREATER = UCOL_GREATER // 1
217  };
218 
219  // Collator public destructor -----------------------------------------
220 
225  virtual ~Collator();
226 
227  // Collator public methods --------------------------------------------
228 
247  virtual UBool operator==(const Collator& other) const;
248 
256  virtual UBool operator!=(const Collator& other) const;
257 
263  virtual Collator* clone(void) const = 0;
264 
284  static Collator* U_EXPORT2 createInstance(UErrorCode& err);
285 
319  static Collator* U_EXPORT2 createInstance(const Locale& loc, UErrorCode& err);
320 
332  virtual EComparisonResult compare(const UnicodeString& source,
333  const UnicodeString& target) const;
334 
347  virtual UCollationResult compare(const UnicodeString& source,
348  const UnicodeString& target,
349  UErrorCode &status) const = 0;
350 
363  virtual EComparisonResult compare(const UnicodeString& source,
364  const UnicodeString& target,
365  int32_t length) const;
366 
380  virtual UCollationResult compare(const UnicodeString& source,
381  const UnicodeString& target,
382  int32_t length,
383  UErrorCode &status) const = 0;
384 
418  virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
419  const UChar* target, int32_t targetLength)
420  const;
421 
438  virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
439  const UChar* target, int32_t targetLength,
440  UErrorCode &status) const = 0;
441 
453  virtual UCollationResult compare(UCharIterator &sIter,
454  UCharIterator &tIter,
455  UErrorCode &status) const;
456 
470  virtual UCollationResult compareUTF8(const StringPiece &source,
471  const StringPiece &target,
472  UErrorCode &status) const;
473 
492  virtual CollationKey& getCollationKey(const UnicodeString& source,
493  CollationKey& key,
494  UErrorCode& status) const = 0;
495 
515  virtual CollationKey& getCollationKey(const UChar*source,
516  int32_t sourceLength,
517  CollationKey& key,
518  UErrorCode& status) const = 0;
523  virtual int32_t hashCode(void) const = 0;
524 
537  virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0;
538 
548  UBool greater(const UnicodeString& source, const UnicodeString& target)
549  const;
550 
560  UBool greaterOrEqual(const UnicodeString& source,
561  const UnicodeString& target) const;
562 
572  UBool equals(const UnicodeString& source, const UnicodeString& target) const;
573 
584  virtual ECollationStrength getStrength(void) const;
585 
604  virtual void setStrength(ECollationStrength newStrength);
605 
621  virtual int32_t getReorderCodes(int32_t *dest,
622  int32_t destCapacity,
623  UErrorCode& status) const;
624 
639  virtual void setReorderCodes(const int32_t* reorderCodes,
640  int32_t reorderCodesLength,
641  UErrorCode& status) ;
642 
661  static int32_t U_EXPORT2 getEquivalentReorderCodes(int32_t reorderCode,
662  int32_t* dest,
663  int32_t destCapacity,
664  UErrorCode& status);
665 
675  static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
676  const Locale& displayLocale,
677  UnicodeString& name);
678 
687  static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
688  UnicodeString& name);
689 
701  static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
702 
711  static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
712 
722  static StringEnumeration* U_EXPORT2 getKeywords(UErrorCode& status);
723 
735  static StringEnumeration* U_EXPORT2 getKeywordValues(const char *keyword, UErrorCode& status);
736 
753  static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* keyword, const Locale& locale,
754  UBool commonlyUsed, UErrorCode& status);
755 
783  static Locale U_EXPORT2 getFunctionalEquivalent(const char* keyword, const Locale& locale,
784  UBool& isAvailable, UErrorCode& status);
785 
786 #if !UCONFIG_NO_SERVICE
787 
798  static URegistryKey U_EXPORT2 registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status);
799 
810  static URegistryKey U_EXPORT2 registerFactory(CollatorFactory* toAdopt, UErrorCode& status);
811 
825  static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
826 #endif /* UCONFIG_NO_SERVICE */
827 
833  virtual void getVersion(UVersionInfo info) const = 0;
834 
845  virtual UClassID getDynamicClassID(void) const = 0;
846 
855  virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
856  UErrorCode &status) = 0;
857 
866  virtual UColAttributeValue getAttribute(UColAttribute attr,
867  UErrorCode &status) const = 0;
868 
869  /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft methods since they are virtual */
888  virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCode);
889 
898  virtual UColReorderCode getMaxVariable() const;
899 
916  virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status) = 0;
917 
933  virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) = 0;
934 
946  virtual void setVariableTop(uint32_t varTop, UErrorCode &status) = 0;
947 
955  virtual uint32_t getVariableTop(UErrorCode &status) const = 0;
956 
966  virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
967 
975  virtual Collator* safeClone(void) const;
976 
993  virtual int32_t getSortKey(const UnicodeString& source,
994  uint8_t* result,
995  int32_t resultLength) const = 0;
996 
1016  virtual int32_t getSortKey(const UChar*source, int32_t sourceLength,
1017  uint8_t*result, int32_t resultLength) const = 0;
1018 
1056  static int32_t U_EXPORT2 getBound(const uint8_t *source,
1057  int32_t sourceLength,
1058  UColBoundMode boundType,
1059  uint32_t noOfLevels,
1060  uint8_t *result,
1061  int32_t resultLength,
1062  UErrorCode &status);
1063 
1064 
1065 protected:
1066 
1067  // Collator protected constructors -------------------------------------
1068 
1076  Collator();
1077 
1078 #ifndef U_HIDE_DEPRECATED_API
1079 
1090  Collator(UCollationStrength collationStrength,
1091  UNormalizationMode decompositionMode);
1092 #endif /* U_HIDE_DEPRECATED_API */
1093 
1099  Collator(const Collator& other);
1100 
1101 public:
1109  virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
1110 
1134  virtual int32_t internalGetShortDefinitionString(const char *locale,
1135  char *buffer,
1136  int32_t capacity,
1137  UErrorCode &status) const;
1138 
1143  virtual UCollationResult internalCompareUTF8(
1144  const char *left, int32_t leftLength,
1145  const char *right, int32_t rightLength,
1146  UErrorCode &errorCode) const;
1147 
1152  virtual int32_t
1153  internalNextSortKeyPart(
1154  UCharIterator *iter, uint32_t state[2],
1155  uint8_t *dest, int32_t count, UErrorCode &errorCode) const;
1156 
1157 #ifndef U_HIDE_INTERNAL_API
1158 
1159  static inline Collator *fromUCollator(UCollator *uc) {
1160  return reinterpret_cast<Collator *>(uc);
1161  }
1163  static inline const Collator *fromUCollator(const UCollator *uc) {
1164  return reinterpret_cast<const Collator *>(uc);
1165  }
1168  return reinterpret_cast<UCollator *>(this);
1169  }
1171  inline const UCollator *toUCollator() const {
1172  return reinterpret_cast<const UCollator *>(this);
1173  }
1174 #endif // U_HIDE_INTERNAL_API
1175 
1176 private:
1180  Collator& operator=(const Collator& other);
1181 
1182  friend class CFactory;
1183  friend class SimpleCFactory;
1184  friend class ICUCollatorFactory;
1185  friend class ICUCollatorService;
1186  static Collator* makeInstance(const Locale& desiredLocale,
1187  UErrorCode& status);
1188 };
1189 
1190 #if !UCONFIG_NO_SERVICE
1191 
1208 public:
1209 
1214  virtual ~CollatorFactory();
1215 
1223  virtual UBool visible(void) const;
1224 
1232  virtual Collator* createCollator(const Locale& loc) = 0;
1233 
1244  virtual UnicodeString& getDisplayName(const Locale& objectLocale,
1245  const Locale& displayLocale,
1246  UnicodeString& result);
1247 
1257  virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
1258 };
1259 #endif /* UCONFIG_NO_SERVICE */
1260 
1261 // Collator inline methods -----------------------------------------------
1262 
1264 
1265 #endif /* #if !UCONFIG_NO_COLLATION */
1266 
1267 #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:77
The Collator class performs locale-sensitive string comparison.
Definition: coll.h:163
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
UCollationResult
UCOL_LESS is returned if source string is compared to be less than target string in the ucol_strcoll(...
Definition: ucol.h:71
const UCollator * toUCollator() const
Definition: coll.h:1171
UNormalizationMode
Constants for normalization modes.
Definition: unorm.h:133
C++ API: Unicode Normalization.
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:91
A factory, used with registerFactory, the creates multiple collators and provides display names for t...
Definition: coll.h:1207
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:73
static const Collator * fromUCollator(const UCollator *uc)
Definition: coll.h:1163
ECollationStrength
Base letter represents a primary difference.
Definition: coll.h:193
UColReorderCode
Enum containing the codes for reordering segments of the collation table that are not script codes...
Definition: ucol.h:139
UColAttribute
Attributes that collation service understands.
Definition: ucol.h:234
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:358
UCollator * toUCollator()
Definition: coll.h:1167
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:94
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:212
C API: Collator.
Collation keys are generated by the Collator class.
Definition: sortkey.h:97
Tertiary collation strength.
Definition: ucol.h:96
A mutable set of Unicode characters and multicharacter strings.
Definition: uniset.h:276
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:312
#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:75
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:1038
C++ API: Locale ID object.
struct UCollator UCollator
structure representing a collator object instance
Definition: ucol.h:56
Basic definitions for ICU, for both C and C++ APIs.
static Collator * fromUCollator(UCollator *uc)
Definition: coll.h:1159
Identical collation strength.
Definition: ucol.h:103
Quaternary collation strength.
Definition: ucol.h:101
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:245
UColAttributeValue
Enum containing attribute values for controling collation behavior.
Definition: ucol.h:87
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:221
Primary collation strength.
Definition: ucol.h:92
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185
C++ API: Unicode Set.