ICU 56.1: coll.h Source File

ICU 56.1 56.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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
66 U_NAMESPACE_BEGIN
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
193 enum ECollationStrength
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
212 enum EComparisonResult
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
492 virtual CollationKey& getCollationKey(const UnicodeString& source,
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
560 UBool greaterOrEqual(const UnicodeString& source,
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
858 virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
859 UErrorCode &status) = 0;
860
869 virtual UColAttributeValue getAttribute(UColAttribute attr,
870 UErrorCode &status) const = 0;
871
890 virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCode);
891
900 virtual UColReorderCode getMaxVariable() const;
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
1078 Collator();
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
1145 virtual UCollationResult internalCompareUTF8(
1146 const char *left, int32_t leftLength,
1147 const char *right, int32_t rightLength,
1148 UErrorCode &errorCode) const;
1149
1154 virtual int32_t
1155 internalNextSortKeyPart(
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 }
1169 inline UCollator *toUCollator() {
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
1209 class U_I18N_API CollatorFactory : public UObject {
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
1265 U_NAMESPACE_END
1266
1267 #endif /* #if !UCONFIG_NO_COLLATION */
1268
1269 #endif
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
UCOL_LESS
string a < string b
Definition: ucol.h:77
icu::Collator
The Collator class performs locale-sensitive string comparison.
Definition: coll.h:163
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
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
icu::Collator::toUCollator
const UCollator * toUCollator() const
Definition: coll.h:1173
UNormalizationMode
UNormalizationMode
Constants for normalization modes.
Definition: unorm.h:137
normlzr.h
C++ API: Unicode Normalization.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
icu::CollatorFactory
A factory, used with registerFactory, the creates multiple collators and provides display names for t...
Definition: coll.h:1209
umisc.h
C API:misc definitions.
UCharIterator
C API for code unit iteration.
Definition: uiter.h:339
icu::StringEnumeration
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:55
UCOL_EQUAL
string a == string b
Definition: ucol.h:73
icu::Collator::fromUCollator
static const Collator * fromUCollator(const UCollator *uc)
Definition: coll.h:1165
icu::Collator::ECollationStrength
ECollationStrength
Base letter represents a primary difference.
Definition: coll.h:193
UColReorderCode
UColReorderCode
Enum containing the codes for reordering segments of the collation table that are not script codes...
Definition: ucol.h:139
UColAttribute
UColAttribute
Attributes that collation service understands.
Definition: ucol.h:234
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
icu::Collator::toUCollator
UCollator * toUCollator()
Definition: coll.h:1169
stringpiece.h
C++ API: StringPiece: Read-only byte string wrapper class.
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
UCOL_SECONDARY
Secondary collation strength.
Definition: ucol.h:94
icu::operator!=
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
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:212
ucol.h
C API: Collator.
icu::CollationKey
Collation keys are generated by the Collator class.
Definition: sortkey.h:97
UCOL_TERTIARY
Tertiary collation strength.
Definition: ucol.h:96
icu::UnicodeSet
A mutable set of Unicode characters and multicharacter strings.
Definition: uniset.h:276
uiter.h
C API: Unicode Character Iteration.
uobject.h
C++ API: Common ICU base class UObject.
URegistryKey
const void * URegistryKey
Opaque type returned by registerInstance, registerFactory and unregister for service registration...
Definition: umisc.h:55
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
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
UCOL_GREATER
string a > string b
Definition: ucol.h:75
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
ULocDataLocaleType
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested...
Definition: uloc.h:336
UColBoundMode
UColBoundMode
enum that is taken by ucol_getBound API See below for explanation do not change the values assigned t...
Definition: ucol.h:1046
locid.h
C++ API: Locale ID object.
UCollator
struct UCollator UCollator
structure representing a collator object instance
Definition: ucol.h:56
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::Collator::fromUCollator
static Collator * fromUCollator(UCollator *uc)
Definition: coll.h:1161
UCOL_IDENTICAL
Identical collation strength.
Definition: ucol.h:103
UCOL_QUATERNARY
Quaternary collation strength.
Definition: ucol.h:101
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:293
UColAttributeValue
UColAttributeValue
Enum containing attribute values for controling collation behavior.
Definition: ucol.h:87
icu::StringPiece
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:52
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:221
UCOL_PRIMARY
Primary collation strength.
Definition: ucol.h:92
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185
uniset.h
C++ API: Unicode Set.