ICU 55.1 55.1

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

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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