ICU 71.1 71.1

tblcoll.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ******************************************************************************
5 * Copyright (C) 1996-2016, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ******************************************************************************
8 */
9
62 #ifndef TBLCOLL_H
63 #define TBLCOLL_H
64
65 #include "unicode/utypes.h"
66
67 #if U_SHOW_CPLUSPLUS_API
68
69 #if !UCONFIG_NO_COLLATION
70
71 #include "unicode/coll.h"
72 #include "unicode/locid.h"
73 #include "unicode/uiter.h"
74 #include "unicode/ucol.h"
75
76 U_NAMESPACE_BEGIN
77
78 struct CollationCacheEntry;
79 struct CollationData;
80 struct CollationSettings;
81 struct CollationTailoring;
85 class StringSearch;
89 class CollationElementIterator;
90 class CollationKey;
91 class SortKeyByteSink;
92 class UnicodeSet;
93 class UnicodeString;
94 class UVector64;
95
115 class U_I18N_API RuleBasedCollator U_FINAL : public Collator {
116 public:
125 RuleBasedCollator(const UnicodeString& rules, UErrorCode& status);
126
136 RuleBasedCollator(const UnicodeString& rules,
137 ECollationStrength collationStrength,
138 UErrorCode& status);
139
149 RuleBasedCollator(const UnicodeString& rules,
150 UColAttributeValue decompositionMode,
151 UErrorCode& status);
152
163 RuleBasedCollator(const UnicodeString& rules,
164 ECollationStrength collationStrength,
165 UColAttributeValue decompositionMode,
166 UErrorCode& status);
167
168 #ifndef U_HIDE_INTERNAL_API
169
173 RuleBasedCollator(const UnicodeString &rules,
174 UParseError &parseError, UnicodeString &reason,
175 UErrorCode &errorCode);
176 #endif /* U_HIDE_INTERNAL_API */
177
183 RuleBasedCollator(const RuleBasedCollator& other);
184
185
203 RuleBasedCollator(const uint8_t *bin, int32_t length,
204 const RuleBasedCollator *base,
205 UErrorCode &status);
206
211 virtual ~RuleBasedCollator();
212
218 RuleBasedCollator& operator=(const RuleBasedCollator& other);
219
226 virtual bool operator==(const Collator& other) const override;
227
233 virtual RuleBasedCollator* clone() const override;
234
245 virtual CollationElementIterator* createCollationElementIterator(
246 const UnicodeString& source) const;
247
257 virtual CollationElementIterator* createCollationElementIterator(
258 const CharacterIterator& source) const;
259
260 // Make deprecated versions of Collator::compare() visible.
261 using Collator::compare;
262
275 virtual UCollationResult compare(const UnicodeString& source,
276 const UnicodeString& target,
277 UErrorCode &status) const override;
278
292 virtual UCollationResult compare(const UnicodeString& source,
293 const UnicodeString& target,
294 int32_t length,
295 UErrorCode &status) const override;
296
313 virtual UCollationResult compare(const char16_t* source, int32_t sourceLength,
314 const char16_t* target, int32_t targetLength,
315 UErrorCode &status) const override;
316
328 virtual UCollationResult compare(UCharIterator &sIter,
329 UCharIterator &tIter,
330 UErrorCode &status) const override;
331
345 virtual UCollationResult compareUTF8(const StringPiece &source,
346 const StringPiece &target,
347 UErrorCode &status) const override;
348
363 virtual CollationKey& getCollationKey(const UnicodeString& source,
364 CollationKey& key,
365 UErrorCode& status) const override;
366
382 virtual CollationKey& getCollationKey(const char16_t *source,
383 int32_t sourceLength,
384 CollationKey& key,
385 UErrorCode& status) const override;
386
392 virtual int32_t hashCode() const override;
393
394 #ifndef U_FORCE_HIDE_DEPRECATED_API
395
405 virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const override;
406 #endif // U_FORCE_HIDE_DEPRECATED_API
407
413 const UnicodeString& getRules() const;
414
420 virtual void getVersion(UVersionInfo info) const override;
421
422 #ifndef U_HIDE_DEPRECATED_API
423
439 int32_t getMaxExpansion(int32_t order) const;
440 #endif /* U_HIDE_DEPRECATED_API */
441
452 virtual UClassID getDynamicClassID(void) const override;
453
465 static UClassID U_EXPORT2 getStaticClassID(void);
466
467 #ifndef U_HIDE_DEPRECATED_API
468
478 uint8_t *cloneRuleData(int32_t &length, UErrorCode &status) const;
479 #endif /* U_HIDE_DEPRECATED_API */
480
491 int32_t cloneBinary(uint8_t *buffer, int32_t capacity, UErrorCode &status) const;
492
504 void getRules(UColRuleOption delta, UnicodeString &buffer) const;
505
513 virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
514 UErrorCode &status) override;
515
523 virtual UColAttributeValue getAttribute(UColAttribute attr,
524 UErrorCode &status) const override;
525
542 virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCode) override;
543
550 virtual UColReorderCode getMaxVariable() const override;
551
552 #ifndef U_FORCE_HIDE_DEPRECATED_API
553
569 virtual uint32_t setVariableTop(const char16_t *varTop, int32_t len, UErrorCode &status) override;
570
586 virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) override;
587
599 virtual void setVariableTop(uint32_t varTop, UErrorCode &status) override;
600 #endif // U_FORCE_HIDE_DEPRECATED_API
601
609 virtual uint32_t getVariableTop(UErrorCode &status) const override;
610
620 virtual UnicodeSet *getTailoredSet(UErrorCode &status) const override;
621
636 virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result,
637 int32_t resultLength) const override;
638
655 virtual int32_t getSortKey(const char16_t *source, int32_t sourceLength,
656 uint8_t *result, int32_t resultLength) const override;
657
671 virtual int32_t getReorderCodes(int32_t *dest,
672 int32_t destCapacity,
673 UErrorCode& status) const override;
674
686 virtual void setReorderCodes(const int32_t* reorderCodes,
687 int32_t reorderCodesLength,
688 UErrorCode& status) override;
689
694 virtual UCollationResult internalCompareUTF8(
695 const char *left, int32_t leftLength,
696 const char *right, int32_t rightLength,
697 UErrorCode &errorCode) const override;
698
722 virtual int32_t internalGetShortDefinitionString(const char *locale,
723 char *buffer,
724 int32_t capacity,
725 UErrorCode &status) const override;
726
731 virtual int32_t internalNextSortKeyPart(
732 UCharIterator *iter, uint32_t state[2],
733 uint8_t *dest, int32_t count, UErrorCode &errorCode) const override;
734
735 // Do not enclose the default constructor with #ifndef U_HIDE_INTERNAL_API
740 RuleBasedCollator();
741
742 #ifndef U_HIDE_INTERNAL_API
743
749 const char *internalGetLocaleID(ULocDataLocaleType type, UErrorCode &errorCode) const;
750
763 void internalGetContractionsAndExpansions(
764 UnicodeSet *contractions, UnicodeSet *expansions,
765 UBool addPrefixes, UErrorCode &errorCode) const;
766
772 void internalAddContractions(UChar32 c, UnicodeSet &set, UErrorCode &errorCode) const;
773
778 void internalBuildTailoring(
779 const UnicodeString &rules,
780 int32_t strength,
781 UColAttributeValue decompositionMode,
782 UParseError *outParseError, UnicodeString *outReason,
783 UErrorCode &errorCode);
784
786 static inline RuleBasedCollator *rbcFromUCollator(UCollator *uc) {
787 return dynamic_cast<RuleBasedCollator *>(fromUCollator(uc));
788 }
790 static inline const RuleBasedCollator *rbcFromUCollator(const UCollator *uc) {
791 return dynamic_cast<const RuleBasedCollator *>(fromUCollator(uc));
792 }
793
798 void internalGetCEs(const UnicodeString &str, UVector64 &ces, UErrorCode &errorCode) const;
799 #endif // U_HIDE_INTERNAL_API
800
801 protected:
809 virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale) override;
810
811 private:
812 friend class CollationElementIterator;
813 friend class Collator;
814
815 RuleBasedCollator(const CollationCacheEntry *entry);
816
822 enum Attributes {
823 ATTR_VARIABLE_TOP = UCOL_ATTRIBUTE_COUNT,
824 ATTR_LIMIT
825 };
826
827 void adoptTailoring(CollationTailoring *t, UErrorCode &errorCode);
828
829 // Both lengths must be <0 or else both must be >=0.
830 UCollationResult doCompare(const char16_t *left, int32_t leftLength,
831 const char16_t *right, int32_t rightLength,
832 UErrorCode &errorCode) const;
833 UCollationResult doCompare(const uint8_t *left, int32_t leftLength,
834 const uint8_t *right, int32_t rightLength,
835 UErrorCode &errorCode) const;
836
837 void writeSortKey(const char16_t *s, int32_t length,
838 SortKeyByteSink &sink, UErrorCode &errorCode) const;
839
840 void writeIdenticalLevel(const char16_t *s, const char16_t *limit,
841 SortKeyByteSink &sink, UErrorCode &errorCode) const;
842
843 const CollationSettings &getDefaultSettings() const;
844
845 void setAttributeDefault(int32_t attribute) {
846 explicitlySetAttributes &= ~((uint32_t)1 << attribute);
847 }
848 void setAttributeExplicitly(int32_t attribute) {
849 explicitlySetAttributes |= (uint32_t)1 << attribute;
850 }
851 UBool attributeHasBeenSetExplicitly(int32_t attribute) const {
852 // assert(0 <= attribute < ATTR_LIMIT);
853 return (UBool)((explicitlySetAttributes & ((uint32_t)1 << attribute)) != 0);
854 }
855
863 UBool isUnsafe(UChar32 c) const;
864
865 static void U_CALLCONV computeMaxExpansions(const CollationTailoring *t, UErrorCode &errorCode);
866 UBool initMaxExpansions(UErrorCode &errorCode) const;
867
868 void setFastLatinOptions(CollationSettings &ownedSettings) const;
869
870 const CollationData *data;
871 const CollationSettings *settings; // reference-counted
872 const CollationTailoring *tailoring; // alias of cacheEntry->tailoring
873 const CollationCacheEntry *cacheEntry; // reference-counted
874 Locale validLocale;
875 uint32_t explicitlySetAttributes;
876
877 UBool actualLocaleIsSameAsValid;
878 };
879
880 U_NAMESPACE_END
881
882 #endif // !UCONFIG_NO_COLLATION
883
884 #endif /* U_SHOW_CPLUSPLUS_API */
885
886 #endif // TBLCOLL_H
coll.h
C++ API: Collation Service.
U_FINAL
#define U_FINAL
Definition: umachine.h:141
icu::RuleBasedCollator::rbcFromUCollator
static RuleBasedCollator * rbcFromUCollator(UCollator *uc)
Definition: tblcoll.h:786
icu::CollationKey
Collation keys are generated by the Collator class.
Definition: sortkey.h:101
UColAttribute
UColAttribute
Attributes that collation service understands.
Definition: ucol.h:245
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::UnicodeSet
A mutable set of Unicode characters and multicharacter strings.
Definition: uniset.h:285
icu::Collator::ECollationStrength
ECollationStrength
Base letter represents a primary difference.
Definition: coll.h:197
U_I18N_API
#define U_I18N_API
Definition: utypes.h:301
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
ULocDataLocaleType
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
Definition: uloc.h:338
U_CALLCONV
#define U_CALLCONV
Definition: platform.h:870
icu::Collator::getVariableTop
virtual uint32_t getVariableTop(UErrorCode &status) const =0
Gets the variable top value of a Collator.
UCOL_ATTRIBUTE_COUNT
@ UCOL_ATTRIBUTE_COUNT
One more than the highest normal UColAttribute value.
Definition: ucol.h:355
UColRuleOption
UColRuleOption
Options for retrieving the rule string.
Definition: ucol.h:362
icu::Collator::internalNextSortKeyPart
virtual int32_t internalNextSortKeyPart(UCharIterator *iter, uint32_t state[2], uint8_t *dest, int32_t count, UErrorCode &errorCode) const
Implements ucol_nextSortKeyPart().
icu::Collator::getTailoredSet
virtual UnicodeSet * getTailoredSet(UErrorCode &status) const
Get a UnicodeSet that contains all the characters and sequences tailored in this collator.
icu::Collator::compareUTF8
virtual UCollationResult compareUTF8(const StringPiece &source, const StringPiece &target, UErrorCode &status) const
Compares two UTF-8 strings using the Collator.
icu::Collator
The Collator class performs locale-sensitive string comparison.
Definition: coll.h:167
icu::Collator::hashCode
virtual int32_t hashCode(void) const =0
Generates the hash code for the collation object.
icu::Collator::setAttribute
virtual void setAttribute(UColAttribute attr, UColAttributeValue value, UErrorCode &status)=0
Universal attribute setter.
UColAttributeValue
UColAttributeValue
Enum containing attribute values for controlling collation behavior.
Definition: ucol.h:92
icu::Collator::internalGetShortDefinitionString
virtual int32_t internalGetShortDefinitionString(const char *locale, char *buffer, int32_t capacity, UErrorCode &status) const
Get the short definition string for a collator.
UCollationResult
UCollationResult
UCOL_LESS is returned if source string is compared to be less than target string in the ucol_strcoll(...
Definition: ucol.h:76
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
icu::Collator::internalCompareUTF8
virtual UCollationResult internalCompareUTF8(const char *left, int32_t leftLength, const char *right, int32_t rightLength, UErrorCode &errorCode) const
Implements ucol_strcollUTF8().
icu::Collator::operator==
virtual bool operator==(const Collator &other) const
Returns true if "other" is the same as "this".
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:467
icu::Collator::getAttribute
virtual UColAttributeValue getAttribute(UColAttribute attr, UErrorCode &status) const =0
Universal attribute getter.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
icu::Collator::setVariableTop
virtual uint32_t setVariableTop(const char16_t *varTop, int32_t len, UErrorCode &status)=0
Sets the variable top to the primary weight of the specified string.
icu::Collator::setReorderCodes
virtual void setReorderCodes(const int32_t *reorderCodes, int32_t reorderCodesLength, UErrorCode &status)
Sets the ordering of scripts for this collator.
icu::RuleBasedCollator
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition: tblcoll.h:115
icu::Collator::getReorderCodes
virtual int32_t getReorderCodes(int32_t *dest, int32_t destCapacity, UErrorCode &status) const
Retrieves the reordering codes for this collator.
icu::Collator::getMaxVariable
virtual UColReorderCode getMaxVariable() const
Returns the maximum reordering group whose characters are affected by UCOL_ALTERNATE_HANDLING.
UCollator
struct UCollator UCollator
structure representing a collator object instance
Definition: ucol.h:61
icu::Collator::getDynamicClassID
virtual UClassID getDynamicClassID(void) const override=0
Returns a unique class ID POLYMORPHICALLY.
icu::Collator::clone
virtual Collator * clone() const =0
Makes a copy of this object.
icu::Collator::getVersion
virtual void getVersion(UVersionInfo info) const =0
Gets the version information for a Collator.
icu::Collator::getSortKey
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 a UnicodeString.
icu::CharacterIterator
Abstract class that defines an API for iteration on text objects.
Definition: chariter.h:361
UCharIterator
C API for code unit iteration.
Definition: uiter.h:341
uiter.h
C API: Unicode Character Iteration.
icu::Collator::getCollationKey
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.
icu::Collator::fromUCollator
static Collator * fromUCollator(UCollator *uc)
Definition: coll.h:1184
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:59
icu::Collator::getLocale
virtual Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const =0
Gets the locale of the Collator.
locid.h
C++ API: Locale ID object.
icu::Collator::compare
virtual EComparisonResult compare(const UnicodeString &source, const UnicodeString &target) const
The comparison function compares the character data stored in two different strings.
icu::CollationElementIterator
The CollationElementIterator class is used as an iterator to walk through each character of an inte...
Definition: coleitr.h:121
icu::Collator::setMaxVariable
virtual Collator & setMaxVariable(UColReorderCode group, UErrorCode &errorCode)
Sets the variable top to the top of the specified reordering group.
icu::StringPiece
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:60
icu::Collator::setLocales
virtual void setLocales(const Locale &requestedLocale, const Locale &validLocale, const Locale &actualLocale)
Used internally by registration to define the requested and valid locales.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
ucol.h
C API: Collator.
icu::RuleBasedCollator::rbcFromUCollator
static const RuleBasedCollator * rbcFromUCollator(const UCollator *uc)
Definition: tblcoll.h:790
UColReorderCode
UColReorderCode
Enum containing the codes for reordering segments of the collation table that are not script codes.
Definition: ucol.h:149