ICU 62.1 62.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 !UCONFIG_NO_COLLATION
68
69#include "unicode/coll.h"
70#include "unicode/locid.h"
71#include "unicode/uiter.h"
72#include "unicode/ucol.h"
73
75
76struct CollationCacheEntry;
77struct CollationData;
78struct CollationSettings;
79struct CollationTailoring;
83class StringSearch;
87class CollationElementIterator;
88class CollationKey;
89class SortKeyByteSink;
90class UnicodeSet;
91class UnicodeString;
92class UVector64;
93
114public:
124
137
150
165
166#ifndef U_HIDE_INTERNAL_API
173 UErrorCode &errorCode);
174#endif /* U_HIDE_INTERNAL_API */
175
182
183
201 RuleBasedCollator(const uint8_t *bin, int32_t length,
202 const RuleBasedCollator *base,
204
210
217
224 virtual UBool operator==(const Collator& other) const;
225
231 virtual Collator* clone(void) const;
232
244 const UnicodeString& source) const;
245
256 const CharacterIterator& source) const;
257
258 // Make deprecated versions of Collator::compare() visible.
259 using Collator::compare;
260
274 const UnicodeString& target,
275 UErrorCode &status) const;
276
291 const UnicodeString& target,
292 int32_t length,
293 UErrorCode &status) const;
294
311 virtual UCollationResult compare(const char16_t* source, int32_t sourceLength,
312 const char16_t* target, int32_t targetLength,
313 UErrorCode &status) const;
314
328 UErrorCode &status) const;
329
344 const StringPiece &target,
345 UErrorCode &status) const;
346
363 UErrorCode& status) const;
364
380 virtual CollationKey& getCollationKey(const char16_t *source,
381 int32_t sourceLength,
383 UErrorCode& status) const;
384
390 virtual int32_t hashCode() const;
391
403
409 const UnicodeString& getRules() const;
410
416 virtual void getVersion(UVersionInfo info) const;
417
418#ifndef U_HIDE_DEPRECATED_API
435 int32_t getMaxExpansion(int32_t order) const;
436#endif /* U_HIDE_DEPRECATED_API */
437
448 virtual UClassID getDynamicClassID(void) const;
449
462
463#ifndef U_HIDE_DEPRECATED_API
474 uint8_t *cloneRuleData(int32_t &length, UErrorCode &status) const;
475#endif /* U_HIDE_DEPRECATED_API */
476
487 int32_t cloneBinary(uint8_t *buffer, int32_t capacity, UErrorCode &status) const;
488
500 void getRules(UColRuleOption delta, UnicodeString &buffer) const;
501
511
520 UErrorCode &status) const;
521
539
547
564 virtual uint32_t setVariableTop(const char16_t *varTop, int32_t len, UErrorCode &status);
565
582
594 virtual void setVariableTop(uint32_t varTop, UErrorCode &status);
595
603 virtual uint32_t getVariableTop(UErrorCode &status) const;
604
615
630 virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result,
631 int32_t resultLength) const;
632
649 virtual int32_t getSortKey(const char16_t *source, int32_t sourceLength,
650 uint8_t *result, int32_t resultLength) const;
651
665 virtual int32_t getReorderCodes(int32_t *dest,
666 int32_t destCapacity,
667 UErrorCode& status) const;
668
680 virtual void setReorderCodes(const int32_t* reorderCodes,
681 int32_t reorderCodesLength,
683
689 const char *left, int32_t leftLength,
690 const char *right, int32_t rightLength,
691 UErrorCode &errorCode) const;
692
716 virtual int32_t internalGetShortDefinitionString(const char *locale,
717 char *buffer,
718 int32_t capacity,
719 UErrorCode &status) const;
720
725 virtual int32_t internalNextSortKeyPart(
726 UCharIterator *iter, uint32_t state[2],
727 uint8_t *dest, int32_t count, UErrorCode &errorCode) const;
728
729 // Do not enclose the default constructor with #ifndef U_HIDE_INTERNAL_API
735
736#ifndef U_HIDE_INTERNAL_API
743 const char *internalGetLocaleID(ULocDataLocaleType type, UErrorCode &errorCode) const;
744
759 UBool addPrefixes, UErrorCode &errorCode) const;
760
766 void internalAddContractions(UChar32 c, UnicodeSet &set, UErrorCode &errorCode) const;
767
773 const UnicodeString &rules,
774 int32_t strength,
777 UErrorCode &errorCode);
778
781 return dynamic_cast<RuleBasedCollator *>(fromUCollator(uc));
782 }
784 static inline const RuleBasedCollator *rbcFromUCollator(const UCollator *uc) {
785 return dynamic_cast<const RuleBasedCollator *>(fromUCollator(uc));
786 }
787
792 void internalGetCEs(const UnicodeString &str, UVector64 &ces, UErrorCode &errorCode) const;
793#endif // U_HIDE_INTERNAL_API
794
795protected:
803 virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
804
805private:
806 friend class CollationElementIterator;
807 friend class Collator;
808
810
816 enum Attributes {
817 ATTR_VARIABLE_TOP = UCOL_ATTRIBUTE_COUNT,
818 ATTR_LIMIT
819 };
820
821 void adoptTailoring(CollationTailoring *t, UErrorCode &errorCode);
822
823 // Both lengths must be <0 or else both must be >=0.
824 UCollationResult doCompare(const char16_t *left, int32_t leftLength,
825 const char16_t *right, int32_t rightLength,
826 UErrorCode &errorCode) const;
827 UCollationResult doCompare(const uint8_t *left, int32_t leftLength,
828 const uint8_t *right, int32_t rightLength,
829 UErrorCode &errorCode) const;
830
831 void writeSortKey(const char16_t *s, int32_t length,
832 SortKeyByteSink &sink, UErrorCode &errorCode) const;
833
834 void writeIdenticalLevel(const char16_t *s, const char16_t *limit,
835 SortKeyByteSink &sink, UErrorCode &errorCode) const;
836
837 const CollationSettings &getDefaultSettings() const;
838
839 void setAttributeDefault(int32_t attribute) {
840 explicitlySetAttributes &= ~((uint32_t)1 << attribute);
841 }
842 void setAttributeExplicitly(int32_t attribute) {
843 explicitlySetAttributes |= (uint32_t)1 << attribute;
844 }
845 UBool attributeHasBeenSetExplicitly(int32_t attribute) const {
846 // assert(0 <= attribute < ATTR_LIMIT);
847 return (UBool)((explicitlySetAttributes & ((uint32_t)1 << attribute)) != 0);
848 }
849
857 UBool isUnsafe(UChar32 c) const;
858
859 static void U_CALLCONV computeMaxExpansions(const CollationTailoring *t, UErrorCode &errorCode);
860 UBool initMaxExpansions(UErrorCode &errorCode) const;
861
862 void setFastLatinOptions(CollationSettings &ownedSettings) const;
863
864 const CollationData *data;
865 const CollationSettings *settings; // reference-counted
866 const CollationTailoring *tailoring; // alias of cacheEntry->tailoring
867 const CollationCacheEntry *cacheEntry; // reference-counted
868 Locale validLocale;
869 uint32_t explicitlySetAttributes;
870
871 UBool actualLocaleIsSameAsValid;
872};
873
875
876#endif // !UCONFIG_NO_COLLATION
877#endif // TBLCOLL_H
Abstract class that defines an API for iteration on text objects.
Definition chariter.h:358
The CollationElementIterator class is used as an iterator to walk through each character of an inte...
Definition coleitr.h:119
Collation keys are generated by the Collator class.
Definition sortkey.h:99
The Collator class performs locale-sensitive string comparison.
Definition coll.h:165
static Collator * fromUCollator(UCollator *uc)
Definition coll.h:1166
ECollationStrength
Base letter represents a primary difference.
Definition coll.h:196
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:188
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition tblcoll.h:113
RuleBasedCollator(const UnicodeString &rules, UColAttributeValue decompositionMode, UErrorCode &status)
RuleBasedCollator constructor.
virtual UBool operator==(const Collator &other) const
Returns true if argument is the same as this object.
virtual void setVariableTop(uint32_t varTop, UErrorCode &status)
Sets the variable top to the specified primary weight.
virtual void setReorderCodes(const int32_t *reorderCodes, int32_t reorderCodesLength, UErrorCode &status)
Sets the ordering of scripts for this collator.
virtual CollationKey & getCollationKey(const char16_t *source, int32_t sourceLength, CollationKey &key, UErrorCode &status) const
Transforms a specified region of the string into a series of characters that can be compared with Col...
RuleBasedCollator & operator=(const RuleBasedCollator &other)
Assignment operator.
virtual CollationKey & getCollationKey(const UnicodeString &source, CollationKey &key, UErrorCode &status) const
Transforms the string into a series of characters that can be compared with CollationKey....
RuleBasedCollator(const UnicodeString &rules, ECollationStrength collationStrength, UColAttributeValue decompositionMode, UErrorCode &status)
RuleBasedCollator constructor.
RuleBasedCollator(const uint8_t *bin, int32_t length, const RuleBasedCollator *base, UErrorCode &status)
Opens a collator from a collator binary image created using cloneBinary.
virtual UCollationResult compare(const char16_t *source, int32_t sourceLength, const char16_t *target, int32_t targetLength, UErrorCode &status) const
The comparison function compares the character data stored in two different string arrays.
virtual int32_t getSortKey(const char16_t *source, int32_t sourceLength, uint8_t *result, int32_t resultLength) const
Get the sort key as an array of bytes from a char16_t buffer.
static const RuleBasedCollator * rbcFromUCollator(const UCollator *uc)
Definition tblcoll.h:784
RuleBasedCollator(const UnicodeString &rules, UParseError &parseError, UnicodeString &reason, UErrorCode &errorCode)
TODO: document & propose as public API.
virtual UCollationResult compare(UCharIterator &sIter, UCharIterator &tIter, UErrorCode &status) const
Compares two strings using the Collator.
virtual void setLocales(const Locale &requestedLocale, const Locale &validLocale, const Locale &actualLocale)
Used internally by registration to define the requested and valid locales.
virtual uint32_t getVariableTop(UErrorCode &status) const
Gets the variable top value of a Collator.
virtual void setAttribute(UColAttribute attr, UColAttributeValue value, UErrorCode &status)
Universal attribute setter.
virtual uint32_t setVariableTop(const char16_t *varTop, int32_t len, UErrorCode &status)
Sets the variable top to the primary weight of the specified string.
virtual Collator * clone(void) const
Makes a copy of this object.
virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status)
Sets the variable top to the primary weight of the specified string.
static UClassID getStaticClassID(void)
Returns the class ID for this class.
void internalBuildTailoring(const UnicodeString &rules, int32_t strength, UColAttributeValue decompositionMode, UParseError *outParseError, UnicodeString *outReason, UErrorCode &errorCode)
Implements from-rule constructors, and ucol_openRules().
void internalAddContractions(UChar32 c, UnicodeSet &set, UErrorCode &errorCode) const
Adds the contractions that start with character c to the set.
virtual UColAttributeValue getAttribute(UColAttribute attr, UErrorCode &status) const
Universal attribute getter.
void internalGetContractionsAndExpansions(UnicodeSet *contractions, UnicodeSet *expansions, UBool addPrefixes, UErrorCode &errorCode) const
Implements ucol_getContractionsAndExpansions().
virtual UnicodeSet * getTailoredSet(UErrorCode &status) const
Get a UnicodeSet that contains all the characters and sequences tailored in this collator.
virtual UClassID getDynamicClassID(void) const
Returns a unique class ID POLYMORPHICALLY.
virtual Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Gets the locale of the Collator.
virtual ~RuleBasedCollator()
Destructor.
virtual Collator & setMaxVariable(UColReorderCode group, UErrorCode &errorCode)
Sets the variable top to the top of the specified reordering group.
int32_t cloneBinary(uint8_t *buffer, int32_t capacity, UErrorCode &status) const
Creates a binary image of a collator.
virtual CollationElementIterator * createCollationElementIterator(const CharacterIterator &source) const
Creates a collation element iterator for the source.
virtual CollationElementIterator * createCollationElementIterator(const UnicodeString &source) const
Creates a collation element iterator for the source string.
virtual int32_t internalGetShortDefinitionString(const char *locale, char *buffer, int32_t capacity, UErrorCode &status) const
Get the short definition string for a collator.
void internalGetCEs(const UnicodeString &str, UVector64 &ces, UErrorCode &errorCode) const
Appends the CEs for the string to the vector.
int32_t getMaxExpansion(int32_t order) const
Returns the maximum length of any expansion sequences that end with the specified comparison order.
uint8_t * cloneRuleData(int32_t &length, UErrorCode &status) const
Do not use this method: The caller and the ICU library might use different heaps.
virtual int32_t internalNextSortKeyPart(UCharIterator *iter, uint32_t state[2], uint8_t *dest, int32_t count, UErrorCode &errorCode) const
Implements ucol_nextSortKeyPart().
RuleBasedCollator(const UnicodeString &rules, ECollationStrength collationStrength, UErrorCode &status)
RuleBasedCollator constructor.
RuleBasedCollator(const UnicodeString &rules, UErrorCode &status)
RuleBasedCollator constructor.
virtual UColReorderCode getMaxVariable() const
Returns the maximum reordering group whose characters are affected by UCOL_ALTERNATE_HANDLING.
virtual UCollationResult internalCompareUTF8(const char *left, int32_t leftLength, const char *right, int32_t rightLength, UErrorCode &errorCode) const
Implements ucol_strcollUTF8().
const char * internalGetLocaleID(ULocDataLocaleType type, UErrorCode &errorCode) const
Implements ucol_getLocaleByType().
RuleBasedCollator()
Only for use in ucol_openRules().
virtual int32_t hashCode() const
Generates the hash code for the rule-based collation object.
virtual UCollationResult compare(const UnicodeString &source, const UnicodeString &target, int32_t length, UErrorCode &status) const
Does the same thing as compare but limits the comparison to a specified length.
RuleBasedCollator(const RuleBasedCollator &other)
Copy constructor.
virtual void getVersion(UVersionInfo info) const
Gets the version information for a Collator.
virtual UCollationResult compareUTF8(const StringPiece &source, const StringPiece &target, UErrorCode &status) const
Compares two UTF-8 strings using the Collator.
virtual UCollationResult compare(const UnicodeString &source, const UnicodeString &target, UErrorCode &status) const
The comparison function compares the character data stored in two different strings.
virtual int32_t getSortKey(const UnicodeString &source, uint8_t *result, int32_t resultLength) const
Get the sort key as an array of bytes from a UnicodeString.
virtual int32_t getReorderCodes(int32_t *dest, int32_t destCapacity, UErrorCode &status) const
Retrieves the reordering codes for this collator.
static RuleBasedCollator * rbcFromUCollator(UCollator *uc)
Definition tblcoll.h:780
const UnicodeString & getRules() const
Gets the tailoring rules for this collator.
void getRules(UColRuleOption delta, UnicodeString &buffer) const
Returns current rules.
A string-like object that points to a sized piece of memory.
Definition stringpiece.h:54
A mutable set of Unicode characters and multicharacter strings.
Definition uniset.h:278
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:287
C++ API: Collation Service.
C++ API: Locale ID object.
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition platform.h:835
C API for code unit iteration.
Definition uiter.h:341
A UParseError struct is used to returned detailed information about parsing errors.
Definition parseerr.h:58
C API: Collator.
struct UCollator UCollator
structure representing a collator object instance
Definition ucol.h:58
UColRuleOption
Options for retrieving the rule string.
Definition ucol.h:357
UColAttribute
Attributes that collation service understands.
Definition ucol.h:242
@ UCOL_ATTRIBUTE_COUNT
One more than the highest normal UColAttribute value.
Definition ucol.h:351
UCollationResult
UCOL_LESS is returned if source string is compared to be less than target string in the ucol_strcoll(...
Definition ucol.h:73
UColAttributeValue
Enum containing attribute values for controling collation behavior.
Definition ucol.h:89
UColReorderCode
Enum containing the codes for reordering segments of the collation table that are not script codes.
Definition ucol.h:146
C API: Unicode Character Iteration.
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
Definition uloc.h:338
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition umachine.h:400
int8_t UBool
The ICU boolean type.
Definition umachine.h:236
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:93
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:396
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:360
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:138
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
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:137