ICU 57.1  57.1
coll.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 * Copyright (C) 1996-2016, 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 
202 
203  // Cannot use #ifndef U_HIDE_DEPRECATED_API for the following, it is
204  // used by virtual methods that cannot have that conditional.
216  {
217  LESS = UCOL_LESS, // -1
218  EQUAL = UCOL_EQUAL, // 0
219  GREATER = UCOL_GREATER // 1
220  };
221 
222  // Collator public destructor -----------------------------------------
223 
228  virtual ~Collator();
229 
230  // Collator public methods --------------------------------------------
231 
250  virtual UBool operator==(const Collator& other) const;
251 
259  virtual UBool operator!=(const Collator& other) const;
260 
266  virtual Collator* clone(void) const = 0;
267 
287  static Collator* U_EXPORT2 createInstance(UErrorCode& err);
288 
322  static Collator* U_EXPORT2 createInstance(const Locale& loc, UErrorCode& err);
323 
335  virtual EComparisonResult compare(const UnicodeString& source,
336  const UnicodeString& target) const;
337 
350  virtual UCollationResult compare(const UnicodeString& source,
351  const UnicodeString& target,
352  UErrorCode &status) const = 0;
353 
366  virtual EComparisonResult compare(const UnicodeString& source,
367  const UnicodeString& target,
368  int32_t length) const;
369 
383  virtual UCollationResult compare(const UnicodeString& source,
384  const UnicodeString& target,
385  int32_t length,
386  UErrorCode &status) const = 0;
387 
421  virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
422  const UChar* target, int32_t targetLength)
423  const;
424 
441  virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
442  const UChar* target, int32_t targetLength,
443  UErrorCode &status) const = 0;
444 
456  virtual UCollationResult compare(UCharIterator &sIter,
457  UCharIterator &tIter,
458  UErrorCode &status) const;
459 
473  virtual UCollationResult compareUTF8(const StringPiece &source,
474  const StringPiece &target,
475  UErrorCode &status) const;
476 
495  virtual CollationKey& getCollationKey(const UnicodeString& source,
496  CollationKey& key,
497  UErrorCode& status) const = 0;
498 
518  virtual CollationKey& getCollationKey(const UChar*source,
519  int32_t sourceLength,
520  CollationKey& key,
521  UErrorCode& status) const = 0;
526  virtual int32_t hashCode(void) const = 0;
527 
540  virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0;
541 
551  UBool greater(const UnicodeString& source, const UnicodeString& target)
552  const;
553 
563  UBool greaterOrEqual(const UnicodeString& source,
564  const UnicodeString& target) const;
565 
575  UBool equals(const UnicodeString& source, const UnicodeString& target) const;
576 
587  virtual ECollationStrength getStrength(void) const;
588 
607  virtual void setStrength(ECollationStrength newStrength);
608 
624  virtual int32_t getReorderCodes(int32_t *dest,
625  int32_t destCapacity,
626  UErrorCode& status) const;
627 
643  virtual void setReorderCodes(const int32_t* reorderCodes,
644  int32_t reorderCodesLength,
645  UErrorCode& status) ;
646 
667  static int32_t U_EXPORT2 getEquivalentReorderCodes(int32_t reorderCode,
668  int32_t* dest,
669  int32_t destCapacity,
670  UErrorCode& status);
671 
681  static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
682  const Locale& displayLocale,
683  UnicodeString& name);
684 
693  static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
694  UnicodeString& name);
695 
707  static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
708 
717  static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
718 
728  static StringEnumeration* U_EXPORT2 getKeywords(UErrorCode& status);
729 
741  static StringEnumeration* U_EXPORT2 getKeywordValues(const char *keyword, UErrorCode& status);
742 
759  static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* keyword, const Locale& locale,
760  UBool commonlyUsed, UErrorCode& status);
761 
789  static Locale U_EXPORT2 getFunctionalEquivalent(const char* keyword, const Locale& locale,
790  UBool& isAvailable, UErrorCode& status);
791 
792 #if !UCONFIG_NO_SERVICE
793 
804  static URegistryKey U_EXPORT2 registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status);
805 
816  static URegistryKey U_EXPORT2 registerFactory(CollatorFactory* toAdopt, UErrorCode& status);
817 
831  static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
832 #endif /* UCONFIG_NO_SERVICE */
833 
839  virtual void getVersion(UVersionInfo info) const = 0;
840 
851  virtual UClassID getDynamicClassID(void) const = 0;
852 
861  virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
862  UErrorCode &status) = 0;
863 
872  virtual UColAttributeValue getAttribute(UColAttribute attr,
873  UErrorCode &status) const = 0;
874 
893  virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCode);
894 
903  virtual UColReorderCode getMaxVariable() const;
904 
921  virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status) = 0;
922 
938  virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) = 0;
939 
951  virtual void setVariableTop(uint32_t varTop, UErrorCode &status) = 0;
952 
960  virtual uint32_t getVariableTop(UErrorCode &status) const = 0;
961 
971  virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
972 
980  virtual Collator* safeClone(void) const;
981 
998  virtual int32_t getSortKey(const UnicodeString& source,
999  uint8_t* result,
1000  int32_t resultLength) const = 0;
1001 
1021  virtual int32_t getSortKey(const UChar*source, int32_t sourceLength,
1022  uint8_t*result, int32_t resultLength) const = 0;
1023 
1061  static int32_t U_EXPORT2 getBound(const uint8_t *source,
1062  int32_t sourceLength,
1063  UColBoundMode boundType,
1064  uint32_t noOfLevels,
1065  uint8_t *result,
1066  int32_t resultLength,
1067  UErrorCode &status);
1068 
1069 
1070 protected:
1071 
1072  // Collator protected constructors -------------------------------------
1073 
1081  Collator();
1082 
1083 #ifndef U_HIDE_DEPRECATED_API
1084 
1095  Collator(UCollationStrength collationStrength,
1096  UNormalizationMode decompositionMode);
1097 #endif /* U_HIDE_DEPRECATED_API */
1098 
1104  Collator(const Collator& other);
1105 
1106 public:
1114  virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
1115 
1139  virtual int32_t internalGetShortDefinitionString(const char *locale,
1140  char *buffer,
1141  int32_t capacity,
1142  UErrorCode &status) const;
1143 
1148  virtual UCollationResult internalCompareUTF8(
1149  const char *left, int32_t leftLength,
1150  const char *right, int32_t rightLength,
1151  UErrorCode &errorCode) const;
1152 
1157  virtual int32_t
1158  internalNextSortKeyPart(
1159  UCharIterator *iter, uint32_t state[2],
1160  uint8_t *dest, int32_t count, UErrorCode &errorCode) const;
1161 
1162 #ifndef U_HIDE_INTERNAL_API
1163 
1164  static inline Collator *fromUCollator(UCollator *uc) {
1165  return reinterpret_cast<Collator *>(uc);
1166  }
1168  static inline const Collator *fromUCollator(const UCollator *uc) {
1169  return reinterpret_cast<const Collator *>(uc);
1170  }
1173  return reinterpret_cast<UCollator *>(this);
1174  }
1176  inline const UCollator *toUCollator() const {
1177  return reinterpret_cast<const UCollator *>(this);
1178  }
1179 #endif // U_HIDE_INTERNAL_API
1180 
1181 private:
1185  Collator& operator=(const Collator& other);
1186 
1187  friend class CFactory;
1188  friend class SimpleCFactory;
1189  friend class ICUCollatorFactory;
1190  friend class ICUCollatorService;
1191  static Collator* makeInstance(const Locale& desiredLocale,
1192  UErrorCode& status);
1193 };
1194 
1195 #if !UCONFIG_NO_SERVICE
1196 
1213 public:
1214 
1219  virtual ~CollatorFactory();
1220 
1228  virtual UBool visible(void) const;
1229 
1237  virtual Collator* createCollator(const Locale& loc) = 0;
1238 
1249  virtual UnicodeString& getDisplayName(const Locale& objectLocale,
1250  const Locale& displayLocale,
1251  UnicodeString& result);
1252 
1262  virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
1263 };
1264 #endif /* UCONFIG_NO_SERVICE */
1265 
1266 // Collator inline methods -----------------------------------------------
1267 
1269 
1270 #endif /* #if !UCONFIG_NO_COLLATION */
1271 
1272 #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 &lt; string b
Definition: ucol.h:77
The Collator class performs locale-sensitive string comparison.
Definition: coll.h:163
virtual UClassID getDynamicClassID() const
ICU4C &quot;poor man&#39;s RTTI&quot;, 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:1176
UNormalizationMode
Constants for normalization modes.
Definition: unorm.h:136
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&#39;s RTTI.
Definition: uobject.h:91
A factory, used with registerFactory, the creates multiple collators and provides display names for t...
Definition: coll.h:1212
C API:misc definitions.
C API for code unit iteration.
Definition: uiter.h:339
Base class for &#39;pure&#39; 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:1168
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:1172
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:215
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 &gt; 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:1046
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:1164
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:293
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 &quot;boilerplate&quot; 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.