ICU4C 79
Loading...
Searching...
No Matches
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
14
61
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
76U_NAMESPACE_BEGIN
77
78struct CollationCacheEntry;
79struct CollationData;
80struct CollationSettings;
81struct CollationTailoring;
85class StringSearch;
89class CollationElementIterator;
90class CollationKey;
91class SortKeyByteSink;
92class UnicodeSet;
93class UnicodeString;
94class UVector64;
95
115class U_I18N_API_CLASS RuleBasedCollator final : public Collator {
116public:
126
137 ECollationStrength collationStrength,
138 UErrorCode& status);
139
150 UColAttributeValue decompositionMode,
151 UErrorCode& status);
152
164 ECollationStrength collationStrength,
165 UColAttributeValue decompositionMode,
166 UErrorCode& status);
167
168#ifndef U_HIDE_INTERNAL_API
174 UParseError& parseError,
175 UnicodeString& reason,
176 UErrorCode& errorCode);
177#endif /* U_HIDE_INTERNAL_API */
178
185
202 U_I18N_API RuleBasedCollator(const uint8_t* bin,
203 int32_t length,
204 const RuleBasedCollator* base,
205 UErrorCode& status);
206
212
219
226 U_I18N_API virtual bool operator==(const Collator& other) const override;
227
233 U_I18N_API virtual RuleBasedCollator* clone() const override;
234
245 U_I18N_API CollationElementIterator*
247
257 U_I18N_API CollationElementIterator*
259
260 // Make deprecated versions of Collator::compare() visible.
261 using Collator::compare;
262
276 const UnicodeString& target,
277 UErrorCode& status) const override;
278
293 const UnicodeString& target,
294 int32_t length,
295 UErrorCode& status) const override;
296
313 U_I18N_API virtual UCollationResult compare(const char16_t* source, int32_t sourceLength,
314 const char16_t* target, int32_t targetLength,
315 UErrorCode& status) const override;
316
329 UCharIterator& tIter,
330 UErrorCode& status) const override;
331
346 const StringPiece& target,
347 UErrorCode& status) const override;
348
364 CollationKey& key,
365 UErrorCode& status) const override;
366
382 U_I18N_API virtual CollationKey& getCollationKey(const char16_t* source,
383 int32_t sourceLength,
384 CollationKey& key,
385 UErrorCode& status) const override;
386
392 U_I18N_API virtual int32_t hashCode() const override;
393
394#ifndef U_FORCE_HIDE_DEPRECATED_API
405 U_I18N_API virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const override;
406#endif // U_FORCE_HIDE_DEPRECATED_API
407
414
420 U_I18N_API virtual void getVersion(UVersionInfo info) const override;
421
422#ifndef U_HIDE_DEPRECATED_API
439 U_I18N_API int32_t getMaxExpansion(int32_t order) const;
440#endif /* U_HIDE_DEPRECATED_API */
441
452 U_I18N_API virtual UClassID getDynamicClassID() const override;
453
466
467#ifndef U_HIDE_DEPRECATED_API
478 U_I18N_API uint8_t* cloneRuleData(int32_t& length, UErrorCode& status) const;
479#endif /* U_HIDE_DEPRECATED_API */
480
491 U_I18N_API int32_t cloneBinary(uint8_t* buffer, int32_t capacity, UErrorCode& status) const;
492
505
514 UColAttributeValue value,
515 UErrorCode& status) override;
516
525 UErrorCode& status) const override;
526
543 U_I18N_API virtual Collator& setMaxVariable(UColReorderCode group, UErrorCode& errorCode) override;
544
551 U_I18N_API virtual UColReorderCode getMaxVariable() const override;
552
553#ifndef U_FORCE_HIDE_DEPRECATED_API
570 U_I18N_API virtual uint32_t setVariableTop(const char16_t* varTop,
571 int32_t len,
572 UErrorCode& status) override;
573
589 U_I18N_API virtual uint32_t setVariableTop(const UnicodeString& varTop, UErrorCode& status) override;
590
602 U_I18N_API virtual void setVariableTop(uint32_t varTop, UErrorCode& status) override;
603#endif // U_FORCE_HIDE_DEPRECATED_API
604
612 U_I18N_API virtual uint32_t getVariableTop(UErrorCode& status) const override;
613
623 U_I18N_API virtual UnicodeSet* getTailoredSet(UErrorCode& status) const override;
624
639 U_I18N_API virtual int32_t getSortKey(const UnicodeString& source,
640 uint8_t* result,
641 int32_t resultLength) const override;
642
659 U_I18N_API virtual int32_t getSortKey(const char16_t* source,
660 int32_t sourceLength,
661 uint8_t* result,
662 int32_t resultLength) const override;
663
677 U_I18N_API virtual int32_t getReorderCodes(int32_t* dest,
678 int32_t destCapacity,
679 UErrorCode& status) const override;
680
692 U_I18N_API virtual void setReorderCodes(const int32_t* reorderCodes,
693 int32_t reorderCodesLength,
694 UErrorCode& status) override;
695
700 U_I18N_API virtual UCollationResult internalCompareUTF8(const char* left, int32_t leftLength,
701 const char* right, int32_t rightLength,
702 UErrorCode& errorCode) const override;
703
727 U_I18N_API virtual int32_t internalGetShortDefinitionString(const char* locale,
728 char* buffer,
729 int32_t capacity,
730 UErrorCode& status) const override;
731
737 uint32_t state[2],
738 uint8_t* dest,
739 int32_t count,
740 UErrorCode& errorCode) const override;
741
742 // Do not enclose the default constructor with #ifndef U_HIDE_INTERNAL_API
748
749#ifndef U_HIDE_INTERNAL_API
756 U_I18N_API const char* internalGetLocaleID(ULocDataLocaleType type, UErrorCode& errorCode) const;
757
771 UnicodeSet* expansions,
772 UBool addPrefixes,
773 UErrorCode& errorCode) const;
774
781
787 int32_t strength,
788 UColAttributeValue decompositionMode,
789 UParseError* outParseError,
790 UnicodeString* outReason,
791 UErrorCode& errorCode);
792
795 return dynamic_cast<RuleBasedCollator *>(fromUCollator(uc));
796 }
797
798 static inline const RuleBasedCollator *rbcFromUCollator(const UCollator *uc) {
799 return dynamic_cast<const RuleBasedCollator *>(fromUCollator(uc));
800 }
801
807 UVector64& ces,
808 UErrorCode& errorCode) const;
809#endif // U_HIDE_INTERNAL_API
810
811protected:
819 virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale) override;
820
821private:
822 friend class CollationElementIterator;
823 friend class Collator;
824
825 RuleBasedCollator(const CollationCacheEntry *entry);
826
832 enum Attributes {
833 ATTR_VARIABLE_TOP = UCOL_ATTRIBUTE_COUNT,
834 ATTR_LIMIT
835 };
836
837 void adoptTailoring(CollationTailoring *t, UErrorCode &errorCode);
838
839 // Both lengths must be <0 or else both must be >=0.
840 UCollationResult doCompare(const char16_t *left, int32_t leftLength,
841 const char16_t *right, int32_t rightLength,
842 UErrorCode &errorCode) const;
843 UCollationResult doCompare(const uint8_t *left, int32_t leftLength,
844 const uint8_t *right, int32_t rightLength,
845 UErrorCode &errorCode) const;
846
847 void writeSortKey(const char16_t *s, int32_t length,
848 SortKeyByteSink &sink, UErrorCode &errorCode) const;
849
850 void writeIdenticalLevel(const char16_t *s, const char16_t *limit,
851 SortKeyByteSink &sink, UErrorCode &errorCode) const;
852
853 const CollationSettings &getDefaultSettings() const;
854
855 void setAttributeDefault(int32_t attribute) {
856 explicitlySetAttributes &= ~(static_cast<uint32_t>(1) << attribute);
857 }
858 void setAttributeExplicitly(int32_t attribute) {
859 explicitlySetAttributes |= static_cast<uint32_t>(1) << attribute;
860 }
861 UBool attributeHasBeenSetExplicitly(int32_t attribute) const {
862 // assert(0 <= attribute < ATTR_LIMIT);
863 return (explicitlySetAttributes & (static_cast<uint32_t>(1) << attribute)) != 0;
864 }
865
873 UBool isUnsafe(UChar32 c) const;
874
875 static void U_CALLCONV computeMaxExpansions(const CollationTailoring *t, UErrorCode &errorCode);
876 UBool initMaxExpansions(UErrorCode &errorCode) const;
877
878 void setFastLatinOptions(CollationSettings &ownedSettings) const;
879
880 const CollationData *data;
881 const CollationSettings *settings; // reference-counted
882 const CollationTailoring *tailoring; // alias of cacheEntry->tailoring
883 const CollationCacheEntry *cacheEntry; // reference-counted
884 Locale validLocale;
885 uint32_t explicitlySetAttributes;
886
887 UBool actualLocaleIsSameAsValid;
888};
889
890U_NAMESPACE_END
891
892#endif // !UCONFIG_NO_COLLATION
893
894#endif /* U_SHOW_CPLUSPLUS_API */
895
896#endif // TBLCOLL_H
Abstract class that defines an API for iteration on text objects.
Definition chariter.h:363
Collation keys are generated by the Collator class.
Definition sortkey.h:101
static Collator * fromUCollator(UCollator *uc)
Definition coll.h:1232
virtual EComparisonResult compare(const UnicodeString &source, const UnicodeString &target) const
The comparison function compares the character data stored in two different strings.
ECollationStrength
Base letter represents a primary difference.
Definition coll.h:204
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:198
U_I18N_API uint8_t * cloneRuleData(int32_t &length, UErrorCode &status) const
Do not use this method: The caller and the ICU library might use different heaps.
U_I18N_API RuleBasedCollator(const UnicodeString &rules, ECollationStrength collationStrength, UColAttributeValue decompositionMode, UErrorCode &status)
RuleBasedCollator constructor.
virtual U_I18N_API uint32_t getVariableTop(UErrorCode &status) const override
Gets the variable top value of a Collator.
virtual U_I18N_API UCollationResult compare(const UnicodeString &source, const UnicodeString &target, int32_t length, UErrorCode &status) const override
Does the same thing as compare but limits the comparison to a specified length.
virtual U_I18N_API UColAttributeValue getAttribute(UColAttribute attr, UErrorCode &status) const override
Universal attribute getter.
virtual U_I18N_API UCollationResult compare(UCharIterator &sIter, UCharIterator &tIter, UErrorCode &status) const override
Compares two strings using the Collator.
virtual U_I18N_API int32_t hashCode() const override
Generates the hash code for the rule-based collation object.
virtual U_I18N_API void setAttribute(UColAttribute attr, UColAttributeValue value, UErrorCode &status) override
Universal attribute setter.
virtual U_I18N_API UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
virtual void setLocales(const Locale &requestedLocale, const Locale &validLocale, const Locale &actualLocale) override
Used internally by registration to define the requested and valid locales.
virtual U_I18N_API uint32_t setVariableTop(const char16_t *varTop, int32_t len, UErrorCode &status) override
Sets the variable top to the primary weight of the specified string.
virtual U_I18N_API int32_t internalNextSortKeyPart(UCharIterator *iter, uint32_t state[2], uint8_t *dest, int32_t count, UErrorCode &errorCode) const override
Implements ucol_nextSortKeyPart().
U_I18N_API void internalGetCEs(const UnicodeString &str, UVector64 &ces, UErrorCode &errorCode) const
Appends the CEs for the string to the vector.
static const RuleBasedCollator * rbcFromUCollator(const UCollator *uc)
Definition tblcoll.h:798
virtual U_I18N_API int32_t getSortKey(const UnicodeString &source, uint8_t *result, int32_t resultLength) const override
Get the sort key as an array of bytes from a UnicodeString.
U_I18N_API RuleBasedCollator(const UnicodeString &rules, UColAttributeValue decompositionMode, UErrorCode &status)
RuleBasedCollator constructor.
U_I18N_API RuleBasedCollator & operator=(const RuleBasedCollator &other)
Assignment operator.
U_I18N_API RuleBasedCollator(const RuleBasedCollator &other)
Copy constructor.
U_I18N_API void internalBuildTailoring(const UnicodeString &rules, int32_t strength, UColAttributeValue decompositionMode, UParseError *outParseError, UnicodeString *outReason, UErrorCode &errorCode)
Implements from-rule constructors, and ucol_openRules().
U_I18N_API CollationElementIterator * createCollationElementIterator(const CharacterIterator &source) const
Creates a collation element iterator for the source.
virtual U_I18N_API UCollationResult internalCompareUTF8(const char *left, int32_t leftLength, const char *right, int32_t rightLength, UErrorCode &errorCode) const override
Implements ucol_strcollUTF8().
virtual U_I18N_API UCollationResult compare(const char16_t *source, int32_t sourceLength, const char16_t *target, int32_t targetLength, UErrorCode &status) const override
The comparison function compares the character data stored in two different string arrays.
virtual U_I18N_API int32_t getReorderCodes(int32_t *dest, int32_t destCapacity, UErrorCode &status) const override
Retrieves the reordering codes for this collator.
virtual U_I18N_API Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const override
Gets the locale of the Collator.
virtual U_I18N_API int32_t getSortKey(const char16_t *source, int32_t sourceLength, uint8_t *result, int32_t resultLength) const override
Get the sort key as an array of bytes from a char16_t buffer.
virtual U_I18N_API UColReorderCode getMaxVariable() const override
Returns the maximum reordering group whose characters are affected by UCOL_ALTERNATE_HANDLING.
U_I18N_API const UnicodeString & getRules() const
Gets the tailoring rules for this collator.
virtual U_I18N_API void setVariableTop(uint32_t varTop, UErrorCode &status) override
Sets the variable top to the specified primary weight.
virtual U_I18N_API CollationKey & getCollationKey(const char16_t *source, int32_t sourceLength, CollationKey &key, UErrorCode &status) const override
Transforms a specified region of the string into a series of characters that can be compared with Col...
virtual U_I18N_API int32_t internalGetShortDefinitionString(const char *locale, char *buffer, int32_t capacity, UErrorCode &status) const override
Get the short definition string for a collator.
U_I18N_API int32_t getMaxExpansion(int32_t order) const
Returns the maximum length of any expansion sequences that end with the specified comparison order.
U_I18N_API RuleBasedCollator(const UnicodeString &rules, UErrorCode &status)
RuleBasedCollator constructor.
U_I18N_API const char * internalGetLocaleID(ULocDataLocaleType type, UErrorCode &errorCode) const
Implements ucol_getLocaleByType().
U_I18N_API void internalGetContractionsAndExpansions(UnicodeSet *contractions, UnicodeSet *expansions, UBool addPrefixes, UErrorCode &errorCode) const
Implements ucol_getContractionsAndExpansions().
U_I18N_API 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 U_I18N_API Collator & setMaxVariable(UColReorderCode group, UErrorCode &errorCode) override
Sets the variable top to the top of the specified reordering group.
virtual U_I18N_API UCollationResult compareUTF8(const StringPiece &source, const StringPiece &target, UErrorCode &status) const override
Compares two UTF-8 strings using the Collator.
virtual U_I18N_API UCollationResult compare(const UnicodeString &source, const UnicodeString &target, UErrorCode &status) const override
The comparison function compares the character data stored in two different strings.
virtual U_I18N_API void getVersion(UVersionInfo info) const override
Gets the version information for a Collator.
U_I18N_API RuleBasedCollator()
Only for use in ucol_openRules().
virtual U_I18N_API RuleBasedCollator * clone() const override
Makes a copy of this object.
virtual U_I18N_API uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) override
Sets the variable top to the primary weight of the specified string.
virtual U_I18N_API ~RuleBasedCollator()
Destructor.
static U_I18N_API UClassID getStaticClassID()
Returns the class ID for this class.
U_I18N_API int32_t cloneBinary(uint8_t *buffer, int32_t capacity, UErrorCode &status) const
Creates a binary image of a collator.
U_I18N_API CollationElementIterator * createCollationElementIterator(const UnicodeString &source) const
Creates a collation element iterator for the source string.
U_I18N_API void getRules(UColRuleOption delta, UnicodeString &buffer) const
Returns current rules.
virtual U_I18N_API UnicodeSet * getTailoredSet(UErrorCode &status) const override
Get a UnicodeSet that contains all the characters and sequences tailored in this collator.
static RuleBasedCollator * rbcFromUCollator(UCollator *uc)
Definition tblcoll.h:794
U_I18N_API void internalAddContractions(UChar32 c, UnicodeSet &set, UErrorCode &errorCode) const
Adds the contractions that start with character c to the set.
virtual U_I18N_API void setReorderCodes(const int32_t *reorderCodes, int32_t reorderCodesLength, UErrorCode &status) override
Sets the ordering of scripts for this collator.
virtual U_I18N_API bool operator==(const Collator &other) const override
Returns true if argument is the same as this object.
U_I18N_API RuleBasedCollator(const UnicodeString &rules, ECollationStrength collationStrength, UErrorCode &status)
RuleBasedCollator constructor.
virtual U_I18N_API CollationKey & getCollationKey(const UnicodeString &source, CollationKey &key, UErrorCode &status) const override
Transforms the string into a series of characters that can be compared with CollationKey....
U_I18N_API RuleBasedCollator(const UnicodeString &rules, UParseError &parseError, UnicodeString &reason, UErrorCode &errorCode)
TODO: document & propose as public API.
A string-like object that points to a sized piece of memory.
Definition stringpiece.h:61
A mutable set of Unicode characters and multicharacter strings.
Definition uniset.h:175
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
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:880
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:61
UColRuleOption
Options for retrieving the rule string.
Definition ucol.h:372
UColAttribute
Attributes that collation service understands.
Definition ucol.h:245
@ UCOL_ATTRIBUTE_COUNT
One more than the highest normal UColAttribute value.
Definition ucol.h:365
UCollationResult
UCOL_LESS is returned if source string is compared to be less than target string in the ucol_strcoll(...
Definition ucol.h:76
UColAttributeValue
Enum containing attribute values for controlling collation behavior.
Definition ucol.h:92
UColReorderCode
Enum containing the codes for reordering segments of the collation table that are not script codes.
Definition ucol.h:149
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:449
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509
#define U_I18N_API_CLASS
Set to export library symbols from inside the i18n library, and to import them from outside,...
Definition utypes.h:457
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:316
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