ICU 54.1 54.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-2014, 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
639 virtual void setReorderCodes(const int32_t* reorderCodes,
640 int32_t reorderCodesLength,
641 UErrorCode& status) ;
642
661 static int32_t U_EXPORT2 getEquivalentReorderCodes(int32_t reorderCode,
662 int32_t* dest,
663 int32_t destCapacity,
664 UErrorCode& status);
665
675 static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
676 const Locale& displayLocale,
677 UnicodeString& name);
678
687 static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
688 UnicodeString& name);
689
701 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
702
711 static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
712
722 static StringEnumeration* U_EXPORT2 getKeywords(UErrorCode& status);
723
735 static StringEnumeration* U_EXPORT2 getKeywordValues(const char *keyword, UErrorCode& status);
736
753 static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* keyword, const Locale& locale,
754 UBool commonlyUsed, UErrorCode& status);
755
783 static Locale U_EXPORT2 getFunctionalEquivalent(const char* keyword, const Locale& locale,
784 UBool& isAvailable, UErrorCode& status);
785
786 #if !UCONFIG_NO_SERVICE
787
798 static URegistryKey U_EXPORT2 registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status);
799
810 static URegistryKey U_EXPORT2 registerFactory(CollatorFactory* toAdopt, UErrorCode& status);
811
825 static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
826 #endif /* UCONFIG_NO_SERVICE */
827
833 virtual void getVersion(UVersionInfo info) const = 0;
834
845 virtual UClassID getDynamicClassID(void) const = 0;
846
855 virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
856 UErrorCode &status) = 0;
857
866 virtual UColAttributeValue getAttribute(UColAttribute attr,
867 UErrorCode &status) const = 0;
868
869 /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft methods since they are virtual */
888 virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCode);
889
898 virtual UColReorderCode getMaxVariable() const;
899
916 virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status) = 0;
917
933 virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) = 0;
934
946 virtual void setVariableTop(uint32_t varTop, UErrorCode &status) = 0;
947
955 virtual uint32_t getVariableTop(UErrorCode &status) const = 0;
956
966 virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
967
975 virtual Collator* safeClone(void) const;
976
993 virtual int32_t getSortKey(const UnicodeString& source,
994 uint8_t* result,
995 int32_t resultLength) const = 0;
996
1016 virtual int32_t getSortKey(const UChar*source, int32_t sourceLength,
1017 uint8_t*result, int32_t resultLength) const = 0;
1018
1056 static int32_t U_EXPORT2 getBound(const uint8_t *source,
1057 int32_t sourceLength,
1058 UColBoundMode boundType,
1059 uint32_t noOfLevels,
1060 uint8_t *result,
1061 int32_t resultLength,
1062 UErrorCode &status);
1063
1064
1065 protected:
1066
1067 // Collator protected constructors -------------------------------------
1068
1076 Collator();
1077
1078 #ifndef U_HIDE_DEPRECATED_API
1079
1090 Collator(UCollationStrength collationStrength,
1091 UNormalizationMode decompositionMode);
1092 #endif /* U_HIDE_DEPRECATED_API */
1093
1099 Collator(const Collator& other);
1100
1101 public:
1109 virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
1110
1134 virtual int32_t internalGetShortDefinitionString(const char *locale,
1135 char *buffer,
1136 int32_t capacity,
1137 UErrorCode &status) const;
1138
1143 virtual UCollationResult internalCompareUTF8(
1144 const char *left, int32_t leftLength,
1145 const char *right, int32_t rightLength,
1146 UErrorCode &errorCode) const;
1147
1152 virtual int32_t
1153 internalNextSortKeyPart(
1154 UCharIterator *iter, uint32_t state[2],
1155 uint8_t *dest, int32_t count, UErrorCode &errorCode) const;
1156
1157 #ifndef U_HIDE_INTERNAL_API
1158
1159 static inline Collator *fromUCollator(UCollator *uc) {
1160 return reinterpret_cast<Collator *>(uc);
1161 }
1163 static inline const Collator *fromUCollator(const UCollator *uc) {
1164 return reinterpret_cast<const Collator *>(uc);
1165 }
1167 inline UCollator *toUCollator() {
1168 return reinterpret_cast<UCollator *>(this);
1169 }
1171 inline const UCollator *toUCollator() const {
1172 return reinterpret_cast<const UCollator *>(this);
1173 }
1174 #endif // U_HIDE_INTERNAL_API
1175
1176 private:
1180 Collator& operator=(const Collator& other);
1181
1182 friend class CFactory;
1183 friend class SimpleCFactory;
1184 friend class ICUCollatorFactory;
1185 friend class ICUCollatorService;
1186 static Collator* makeInstance(const Locale& desiredLocale,
1187 UErrorCode& status);
1188 };
1189
1190 #if !UCONFIG_NO_SERVICE
1191
1207 class U_I18N_API CollatorFactory : public UObject {
1208 public:
1209
1214 virtual ~CollatorFactory();
1215
1223 virtual UBool visible(void) const;
1224
1232 virtual Collator* createCollator(const Locale& loc) = 0;
1233
1244 virtual UnicodeString& getDisplayName(const Locale& objectLocale,
1245 const Locale& displayLocale,
1246 UnicodeString& result);
1247
1257 virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
1258 };
1259 #endif /* UCONFIG_NO_SERVICE */
1260
1261 // Collator inline methods -----------------------------------------------
1262
1263 U_NAMESPACE_END
1264
1265 #endif /* #if !UCONFIG_NO_COLLATION */
1266
1267 #endif