ICU 55.1  55.1
coll.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 * Copyright (C) 1996-2015, 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 
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 
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 
640  virtual void setReorderCodes(const int32_t* reorderCodes,
641  int32_t reorderCodesLength,
642  UErrorCode& status) ;
643 
664  static int32_t U_EXPORT2 getEquivalentReorderCodes(int32_t reorderCode,
665  int32_t* dest,
666  int32_t destCapacity,
667  UErrorCode& status);
668 
678  static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
679  const Locale& displayLocale,
680  UnicodeString& name);
681 
690  static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
691  UnicodeString& name);
692 
704  static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
705 
714  static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
715 
725  static StringEnumeration* U_EXPORT2 getKeywords(UErrorCode& status);
726 
738  static StringEnumeration* U_EXPORT2 getKeywordValues(const char *keyword, UErrorCode& status);
739 
756  static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* keyword, const Locale& locale,
757  UBool commonlyUsed, UErrorCode& status);
758 
786  static Locale U_EXPORT2 getFunctionalEquivalent(const char* keyword, const Locale& locale,
787  UBool& isAvailable, UErrorCode& status);
788 
789 #if !UCONFIG_NO_SERVICE
790 
801  static URegistryKey U_EXPORT2 registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status);
802 
813  static URegistryKey U_EXPORT2 registerFactory(CollatorFactory* toAdopt, UErrorCode& status);
814 
828  static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
829 #endif /* UCONFIG_NO_SERVICE */
830 
836  virtual void getVersion(UVersionInfo info) const = 0;
837 
848  virtual UClassID getDynamicClassID(void) const = 0;
849 
859  UErrorCode &status) = 0;
860 
870  UErrorCode &status) const = 0;
871 
890  virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCode);
891 
901 
918  virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status) = 0;
919 
935  virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) = 0;
936 
948  virtual void setVariableTop(uint32_t varTop, UErrorCode &status) = 0;
949 
957  virtual uint32_t getVariableTop(UErrorCode &status) const = 0;
958 
968  virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
969 
977  virtual Collator* safeClone(void) const;
978 
995  virtual int32_t getSortKey(const UnicodeString& source,
996  uint8_t* result,
997  int32_t resultLength) const = 0;
998 
1018  virtual int32_t getSortKey(const UChar*source, int32_t sourceLength,
1019  uint8_t*result, int32_t resultLength) const = 0;
1020 
1058  static int32_t U_EXPORT2 getBound(const uint8_t *source,
1059  int32_t sourceLength,
1060  UColBoundMode boundType,
1061  uint32_t noOfLevels,
1062  uint8_t *result,
1063  int32_t resultLength,
1064  UErrorCode &status);
1065 
1066 
1067 protected:
1068 
1069  // Collator protected constructors -------------------------------------
1070 
1079 
1080 #ifndef U_HIDE_DEPRECATED_API
1081 
1092  Collator(UCollationStrength collationStrength,
1093  UNormalizationMode decompositionMode);
1094 #endif /* U_HIDE_DEPRECATED_API */
1095 
1101  Collator(const Collator& other);
1102 
1103 public:
1111  virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
1112 
1136  virtual int32_t internalGetShortDefinitionString(const char *locale,
1137  char *buffer,
1138  int32_t capacity,
1139  UErrorCode &status) const;
1140 
1146  const char *left, int32_t leftLength,
1147  const char *right, int32_t rightLength,
1148  UErrorCode &errorCode) const;
1149 
1154  virtual int32_t
1156  UCharIterator *iter, uint32_t state[2],
1157  uint8_t *dest, int32_t count, UErrorCode &errorCode) const;
1158 
1159 #ifndef U_HIDE_INTERNAL_API
1160 
1161  static inline Collator *fromUCollator(UCollator *uc) {
1162  return reinterpret_cast<Collator *>(uc);
1163  }
1165  static inline const Collator *fromUCollator(const UCollator *uc) {
1166  return reinterpret_cast<const Collator *>(uc);
1167  }
1170  return reinterpret_cast<UCollator *>(this);
1171  }
1173  inline const UCollator *toUCollator() const {
1174  return reinterpret_cast<const UCollator *>(this);
1175  }
1176 #endif // U_HIDE_INTERNAL_API
1177 
1178 private:
1182  Collator& operator=(const Collator& other);
1183 
1184  friend class CFactory;
1185  friend class SimpleCFactory;
1186  friend class ICUCollatorFactory;
1187  friend class ICUCollatorService;
1188  static Collator* makeInstance(const Locale& desiredLocale,
1189  UErrorCode& status);
1190 };
1191 
1192 #if !UCONFIG_NO_SERVICE
1193 
1210 public:
1211 
1216  virtual ~CollatorFactory();
1217 
1225  virtual UBool visible(void) const;
1226 
1234  virtual Collator* createCollator(const Locale& loc) = 0;
1235 
1246  virtual UnicodeString& getDisplayName(const Locale& objectLocale,
1247  const Locale& displayLocale,
1248  UnicodeString& result);
1249 
1259  virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
1260 };
1261 #endif /* UCONFIG_NO_SERVICE */
1262 
1263 // Collator inline methods -----------------------------------------------
1264 
1266 
1267 #endif /* #if !UCONFIG_NO_COLLATION */
1268 
1269 #endif
UCOL_IDENTICAL
@ UCOL_IDENTICAL
Identical collation strength.
Definition: ucol.h:103
UCOL_QUATERNARY
@ UCOL_QUATERNARY
Quaternary collation strength.
Definition: ucol.h:101
UCOL_EQUAL
@ UCOL_EQUAL
string a == string b
Definition: ucol.h:73
normlzr.h
C++ API: Unicode Normalization.
icu::Collator::~Collator
virtual ~Collator()
Destructor.
icu::CollatorFactory::~CollatorFactory
virtual ~CollatorFactory()
Destructor.
icu::CollatorFactory::getDisplayName
virtual UnicodeString & getDisplayName(const Locale &objectLocale, const Locale &displayLocale, UnicodeString &result)
Return the name of the collator for the objectLocale, localized for the displayLocale.
icu::Collator::greaterOrEqual
UBool greaterOrEqual(const UnicodeString &source, const UnicodeString &target) const
Convenience method for comparing two strings based on the collation rules.
icu::CollationKey
Collation keys are generated by the Collator class.
Definition: sortkey.h:97
UColAttribute
UColAttribute
Attributes that collation service understands.
Definition: ucol.h:234
icu::Collator::createInstance
static Collator * createInstance(const Locale &loc, UErrorCode &err)
Gets the collation object for the desired locale.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::Collator::fromUCollator
static const Collator * fromUCollator(const UCollator *uc)
Definition: coll.h:1165
icu::UnicodeSet
A mutable set of Unicode characters and multicharacter strings.
Definition: uniset.h:276
icu::Collator::ECollationStrength
ECollationStrength
Base letter represents a primary difference.
Definition: coll.h:194
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:358
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
icu::Collator::Collator
Collator()
Default constructor.
ULocDataLocaleType
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
Definition: uloc.h:336
icu::Collator::setVariableTop
virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status)=0
Sets the variable top to the primary weight of the specified string.
UCOL_LESS
@ UCOL_LESS
string a < string b
Definition: ucol.h:77
icu::Collator::getVariableTop
virtual uint32_t getVariableTop(UErrorCode &status) const =0
Gets the variable top value of a Collator.
icu::Collator::getDynamicClassID
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID POLYMORPHICALLY.
icu::Collator::internalNextSortKeyPart
virtual int32_t internalNextSortKeyPart(UCharIterator *iter, uint32_t state[2], uint8_t *dest, int32_t count, UErrorCode &errorCode) const
Implements ucol_nextSortKeyPart().
icu::Collator::getTailoredSet
virtual UnicodeSet * getTailoredSet(UErrorCode &status) const
Get a UnicodeSet that contains all the characters and sequences tailored in this collator.
icu::Collator::compareUTF8
virtual UCollationResult compareUTF8(const StringPiece &source, const StringPiece &target, UErrorCode &status) const
Compares two UTF-8 strings using the Collator.
UCOL_PRIMARY
@ UCOL_PRIMARY
Primary collation strength.
Definition: ucol.h:92
icu::Collator
The Collator class performs locale-sensitive string comparison.
Definition: coll.h:163
icu::Collator::operator==
virtual UBool operator==(const Collator &other) const
Returns TRUE if "other" is the same as "this".
icu::Collator::hashCode
virtual int32_t hashCode(void) const =0
Generates the hash code for the collation object.
icu::Collator::registerInstance
static URegistryKey registerInstance(Collator *toAdopt, const Locale &locale, UErrorCode &status)
Register a new Collator.
icu::Collator::registerFactory
static URegistryKey registerFactory(CollatorFactory *toAdopt, UErrorCode &status)
Register a new CollatorFactory.
icu::Collator::setAttribute
virtual void setAttribute(UColAttribute attr, UColAttributeValue value, UErrorCode &status)=0
Universal attribute setter.
UColAttributeValue
UColAttributeValue
Enum containing attribute values for controling collation behavior.
Definition: ucol.h:87
icu::Collator::internalGetShortDefinitionString
virtual int32_t internalGetShortDefinitionString(const char *locale, char *buffer, int32_t capacity, UErrorCode &status) const
Get the short definition string for a collator.
UCollationResult
UCollationResult
UCOL_LESS is returned if source string is compared to be less than target string in the ucol_strcoll(...
Definition: ucol.h:71
umisc.h
C API:misc definitions.
icu::Collator::setVariableTop
virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status)=0
Sets the variable top to the primary weight of the specified string.
UCOL_SECONDARY
@ UCOL_SECONDARY
Secondary collation strength.
Definition: ucol.h:94
icu::Collator::setStrength
virtual void setStrength(ECollationStrength newStrength)
Sets the minimum strength to be used in comparison or transformation.
icu::Collator::internalCompareUTF8
virtual UCollationResult internalCompareUTF8(const char *left, int32_t leftLength, const char *right, int32_t rightLength, UErrorCode &errorCode) const
Implements ucol_strcollUTF8().
stringpiece.h
C++ API: StringPiece: Read-only byte string wrapper class.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:246
icu::Collator::getKeywordValues
static StringEnumeration * getKeywordValues(const char *keyword, UErrorCode &status)
Given a keyword, create a string enumeration of all values for that keyword that are currently in use...
icu::CollatorFactory::createCollator
virtual Collator * createCollator(const Locale &loc)=0
Return a collator for the provided locale.
icu::Collator::toUCollator
UCollator * toUCollator()
Definition: coll.h:1169
URegistryKey
const void * URegistryKey
Opaque type returned by registerInstance, registerFactory and unregister for service registration.
Definition: umisc.h:55
icu::Collator::getAttribute
virtual UColAttributeValue getAttribute(UColAttribute attr, UErrorCode &status) const =0
Universal attribute getter.
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:221
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition: utypes.h:476
icu::StringEnumeration
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:55
icu::CollatorFactory::getSupportedIDs
virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode &status)=0
Return an array of all the locale names directly supported by this factory.
icu::Collator::setReorderCodes
virtual void setReorderCodes(const int32_t *reorderCodes, int32_t reorderCodesLength, UErrorCode &status)
Sets the ordering of scripts for this collator.
icu::Collator::getReorderCodes
virtual int32_t getReorderCodes(int32_t *dest, int32_t destCapacity, UErrorCode &status) const
Retrieves the reordering codes for this collator.
icu::Collator::getDisplayName
static UnicodeString & getDisplayName(const Locale &objectLocale, UnicodeString &name)
Get name of the object for the desired Locale, in the langauge of the default locale.
UColBoundMode
UColBoundMode
enum that is taken by ucol_getBound API See below for explanation do not change the values assigned...
Definition: ucol.h:1046
UNormalizationMode
UNormalizationMode
Constants for normalization modes.
Definition: unorm.h:133
icu::Collator::toUCollator
const UCollator * toUCollator() const
Definition: coll.h:1173
icu::Collator::getMaxVariable
virtual UColReorderCode getMaxVariable() const
Returns the maximum reordering group whose characters are affected by UCOL_ALTERNATE_HANDLING.
UCollator
struct UCollator UCollator
structure representing a collator object instance
Definition: ucol.h:56
icu::Collator::getVersion
virtual void getVersion(UVersionInfo info) const =0
Gets the version information for a Collator.
icu::Collator::getKeywords
static StringEnumeration * getKeywords(UErrorCode &status)
Create a string enumerator of all possible keywords that are relevant to collation.
icu::Collator::getSortKey
virtual int32_t getSortKey(const UnicodeString &source, uint8_t *result, int32_t resultLength) const =0
Get the sort key as an array of bytes from a UnicodeString.
icu::Collator::getStrength
virtual ECollationStrength getStrength(void) const
Determines the minimum strength that will be used in comparison or transformation.
icu::Collator::greater
UBool greater(const UnicodeString &source, const UnicodeString &target) const
Convenience method for comparing two strings based on the collation rules.
icu::Collator::createInstance
static Collator * createInstance(UErrorCode &err)
Creates the Collator object for the current default locale.
icu::Collator::Collator
Collator(UCollationStrength collationStrength, UNormalizationMode decompositionMode)
Constructor.
UCharIterator
C API for code unit iteration.
Definition: uiter.h:339
icu::Collator::getSortKey
virtual int32_t getSortKey(const UChar *source, int32_t sourceLength, uint8_t *result, int32_t resultLength) const =0
Get the sort key as an array of bytes from a UChar buffer.
icu::Collator::Collator
Collator(const Collator &other)
Copy constructor.
icu::Collator::getAvailableLocales
static const Locale * getAvailableLocales(int32_t &count)
Get the set of Locales for which Collations are installed.
icu::Collator::clone
virtual Collator * clone(void) const =0
Makes a copy of this object.
icu::Collator::safeClone
virtual Collator * safeClone(void) const
Same as clone().
UCOL_TERTIARY
@ UCOL_TERTIARY
Tertiary collation strength.
Definition: ucol.h:96
icu::Collator::getEquivalentReorderCodes
static int32_t getEquivalentReorderCodes(int32_t reorderCode, int32_t *dest, int32_t destCapacity, UErrorCode &status)
Retrieves the reorder codes that are grouped with the given reorder code.
icu::Collator::getFunctionalEquivalent
static Locale getFunctionalEquivalent(const char *keyword, const Locale &locale, UBool &isAvailable, UErrorCode &status)
Return the functionally equivalent locale for the given requested locale, with respect to given keywo...
icu::Collator::operator!=
virtual UBool operator!=(const Collator &other) const
Returns true if "other" is not the same as "this".
icu::CollatorFactory::visible
virtual UBool visible(void) const
Return true if this factory is visible.
uiter.h
C API: Unicode Character Iteration.
icu::Collator::getKeywordValuesForLocale
static StringEnumeration * getKeywordValuesForLocale(const char *keyword, const Locale &locale, UBool commonlyUsed, UErrorCode &status)
Given a key and a locale, returns an array of string values in a preferred order that would make a di...
icu::Collator::getCollationKey
virtual CollationKey & getCollationKey(const UnicodeString &source, CollationKey &key, UErrorCode &status) const =0
Transforms the string into a series of characters that can be compared with CollationKey::compareTo.
icu::Collator::setVariableTop
virtual void setVariableTop(uint32_t varTop, UErrorCode &status)=0
Sets the variable top to the specified primary weight.
icu::Collator::getAvailableLocales
static StringEnumeration * getAvailableLocales(void)
Return a StringEnumeration over the locales available at the time of the call, including registered l...
UChar
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
icu::Collator::fromUCollator
static Collator * fromUCollator(UCollator *uc)
Definition: coll.h:1161
UVersionInfo
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
icu::Collator::getLocale
virtual Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const =0
Gets the locale of the Collator.
icu::Collator::getBound
static int32_t getBound(const uint8_t *source, int32_t sourceLength, UColBoundMode boundType, uint32_t noOfLevels, uint8_t *result, int32_t resultLength, UErrorCode &status)
Produce a bound for a given sortkey and a number of levels.
locid.h
C++ API: Locale ID object.
uobject.h
C++ API: Common ICU base class UObject.
icu::Collator::equals
UBool equals(const UnicodeString &source, const UnicodeString &target) const
Convenience method for comparing two strings based on the collation rules.
uniset.h
C++ API: Unicode Set.
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
icu::Collator::setMaxVariable
virtual Collator & setMaxVariable(UColReorderCode group, UErrorCode &errorCode)
Sets the variable top to the top of the specified reordering group.
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
icu::StringPiece
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:52
icu::CollatorFactory
A factory, used with registerFactory, the creates multiple collators and provides display names for t...
Definition: coll.h:1209
icu::Collator::getDisplayName
static UnicodeString & getDisplayName(const Locale &objectLocale, const Locale &displayLocale, UnicodeString &name)
Get name of the object for the desired Locale, in the desired langauge.
icu::Collator::setLocales
virtual void setLocales(const Locale &requestedLocale, const Locale &validLocale, const Locale &actualLocale)
Used internally by registration to define the requested and valid locales.
icu::Collator::EComparisonResult
EComparisonResult
LESS is returned if source string is compared to be less than target string in the compare() method.
Definition: coll.h:213
icu::Collator::getCollationKey
virtual CollationKey & getCollationKey(const UChar *source, int32_t sourceLength, CollationKey &key, UErrorCode &status) const =0
Transforms the string into a series of characters that can be compared with CollationKey::compareTo.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185
ucol.h
C API: Collator.
icu::Collator::unregister
static UBool unregister(URegistryKey key, UErrorCode &status)
Unregister a previously-registered Collator or CollatorFactory using the key returned from the regist...
UCOL_GREATER
@ UCOL_GREATER
string a > string b
Definition: ucol.h:75
UColReorderCode
UColReorderCode
Enum containing the codes for reordering segments of the collation table that are not script codes.
Definition: ucol.h:139