ICU 65.1  65.1
coll.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ******************************************************************************
5 * Copyright (C) 1996-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ******************************************************************************
8 */
9 
52 #ifndef COLL_H
53 #define COLL_H
54 
55 #include "unicode/utypes.h"
56 
57 #if U_SHOW_CPLUSPLUS_API
58 
59 #if !UCONFIG_NO_COLLATION
60 
61 #include "unicode/uobject.h"
62 #include "unicode/ucol.h"
63 #include "unicode/unorm.h"
64 #include "unicode/locid.h"
65 #include "unicode/uniset.h"
66 #include "unicode/umisc.h"
67 #include "unicode/uiter.h"
68 #include "unicode/stringpiece.h"
69 
70 U_NAMESPACE_BEGIN
71 
72 class StringEnumeration;
73 
74 #if !UCONFIG_NO_SERVICE
75 
78 class CollatorFactory;
79 #endif
80 
84 class CollationKey;
85 
167 class U_I18N_API Collator : public UObject {
168 public:
169 
170  // Collator public enums -----------------------------------------------
171 
198  {
199  PRIMARY = UCOL_PRIMARY, // 0
200  SECONDARY = UCOL_SECONDARY, // 1
201  TERTIARY = UCOL_TERTIARY, // 2
202  QUATERNARY = UCOL_QUATERNARY, // 3
203  IDENTICAL = UCOL_IDENTICAL // 15
204  };
205 
206 
207  // Cannot use #ifndef U_HIDE_DEPRECATED_API for the following, it is
208  // used by virtual methods that cannot have that conditional.
220  {
221  LESS = UCOL_LESS, // -1
222  EQUAL = UCOL_EQUAL, // 0
223  GREATER = UCOL_GREATER // 1
224  };
225 
226  // Collator public destructor -----------------------------------------
227 
232  virtual ~Collator();
233 
234  // Collator public methods --------------------------------------------
235 
254  virtual UBool operator==(const Collator& other) const;
255 
263  virtual UBool operator!=(const Collator& other) const;
264 
270  virtual Collator* clone() const = 0;
271 
291  static Collator* U_EXPORT2 createInstance(UErrorCode& err);
292 
326  static Collator* U_EXPORT2 createInstance(const Locale& loc, UErrorCode& err);
327 
339  virtual EComparisonResult compare(const UnicodeString& source,
340  const UnicodeString& target) const;
341 
354  virtual UCollationResult compare(const UnicodeString& source,
355  const UnicodeString& target,
356  UErrorCode &status) const = 0;
357 
370  virtual EComparisonResult compare(const UnicodeString& source,
371  const UnicodeString& target,
372  int32_t length) const;
373 
387  virtual UCollationResult compare(const UnicodeString& source,
388  const UnicodeString& target,
389  int32_t length,
390  UErrorCode &status) const = 0;
391 
425  virtual EComparisonResult compare(const char16_t* source, int32_t sourceLength,
426  const char16_t* target, int32_t targetLength)
427  const;
428 
445  virtual UCollationResult compare(const char16_t* source, int32_t sourceLength,
446  const char16_t* target, int32_t targetLength,
447  UErrorCode &status) const = 0;
448 
460  virtual UCollationResult compare(UCharIterator &sIter,
461  UCharIterator &tIter,
462  UErrorCode &status) const;
463 
477  virtual UCollationResult compareUTF8(const StringPiece &source,
478  const StringPiece &target,
479  UErrorCode &status) const;
480 
499  virtual CollationKey& getCollationKey(const UnicodeString& source,
500  CollationKey& key,
501  UErrorCode& status) const = 0;
502 
522  virtual CollationKey& getCollationKey(const char16_t*source,
523  int32_t sourceLength,
524  CollationKey& key,
525  UErrorCode& status) const = 0;
530  virtual int32_t hashCode(void) const = 0;
531 
544  virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0;
545 
555  UBool greater(const UnicodeString& source, const UnicodeString& target)
556  const;
557 
567  UBool greaterOrEqual(const UnicodeString& source,
568  const UnicodeString& target) const;
569 
579  UBool equals(const UnicodeString& source, const UnicodeString& target) const;
580 
591  virtual ECollationStrength getStrength(void) const;
592 
611  virtual void setStrength(ECollationStrength newStrength);
612 
628  virtual int32_t getReorderCodes(int32_t *dest,
629  int32_t destCapacity,
630  UErrorCode& status) const;
631 
647  virtual void setReorderCodes(const int32_t* reorderCodes,
648  int32_t reorderCodesLength,
649  UErrorCode& status) ;
650 
671  static int32_t U_EXPORT2 getEquivalentReorderCodes(int32_t reorderCode,
672  int32_t* dest,
673  int32_t destCapacity,
674  UErrorCode& status);
675 
685  static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
686  const Locale& displayLocale,
687  UnicodeString& name);
688 
697  static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
698  UnicodeString& name);
699 
711  static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
712 
721  static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
722 
732  static StringEnumeration* U_EXPORT2 getKeywords(UErrorCode& status);
733 
745  static StringEnumeration* U_EXPORT2 getKeywordValues(const char *keyword, UErrorCode& status);
746 
763  static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* keyword, const Locale& locale,
764  UBool commonlyUsed, UErrorCode& status);
765 
793  static Locale U_EXPORT2 getFunctionalEquivalent(const char* keyword, const Locale& locale,
794  UBool& isAvailable, UErrorCode& status);
795 
796 #if !UCONFIG_NO_SERVICE
797 
808  static URegistryKey U_EXPORT2 registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status);
809 
820  static URegistryKey U_EXPORT2 registerFactory(CollatorFactory* toAdopt, UErrorCode& status);
821 
835  static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
836 #endif /* UCONFIG_NO_SERVICE */
837 
843  virtual void getVersion(UVersionInfo info) const = 0;
844 
855  virtual UClassID getDynamicClassID(void) const = 0;
856 
865  virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
866  UErrorCode &status) = 0;
867 
876  virtual UColAttributeValue getAttribute(UColAttribute attr,
877  UErrorCode &status) const = 0;
878 
897  virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCode);
898 
907  virtual UColReorderCode getMaxVariable() const;
908 
925  virtual uint32_t setVariableTop(const char16_t *varTop, int32_t len, UErrorCode &status) = 0;
926 
942  virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) = 0;
943 
955  virtual void setVariableTop(uint32_t varTop, UErrorCode &status) = 0;
956 
964  virtual uint32_t getVariableTop(UErrorCode &status) const = 0;
965 
975  virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
976 
984  virtual Collator* safeClone() const;
985 
1002  virtual int32_t getSortKey(const UnicodeString& source,
1003  uint8_t* result,
1004  int32_t resultLength) const = 0;
1005 
1025  virtual int32_t getSortKey(const char16_t*source, int32_t sourceLength,
1026  uint8_t*result, int32_t resultLength) const = 0;
1027 
1065  static int32_t U_EXPORT2 getBound(const uint8_t *source,
1066  int32_t sourceLength,
1067  UColBoundMode boundType,
1068  uint32_t noOfLevels,
1069  uint8_t *result,
1070  int32_t resultLength,
1071  UErrorCode &status);
1072 
1073 
1074 protected:
1075 
1076  // Collator protected constructors -------------------------------------
1077 
1085  Collator();
1086 
1087 #ifndef U_HIDE_DEPRECATED_API
1088 
1099  Collator(UCollationStrength collationStrength,
1100  UNormalizationMode decompositionMode);
1101 #endif /* U_HIDE_DEPRECATED_API */
1102 
1108  Collator(const Collator& other);
1109 
1110 public:
1118  virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
1119 
1143  virtual int32_t internalGetShortDefinitionString(const char *locale,
1144  char *buffer,
1145  int32_t capacity,
1146  UErrorCode &status) const;
1147 
1152  virtual UCollationResult internalCompareUTF8(
1153  const char *left, int32_t leftLength,
1154  const char *right, int32_t rightLength,
1155  UErrorCode &errorCode) const;
1156 
1161  virtual int32_t
1162  internalNextSortKeyPart(
1163  UCharIterator *iter, uint32_t state[2],
1164  uint8_t *dest, int32_t count, UErrorCode &errorCode) const;
1165 
1166 #ifndef U_HIDE_INTERNAL_API
1167 
1168  static inline Collator *fromUCollator(UCollator *uc) {
1169  return reinterpret_cast<Collator *>(uc);
1170  }
1172  static inline const Collator *fromUCollator(const UCollator *uc) {
1173  return reinterpret_cast<const Collator *>(uc);
1174  }
1177  return reinterpret_cast<UCollator *>(this);
1178  }
1180  inline const UCollator *toUCollator() const {
1181  return reinterpret_cast<const UCollator *>(this);
1182  }
1183 #endif // U_HIDE_INTERNAL_API
1184 
1185 private:
1189  Collator& operator=(const Collator& other);
1190 
1191  friend class CFactory;
1192  friend class SimpleCFactory;
1193  friend class ICUCollatorFactory;
1194  friend class ICUCollatorService;
1195  static Collator* makeInstance(const Locale& desiredLocale,
1196  UErrorCode& status);
1197 };
1198 
1199 #if !UCONFIG_NO_SERVICE
1200 
1217 public:
1218 
1223  virtual ~CollatorFactory();
1224 
1232  virtual UBool visible(void) const;
1233 
1241  virtual Collator* createCollator(const Locale& loc) = 0;
1242 
1253  virtual UnicodeString& getDisplayName(const Locale& objectLocale,
1254  const Locale& displayLocale,
1255  UnicodeString& result);
1256 
1266  virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
1267 };
1268 #endif /* UCONFIG_NO_SERVICE */
1269 
1270 // Collator inline methods -----------------------------------------------
1271 
1272 U_NAMESPACE_END
1273 
1274 #endif /* #if !UCONFIG_NO_COLLATION */
1275 
1276 #endif /* U_SHOW_CPLUSPLUS_API */
1277 
1278 #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:59
string a < string b
Definition: ucol.h:79
The Collator class performs locale-sensitive string comparison.
Definition: coll.h:167
const UCollator * toUCollator() const
Definition: coll.h:1180
UCollationResult
UCOL_LESS is returned if source string is compared to be less than target string in the ucol_strcoll(...
Definition: ucol.h:73
UNormalizationMode
Constants for normalization modes.
Definition: unorm.h:138
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:96
A factory, used with registerFactory, the creates multiple collators and provides display names for t...
Definition: coll.h:1216
C API:misc definitions.
C API for code unit iteration.
Definition: uiter.h:341
Base class for &#39;pure&#39; C++ implementations of uenum api.
Definition: strenum.h:61
string a == string b
Definition: ucol.h:75
static const Collator * fromUCollator(const UCollator *uc)
Definition: coll.h:1172
ECollationStrength
Base letter represents a primary difference.
Definition: coll.h:197
UColReorderCode
Enum containing the codes for reordering segments of the collation table that are not script codes...
Definition: ucol.h:146
UColAttribute
Attributes that collation service understands.
Definition: ucol.h:242
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
UCollator * toUCollator()
Definition: coll.h:1176
C++ API: StringPiece: Read-only byte string wrapper class.
Secondary collation strength.
Definition: ucol.h:96
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:251
C API: Unicode Normalization.
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
EComparisonResult
LESS is returned if source string is compared to be less than target string in the compare() method...
Definition: coll.h:219
C API: Collator.
Collation keys are generated by the Collator class.
Definition: sortkey.h:101
Tertiary collation strength.
Definition: ucol.h:98
A mutable set of Unicode characters and multicharacter strings.
Definition: uniset.h:281
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:57
string a > string b
Definition: ucol.h:77
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested...
Definition: uloc.h:338
UColBoundMode
enum that is taken by ucol_getBound API See below for explanation do not change the values assigned t...
Definition: ucol.h:1057
C++ API: Locale ID object.
struct UCollator UCollator
structure representing a collator object instance
Definition: ucol.h:58
Basic definitions for ICU, for both C and C++ APIs.
static Collator * fromUCollator(UCollator *uc)
Definition: coll.h:1168
Identical collation strength.
Definition: ucol.h:105
Quaternary collation strength.
Definition: ucol.h:103
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:294
UColAttributeValue
Enum containing attribute values for controling collation behavior.
Definition: ucol.h:89
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:60
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
Primary collation strength.
Definition: ucol.h:94
int8_t UBool
The ICU boolean type.
Definition: umachine.h:260
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
C++ API: Unicode Set.