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
tblcoll.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 * Copyright (C) 1996-2014, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ******************************************************************************
6 */
7
60 #ifndef TBLCOLL_H
61 #define TBLCOLL_H
62
63 #include "unicode/utypes.h"
64
65 #if !UCONFIG_NO_COLLATION
66
67 #include "unicode/coll.h"
68 #include "unicode/locid.h"
69 #include "unicode/uiter.h"
70 #include "unicode/ucol.h"
71
72 U_NAMESPACE_BEGIN
73
74 struct CollationCacheEntry;
75 struct CollationData;
76 struct CollationSettings;
77 struct CollationTailoring;
81 class StringSearch;
85 class CollationElementIterator;
86 class CollationKey;
87 class SortKeyByteSink;
88 class UnicodeSet;
89 class UnicodeString;
90 class UVector64;
91
111 class U_I18N_API RuleBasedCollator : public Collator {
112 public:
121 RuleBasedCollator(const UnicodeString& rules, UErrorCode& status);
122
132 RuleBasedCollator(const UnicodeString& rules,
133 ECollationStrength collationStrength,
134 UErrorCode& status);
135
145 RuleBasedCollator(const UnicodeString& rules,
146 UColAttributeValue decompositionMode,
147 UErrorCode& status);
148
159 RuleBasedCollator(const UnicodeString& rules,
160 ECollationStrength collationStrength,
161 UColAttributeValue decompositionMode,
162 UErrorCode& status);
163
164 #ifndef U_HIDE_INTERNAL_API
165
169 RuleBasedCollator(const UnicodeString &rules,
170 UParseError &parseError, UnicodeString &reason,
171 UErrorCode &errorCode);
172 #endif /* U_HIDE_INTERNAL_API */
173
179 RuleBasedCollator(const RuleBasedCollator& other);
180
181
199 RuleBasedCollator(const uint8_t *bin, int32_t length,
200 const RuleBasedCollator *base,
201 UErrorCode &status);
202
207 virtual ~RuleBasedCollator();
208
214 RuleBasedCollator& operator=(const RuleBasedCollator& other);
215
222 virtual UBool operator==(const Collator& other) const;
223
229 virtual Collator* clone(void) const;
230
241 virtual CollationElementIterator* createCollationElementIterator(
242 const UnicodeString& source) const;
243
253 virtual CollationElementIterator* createCollationElementIterator(
254 const CharacterIterator& source) const;
255
256 // Make deprecated versions of Collator::compare() visible.
257 using Collator::compare;
258
271 virtual UCollationResult compare(const UnicodeString& source,
272 const UnicodeString& target,
273 UErrorCode &status) const;
274
288 virtual UCollationResult compare(const UnicodeString& source,
289 const UnicodeString& target,
290 int32_t length,
291 UErrorCode &status) const;
292
309 virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
310 const UChar* target, int32_t targetLength,
311 UErrorCode &status) const;
312
324 virtual UCollationResult compare(UCharIterator &sIter,
325 UCharIterator &tIter,
326 UErrorCode &status) const;
327
341 virtual UCollationResult compareUTF8(const StringPiece &source,
342 const StringPiece &target,
343 UErrorCode &status) const;
344
359 virtual CollationKey& getCollationKey(const UnicodeString& source,
360 CollationKey& key,
361 UErrorCode& status) const;
362
378 virtual CollationKey& getCollationKey(const UChar *source,
379 int32_t sourceLength,
380 CollationKey& key,
381 UErrorCode& status) const;
382
388 virtual int32_t hashCode() const;
389
400 virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
401
407 const UnicodeString& getRules() const;
408
414 virtual void getVersion(UVersionInfo info) const;
415
416 #ifndef U_HIDE_DEPRECATED_API
417
433 int32_t getMaxExpansion(int32_t order) const;
434 #endif /* U_HIDE_DEPRECATED_API */
435
446 virtual UClassID getDynamicClassID(void) const;
447
459 static UClassID U_EXPORT2 getStaticClassID(void);
460
461 #ifndef U_HIDE_DEPRECATED_API
462
472 uint8_t *cloneRuleData(int32_t &length, UErrorCode &status) const;
473 #endif /* U_HIDE_DEPRECATED_API */
474
485 int32_t cloneBinary(uint8_t *buffer, int32_t capacity, UErrorCode &status) const;
486
498 void getRules(UColRuleOption delta, UnicodeString &buffer) const;
499
507 virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
508 UErrorCode &status);
509
517 virtual UColAttributeValue getAttribute(UColAttribute attr,
518 UErrorCode &status) const;
519
536 virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCode);
537
544 virtual UColReorderCode getMaxVariable() const;
545
562 virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status);
563
579 virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status);
580
592 virtual void setVariableTop(uint32_t varTop, UErrorCode &status);
593
601 virtual uint32_t getVariableTop(UErrorCode &status) const;
602
612 virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
613
628 virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result,
629 int32_t resultLength) const;
630
647 virtual int32_t getSortKey(const UChar *source, int32_t sourceLength,
648 uint8_t *result, int32_t resultLength) const;
649
663 virtual int32_t getReorderCodes(int32_t *dest,
664 int32_t destCapacity,
665 UErrorCode& status) const;
666
677 virtual void setReorderCodes(const int32_t* reorderCodes,
678 int32_t reorderCodesLength,
679 UErrorCode& status) ;
680
685 virtual UCollationResult internalCompareUTF8(
686 const char *left, int32_t leftLength,
687 const char *right, int32_t rightLength,
688 UErrorCode &errorCode) const;
689
713 virtual int32_t internalGetShortDefinitionString(const char *locale,
714 char *buffer,
715 int32_t capacity,
716 UErrorCode &status) const;
717
722 virtual int32_t internalNextSortKeyPart(
723 UCharIterator *iter, uint32_t state[2],
724 uint8_t *dest, int32_t count, UErrorCode &errorCode) const;
725
730 RuleBasedCollator();
731
732 #ifndef U_HIDE_INTERNAL_API
733
739 const char *internalGetLocaleID(ULocDataLocaleType type, UErrorCode &errorCode) const;
740
753 void internalGetContractionsAndExpansions(
754 UnicodeSet *contractions, UnicodeSet *expansions,
755 UBool addPrefixes, UErrorCode &errorCode) const;
756
762 void internalAddContractions(UChar32 c, UnicodeSet &set, UErrorCode &errorCode) const;
763
768 void internalBuildTailoring(
769 const UnicodeString &rules,
770 int32_t strength,
771 UColAttributeValue decompositionMode,
772 UParseError *outParseError, UnicodeString *outReason,
773 UErrorCode &errorCode);
774
776 static inline RuleBasedCollator *rbcFromUCollator(UCollator *uc) {
777 return dynamic_cast<RuleBasedCollator *>(fromUCollator(uc));
778 }
780 static inline const RuleBasedCollator *rbcFromUCollator(const UCollator *uc) {
781 return dynamic_cast<const RuleBasedCollator *>(fromUCollator(uc));
782 }
783
788 void internalGetCEs(const UnicodeString &str, UVector64 &ces, UErrorCode &errorCode) const;
789 #endif // U_HIDE_INTERNAL_API
790
791 protected:
799 virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
800
801 private:
802 friend class CollationElementIterator;
803 friend class Collator;
804
805 RuleBasedCollator(const CollationCacheEntry *entry);
806
812 enum Attributes {
813 ATTR_VARIABLE_TOP = UCOL_ATTRIBUTE_COUNT,
814 ATTR_LIMIT
815 };
816
817 void adoptTailoring(CollationTailoring *t, UErrorCode &errorCode);
818
819 // Both lengths must be <0 or else both must be >=0.
820 UCollationResult doCompare(const UChar *left, int32_t leftLength,
821 const UChar *right, int32_t rightLength,
822 UErrorCode &errorCode) const;
823 UCollationResult doCompare(const uint8_t *left, int32_t leftLength,
824 const uint8_t *right, int32_t rightLength,
825 UErrorCode &errorCode) const;
826
827 void writeSortKey(const UChar *s, int32_t length,
828 SortKeyByteSink &sink, UErrorCode &errorCode) const;
829
830 void writeIdenticalLevel(const UChar *s, const UChar *limit,
831 SortKeyByteSink &sink, UErrorCode &errorCode) const;
832
833 const CollationSettings &getDefaultSettings() const;
834
835 void setAttributeDefault(int32_t attribute) {
836 explicitlySetAttributes &= ~((uint32_t)1 << attribute);
837 }
838 void setAttributeExplicitly(int32_t attribute) {
839 explicitlySetAttributes |= (uint32_t)1 << attribute;
840 }
841 UBool attributeHasBeenSetExplicitly(int32_t attribute) const {
842 // assert(0 <= attribute < ATTR_LIMIT);
843 return (UBool)((explicitlySetAttributes & ((uint32_t)1 << attribute)) != 0);
844 }
845
853 UBool isUnsafe(UChar32 c) const;
854
855 static void computeMaxExpansions(const CollationTailoring *t, UErrorCode &errorCode);
856 UBool initMaxExpansions(UErrorCode &errorCode) const;
857
858 void setFastLatinOptions(CollationSettings &ownedSettings) const;
859
860 const CollationData *data;
861 const CollationSettings *settings; // reference-counted
862 const CollationTailoring *tailoring; // alias of cacheEntry->tailoring
863 const CollationCacheEntry *cacheEntry; // reference-counted
864 Locale validLocale;
865 uint32_t explicitlySetAttributes;
866
867 UBool actualLocaleIsSameAsValid;
868 };
869
870 U_NAMESPACE_END
871
872 #endif // !UCONFIG_NO_COLLATION
873 #endif // TBLCOLL_H