ICU 50.2 50.2
coll.h
Go to the documentation of this file.
1/*
2******************************************************************************
3* Copyright (C) 1996-2012, International Business Machines *
4* Corporation and others. All Rights Reserved. *
5******************************************************************************
6*/
7
12
48
49#ifndef COLL_H
50#define COLL_H
51
52#include "unicode/utypes.h"
53
54#if !UCONFIG_NO_COLLATION
55
56#include "unicode/uobject.h"
57#include "unicode/ucol.h"
58#include "unicode/normlzr.h"
59#include "unicode/locid.h"
60#include "unicode/uniset.h"
61#include "unicode/umisc.h"
62#include "unicode/uiter.h"
63#include "unicode/stringpiece.h"
64
66
68
69#if !UCONFIG_NO_SERVICE
73class CollatorFactory;
74#endif
75
79class CollationKey;
80
176
178public:
179
180 // Collator public enums -----------------------------------------------
181
208 {
209 PRIMARY = UCOL_PRIMARY, // 0
210 SECONDARY = UCOL_SECONDARY, // 1
211 TERTIARY = UCOL_TERTIARY, // 2
212 QUATERNARY = UCOL_QUATERNARY, // 3
213 IDENTICAL = UCOL_IDENTICAL // 15
214 };
215
227 {
228 LESS = UCOL_LESS, // -1
229 EQUAL = UCOL_EQUAL, // 0
230 GREATER = UCOL_GREATER // 1
231 };
232
233 // Collator public destructor -----------------------------------------
234
239 virtual ~Collator();
240
241 // Collator public methods --------------------------------------------
242
261 virtual UBool operator==(const Collator& other) const;
262
270 virtual UBool operator!=(const Collator& other) const;
271
277 virtual Collator* clone(void) const = 0;
278
298 static Collator* U_EXPORT2 createInstance(UErrorCode& err);
299
323 static Collator* U_EXPORT2 createInstance(const Locale& loc, UErrorCode& err);
324
325#ifdef U_USE_COLLATION_OBSOLETE_2_6
349 static Collator *createInstance(const Locale &loc, UVersionInfo version, UErrorCode &err);
350#endif
351
364 const UnicodeString& target) const;
365
379 const UnicodeString& target,
380 UErrorCode &status) const = 0;
381
395 const UnicodeString& target,
396 int32_t length) const;
397
412 const UnicodeString& target,
413 int32_t length,
414 UErrorCode &status) const = 0;
415
449 virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
450 const UChar* target, int32_t targetLength)
451 const;
452
469 virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
470 const UChar* target, int32_t targetLength,
471 UErrorCode &status) const = 0;
472
485 UCharIterator &tIter,
486 UErrorCode &status) const;
487
502 const StringPiece &target,
503 UErrorCode &status) const;
504
521 CollationKey& key,
522 UErrorCode& status) const = 0;
523
540 virtual CollationKey& getCollationKey(const UChar*source,
541 int32_t sourceLength,
542 CollationKey& key,
543 UErrorCode& status) const = 0;
548 virtual int32_t hashCode(void) const = 0;
549
562 virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0;
563
573 UBool greater(const UnicodeString& source, const UnicodeString& target)
574 const;
575
586 const UnicodeString& target) const;
587
597 UBool equals(const UnicodeString& source, const UnicodeString& target) const;
598
609 virtual ECollationStrength getStrength(void) const;
610
629 virtual void setStrength(ECollationStrength newStrength);
630
646 virtual int32_t getReorderCodes(int32_t *dest,
647 int32_t destCapacity,
648 UErrorCode& status) const;
649
664 virtual void setReorderCodes(const int32_t* reorderCodes,
665 int32_t reorderCodesLength,
666 UErrorCode& status) ;
667
686 static int32_t U_EXPORT2 getEquivalentReorderCodes(int32_t reorderCode,
687 int32_t* dest,
688 int32_t destCapacity,
689 UErrorCode& status);
690
700 static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
701 const Locale& displayLocale,
702 UnicodeString& name);
703
712 static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
713 UnicodeString& name);
714
726 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
727
736 static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
737
747 static StringEnumeration* U_EXPORT2 getKeywords(UErrorCode& status);
748
760 static StringEnumeration* U_EXPORT2 getKeywordValues(const char *keyword, UErrorCode& status);
761
778 static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* keyword, const Locale& locale,
779 UBool commonlyUsed, UErrorCode& status);
780
808 static Locale U_EXPORT2 getFunctionalEquivalent(const char* keyword, const Locale& locale,
809 UBool& isAvailable, UErrorCode& status);
810
811#if !UCONFIG_NO_SERVICE
820 static URegistryKey U_EXPORT2 registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status);
821
829 static URegistryKey U_EXPORT2 registerFactory(CollatorFactory* toAdopt, UErrorCode& status);
830
841 static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
842#endif /* UCONFIG_NO_SERVICE */
843
849 virtual void getVersion(UVersionInfo info) const = 0;
850
861 virtual UClassID getDynamicClassID(void) const = 0;
862
872 UErrorCode &status) = 0;
873
883 UErrorCode &status) const = 0;
884
895 virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status) = 0;
896
906 virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) = 0;
907
915 virtual void setVariableTop(uint32_t varTop, UErrorCode &status) = 0;
916
923 virtual uint32_t getVariableTop(UErrorCode &status) const = 0;
924
934 virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
935
943 virtual Collator* safeClone(void) const;
944
957 virtual int32_t getSortKey(const UnicodeString& source,
958 uint8_t* result,
959 int32_t resultLength) const = 0;
960
976 virtual int32_t getSortKey(const UChar*source, int32_t sourceLength,
977 uint8_t*result, int32_t resultLength) const = 0;
978
1016 static int32_t U_EXPORT2 getBound(const uint8_t *source,
1017 int32_t sourceLength,
1018 UColBoundMode boundType,
1019 uint32_t noOfLevels,
1020 uint8_t *result,
1021 int32_t resultLength,
1022 UErrorCode &status);
1023
1024
1025protected:
1026
1027 // Collator protected constructors -------------------------------------
1028
1037
1038#ifndef U_HIDE_DEPRECATED_API
1050 Collator(UCollationStrength collationStrength,
1051 UNormalizationMode decompositionMode);
1052#endif /* U_HIDE_DEPRECATED_API */
1053
1059 Collator(const Collator& other);
1060
1061 // Collator protected methods -----------------------------------------
1062
1063
1071 virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
1072
1073public:
1074#if !UCONFIG_NO_SERVICE
1075#ifndef U_HIDE_INTERNAL_API
1080 static UCollator* createUCollator(const char* loc, UErrorCode* status);
1081#endif /* U_HIDE_INTERNAL_API */
1082#endif
1083
1107 virtual int32_t internalGetShortDefinitionString(const char *locale,
1108 char *buffer,
1109 int32_t capacity,
1110 UErrorCode &status) const;
1111private:
1116 Collator& operator=(const Collator& other);
1117
1118 friend class CFactory;
1119 friend class SimpleCFactory;
1120 friend class ICUCollatorFactory;
1121 friend class ICUCollatorService;
1122 static Collator* makeInstance(const Locale& desiredLocale,
1123 UErrorCode& status);
1124
1125 // Collator private data members ---------------------------------------
1126
1127 /*
1128 synwee : removed as attributes to be handled by child class
1129 UCollationStrength strength;
1130 Normalizer::EMode decmp;
1131 */
1132 /* This is useless information */
1133/* static const UVersionInfo fVersion;*/
1134};
1135
1136#if !UCONFIG_NO_SERVICE
1154public:
1155
1161
1169 virtual UBool visible(void) const;
1170
1178 virtual Collator* createCollator(const Locale& loc) = 0;
1179
1190 virtual UnicodeString& getDisplayName(const Locale& objectLocale,
1191 const Locale& displayLocale,
1192 UnicodeString& result);
1193
1203 virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
1204};
1205#endif /* UCONFIG_NO_SERVICE */
1206
1207// Collator inline methods -----------------------------------------------
1208
1210
1211#endif /* #if !UCONFIG_NO_COLLATION */
1212
1213#endif
Collation keys are generated by the Collator class.
Definition sortkey.h:97
A factory, used with registerFactory, the creates multiple collators and provides display names for t...
Definition coll.h:1153
virtual Collator * createCollator(const Locale &loc)=0
Return a collator for the provided locale.
virtual ~CollatorFactory()
Destructor.
virtual UBool visible(void) const
Return true if this factory is visible.
virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode &status)=0
Return an array of all the locale names directly supported by this factory.
virtual UnicodeString & getDisplayName(const Locale &objectLocale, const Locale &displayLocale, UnicodeString &result)
Return the name of the collator for the objectLocale, localized for the displayLocale.
The Collator class performs locale-sensitive string comparison.
Definition coll.h:177
EComparisonResult
LESS is returned if source string is compared to be less than target string in the compare() method.
Definition coll.h:227
static UnicodeString & getDisplayName(const Locale &objectLocale, const Locale &displayLocale, UnicodeString &name)
Get name of the object for the desired Locale, in the desired langauge.
virtual ECollationStrength getStrength(void) const
Determines the minimum strength that will be used in comparison or transformation.
static URegistryKey registerInstance(Collator *toAdopt, const Locale &locale, UErrorCode &status)
Register a new Collator.
virtual void setAttribute(UColAttribute attr, UColAttributeValue value, UErrorCode &status)=0
Universal attribute setter.
virtual int32_t getReorderCodes(int32_t *dest, int32_t destCapacity, UErrorCode &status) const
Retrieves the reordering codes for this collator.
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...
ECollationStrength
Base letter represents a primary difference.
Definition coll.h:208
Collator(UCollationStrength collationStrength, UNormalizationMode decompositionMode)
Constructor.
virtual Collator * safeClone(void) const
Same as clone().
virtual void setVariableTop(uint32_t varTop, UErrorCode &status)=0
Sets the variable top to a collation element value supplied.
virtual void setStrength(ECollationStrength newStrength)
Sets the minimum strength to be used in comparison or transformation.
virtual UCollationResult compare(UCharIterator &sIter, UCharIterator &tIter, UErrorCode &status) const
Compares two strings using the Collator.
virtual void setReorderCodes(const int32_t *reorderCodes, int32_t reorderCodesLength, UErrorCode &status)
Sets the ordering of scripts for this collator.
Collator(const Collator &other)
Copy constructor.
virtual void getVersion(UVersionInfo info) const =0
Gets the version information for a Collator.
virtual UBool operator==(const Collator &other) const
Returns TRUE if "other" is the same as "this".
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.
virtual UCollationResult compare(const UChar *source, int32_t sourceLength, const UChar *target, int32_t targetLength, UErrorCode &status) const =0
The comparison function compares the character data stored in two different string arrays.
virtual int32_t internalGetShortDefinitionString(const char *locale, char *buffer, int32_t capacity, UErrorCode &status) const
Get the short definition string for a collator.
virtual EComparisonResult compare(const UChar *source, int32_t sourceLength, const UChar *target, int32_t targetLength) const
The comparison function compares the character data stored in two different string arrays.
virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status)=0
Sets the variable top to a collation element value of a string supplied.
virtual Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const =0
Gets the locale of the Collator.
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.
Collator()
Default constructor.
virtual UCollationResult compare(const UnicodeString &source, const UnicodeString &target, UErrorCode &status) const =0
The comparison function compares the character data stored in two different strings.
virtual UBool operator!=(const Collator &other) const
Returns true if "other" is not the same as "this".
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...
virtual UnicodeSet * getTailoredSet(UErrorCode &status) const
Get an UnicodeSet that contains all the characters and sequences tailored in this collator.
UBool greater(const UnicodeString &source, const UnicodeString &target) const
Convenience method for comparing two strings based on the collation rules.
static StringEnumeration * getKeywords(UErrorCode &status)
Create a string enumerator of all possible keywords that are relevant to collation.
virtual int32_t hashCode(void) const =0
Generates the hash code for the collation object.
static UCollator * createUCollator(const char *loc, UErrorCode *status)
used only by ucol_open, not for public use
static Collator * createInstance(UErrorCode &err)
Creates the Collator object for the current default locale.
virtual EComparisonResult compare(const UnicodeString &source, const UnicodeString &target) const
The comparison function compares the character data stored in two different strings.
static StringEnumeration * getAvailableLocales(void)
Return a StringEnumeration over the locales available at the time of the call, including registered l...
static URegistryKey registerFactory(CollatorFactory *toAdopt, UErrorCode &status)
Register a new CollatorFactory.
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...
static UnicodeString & getDisplayName(const Locale &objectLocale, UnicodeString &name)
Get name of the object for the desired Locale, in the langauge of the default locale.
static const Locale * getAvailableLocales(int32_t &count)
Get the set of Locales for which Collations are installed.
virtual void setLocales(const Locale &requestedLocale, const Locale &validLocale, const Locale &actualLocale)
Used internally by registraton to define the requested and valid locales.
virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status)=0
Sets the variable top to a collation element value of a string supplied.
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.
virtual Collator * clone(void) const =0
Makes a copy of this object.
virtual UCollationResult compareUTF8(const StringPiece &source, const StringPiece &target, UErrorCode &status) const
Compares two UTF-8 strings using the Collator.
virtual UColAttributeValue getAttribute(UColAttribute attr, UErrorCode &status) const =0
Universal attribute getter.
virtual UCollationResult compare(const UnicodeString &source, const UnicodeString &target, int32_t length, UErrorCode &status) const =0
Does the same thing as compare but limits the comparison to a specified length.
UBool equals(const UnicodeString &source, const UnicodeString &target) const
Convenience method for comparing two strings based on the collation rules.
static Collator * createInstance(const Locale &loc, UErrorCode &err)
Gets the table-based collation object for the desired locale.
virtual uint32_t getVariableTop(UErrorCode &status) const =0
Gets the variable top value of a Collator.
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 an UnicodeString.
virtual EComparisonResult compare(const UnicodeString &source, const UnicodeString &target, int32_t length) const
Does the same thing as compare but limits the comparison to a specified length.
UBool greaterOrEqual(const UnicodeString &source, const UnicodeString &target) const
Convenience method for comparing two strings based on the collation rules.
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID POLYMORPHICALLY.
virtual ~Collator()
Destructor.
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 an UChar buffer.
static UBool unregister(URegistryKey key, UErrorCode &status)
Unregister a previously-registered Collator or CollatorFactory using the key returned from the regist...
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.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:182
Base class for 'pure' C++ implementations of uenum api.
Definition strenum.h:55
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:229
A mutable set of Unicode characters and multicharacter strings.
Definition uniset.h:273
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:247
C++ API: Locale ID object.
C++ API: Unicode Normalization.
C++ API: StringPiece: Read-only byte string wrapper class.
C API for code unit iteration.
Definition uiter.h:339
C API: Collator.
struct UCollator UCollator
structure representing a collator object instance
Definition ucol.h:62
UColAttribute
Attributes that collation service understands.
Definition ucol.h:240
UColAttributeValue UCollationStrength
Base letter represents a primary difference.
Definition ucol.h:234
UCollationResult
UCOL_LESS is returned if source string is compared to be less than target string in the u_strcoll() m...
Definition ucol.h:77
@ UCOL_LESS
string a < string b
Definition ucol.h:83
@ UCOL_GREATER
string a > string b
Definition ucol.h:81
@ UCOL_EQUAL
string a == string b
Definition ucol.h:79
UColBoundMode
enum that is taken by ucol_getBound API See below for explanation do not change the values assigned...
Definition ucol.h:1013
UColAttributeValue
Enum containing attribute values for controling collation behavior.
Definition ucol.h:93
@ UCOL_TERTIARY
Tertiary collation strength.
Definition ucol.h:102
@ UCOL_IDENTICAL
Identical collation strength.
Definition ucol.h:109
@ UCOL_QUATERNARY
Quaternary collation strength.
Definition ucol.h:107
@ UCOL_PRIMARY
Primary collation strength.
Definition ucol.h:98
@ UCOL_SECONDARY
Secondary collation strength.
Definition ucol.h:100
C API: Unicode Character Iteration.
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
Definition uloc.h:336
int8_t UBool
The ICU boolean type.
Definition umachine.h:200
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
C API:misc definitions.
const void * URegistryKey
Opaque type returned by registerInstance, registerFactory and unregister for service registration.
Definition umisc.h:55
C++ API: Unicode Set.
UNormalizationMode
Constants for normalization modes.
Definition unorm.h:133
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:476
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:358
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
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
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129