ICU 53.1  53.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
171 class U_I18N_API Collator : public UObject {
172 public:
173 
174  // Collator public enums -----------------------------------------------
175 
202  {
203  PRIMARY = UCOL_PRIMARY, // 0
204  SECONDARY = UCOL_SECONDARY, // 1
205  TERTIARY = UCOL_TERTIARY, // 2
206  QUATERNARY = UCOL_QUATERNARY, // 3
207  IDENTICAL = UCOL_IDENTICAL // 15
208  };
209 
221  {
222  LESS = UCOL_LESS, // -1
223  EQUAL = UCOL_EQUAL, // 0
224  GREATER = UCOL_GREATER // 1
225  };
226 
227  // Collator public destructor -----------------------------------------
228 
233  virtual ~Collator();
234 
235  // Collator public methods --------------------------------------------
236 
255  virtual UBool operator==(const Collator& other) const;
256 
264  virtual UBool operator!=(const Collator& other) const;
265 
271  virtual Collator* clone(void) const = 0;
272 
292  static Collator* U_EXPORT2 createInstance(UErrorCode& err);
293 
317  static Collator* U_EXPORT2 createInstance(const Locale& loc, UErrorCode& err);
318 
330  virtual EComparisonResult compare(const UnicodeString& source,
331  const UnicodeString& target) const;
332 
345  virtual UCollationResult compare(const UnicodeString& source,
346  const UnicodeString& target,
347  UErrorCode &status) const = 0;
348 
361  virtual EComparisonResult compare(const UnicodeString& source,
362  const UnicodeString& target,
363  int32_t length) const;
364 
378  virtual UCollationResult compare(const UnicodeString& source,
379  const UnicodeString& target,
380  int32_t length,
381  UErrorCode &status) const = 0;
382 
416  virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
417  const UChar* target, int32_t targetLength)
418  const;
419 
436  virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
437  const UChar* target, int32_t targetLength,
438  UErrorCode &status) const = 0;
439 
451  virtual UCollationResult compare(UCharIterator &sIter,
452  UCharIterator &tIter,
453  UErrorCode &status) const;
454 
468  virtual UCollationResult compareUTF8(const StringPiece &source,
469  const StringPiece &target,
470  UErrorCode &status) const;
471 
487  virtual CollationKey& getCollationKey(const UnicodeString& source,
488  CollationKey& key,
489  UErrorCode& status) const = 0;
490 
507  virtual CollationKey& getCollationKey(const UChar*source,
508  int32_t sourceLength,
509  CollationKey& key,
510  UErrorCode& status) const = 0;
515  virtual int32_t hashCode(void) const = 0;
516 
529  virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0;
530 
540  UBool greater(const UnicodeString& source, const UnicodeString& target)
541  const;
542 
552  UBool greaterOrEqual(const UnicodeString& source,
553  const UnicodeString& target) const;
554 
564  UBool equals(const UnicodeString& source, const UnicodeString& target) const;
565 
576  virtual ECollationStrength getStrength(void) const;
577 
596  virtual void setStrength(ECollationStrength newStrength);
597 
613  virtual int32_t getReorderCodes(int32_t *dest,
614  int32_t destCapacity,
615  UErrorCode& status) const;
616 
631  virtual void setReorderCodes(const int32_t* reorderCodes,
632  int32_t reorderCodesLength,
633  UErrorCode& status) ;
634 
653  static int32_t U_EXPORT2 getEquivalentReorderCodes(int32_t reorderCode,
654  int32_t* dest,
655  int32_t destCapacity,
656  UErrorCode& status);
657 
667  static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
668  const Locale& displayLocale,
669  UnicodeString& name);
670 
679  static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
680  UnicodeString& name);
681 
693  static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
694 
703  static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
704 
714  static StringEnumeration* U_EXPORT2 getKeywords(UErrorCode& status);
715 
727  static StringEnumeration* U_EXPORT2 getKeywordValues(const char *keyword, UErrorCode& status);
728 
745  static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* keyword, const Locale& locale,
746  UBool commonlyUsed, UErrorCode& status);
747 
775  static Locale U_EXPORT2 getFunctionalEquivalent(const char* keyword, const Locale& locale,
776  UBool& isAvailable, UErrorCode& status);
777 
778 #if !UCONFIG_NO_SERVICE
779 
790  static URegistryKey U_EXPORT2 registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status);
791 
802  static URegistryKey U_EXPORT2 registerFactory(CollatorFactory* toAdopt, UErrorCode& status);
803 
817  static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
818 #endif /* UCONFIG_NO_SERVICE */
819 
825  virtual void getVersion(UVersionInfo info) const = 0;
826 
837  virtual UClassID getDynamicClassID(void) const = 0;
838 
847  virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
848  UErrorCode &status) = 0;
849 
858  virtual UColAttributeValue getAttribute(UColAttribute attr,
859  UErrorCode &status) const = 0;
860 
861  /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft methods since they are virtual */
880  virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCode);
881 
890  virtual UColReorderCode getMaxVariable() const;
891 
908  virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status) = 0;
909 
925  virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) = 0;
926 
938  virtual void setVariableTop(uint32_t varTop, UErrorCode &status) = 0;
939 
947  virtual uint32_t getVariableTop(UErrorCode &status) const = 0;
948 
958  virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
959 
967  virtual Collator* safeClone(void) const;
968 
981  virtual int32_t getSortKey(const UnicodeString& source,
982  uint8_t* result,
983  int32_t resultLength) const = 0;
984 
1000  virtual int32_t getSortKey(const UChar*source, int32_t sourceLength,
1001  uint8_t*result, int32_t resultLength) const = 0;
1002 
1040  static int32_t U_EXPORT2 getBound(const uint8_t *source,
1041  int32_t sourceLength,
1042  UColBoundMode boundType,
1043  uint32_t noOfLevels,
1044  uint8_t *result,
1045  int32_t resultLength,
1046  UErrorCode &status);
1047 
1048 
1049 protected:
1050 
1051  // Collator protected constructors -------------------------------------
1052 
1060  Collator();
1061 
1062 #ifndef U_HIDE_DEPRECATED_API
1063 
1074  Collator(UCollationStrength collationStrength,
1075  UNormalizationMode decompositionMode);
1076 #endif /* U_HIDE_DEPRECATED_API */
1077 
1083  Collator(const Collator& other);
1084 
1085 public:
1093  virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
1094 
1118  virtual int32_t internalGetShortDefinitionString(const char *locale,
1119  char *buffer,
1120  int32_t capacity,
1121  UErrorCode &status) const;
1122 
1127  virtual UCollationResult internalCompareUTF8(
1128  const char *left, int32_t leftLength,
1129  const char *right, int32_t rightLength,
1130  UErrorCode &errorCode) const;
1131 
1136  virtual int32_t
1137  internalNextSortKeyPart(
1138  UCharIterator *iter, uint32_t state[2],
1139  uint8_t *dest, int32_t count, UErrorCode &errorCode) const;
1140 
1141 #ifndef U_HIDE_INTERNAL_API
1142 
1143  static inline Collator *fromUCollator(UCollator *uc) {
1144  return reinterpret_cast<Collator *>(uc);
1145  }
1147  static inline const Collator *fromUCollator(const UCollator *uc) {
1148  return reinterpret_cast<const Collator *>(uc);
1149  }
1152  return reinterpret_cast<UCollator *>(this);
1153  }
1155  inline const UCollator *toUCollator() const {
1156  return reinterpret_cast<const UCollator *>(this);
1157  }
1158 #endif // U_HIDE_INTERNAL_API
1159 
1160 private:
1164  Collator& operator=(const Collator& other);
1165 
1166  friend class CFactory;
1167  friend class SimpleCFactory;
1168  friend class ICUCollatorFactory;
1169  friend class ICUCollatorService;
1170  static Collator* makeInstance(const Locale& desiredLocale,
1171  UErrorCode& status);
1172 };
1173 
1174 #if !UCONFIG_NO_SERVICE
1175 
1192 public:
1193 
1198  virtual ~CollatorFactory();
1199 
1207  virtual UBool visible(void) const;
1208 
1216  virtual Collator* createCollator(const Locale& loc) = 0;
1217 
1228  virtual UnicodeString& getDisplayName(const Locale& objectLocale,
1229  const Locale& displayLocale,
1230  UnicodeString& result);
1231 
1241  virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
1242 };
1243 #endif /* UCONFIG_NO_SERVICE */
1244 
1245 // Collator inline methods -----------------------------------------------
1246 
1248 
1249 #endif /* #if !UCONFIG_NO_COLLATION */
1250 
1251 #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:171
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:1155
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:1191
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:1147
ECollationStrength
Base letter represents a primary difference.
Definition: coll.h:201
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:1151
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:220
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: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: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:1023
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:1143
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:200
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185
C++ API: Unicode Set.