tblcoll.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
******************************************************************************
* Copyright (C) 1996-2016, International Business Machines Corporation and
* others. All Rights Reserved.
******************************************************************************
*/
#ifndef TBLCOLL_H
#define TBLCOLL_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_COLLATION
#include "unicode/coll.h"
#include "unicode/locid.h"
#include "unicode/uiter.h"
#include "unicode/ucol.h"
U_NAMESPACE_BEGIN
struct CollationCacheEntry;
struct CollationData;
struct CollationSettings;
struct CollationTailoring;
class StringSearch;
class CollationElementIterator;
class CollationKey;
class SortKeyByteSink;
class UnicodeSet;
class UnicodeString;
class UVector64;
class U_I18N_API RuleBasedCollator final : public Collator {
public:
RuleBasedCollator(const UnicodeString& rules, UErrorCode& status);
RuleBasedCollator(const UnicodeString& rules,
ECollationStrength collationStrength,
UErrorCode& status);
RuleBasedCollator(const UnicodeString& rules,
UColAttributeValue decompositionMode,
UErrorCode& status);
RuleBasedCollator(const UnicodeString& rules,
ECollationStrength collationStrength,
UColAttributeValue decompositionMode,
UErrorCode& status);
#ifndef U_HIDE_INTERNAL_API
RuleBasedCollator(const UnicodeString &rules,
UParseError &parseError, UnicodeString &reason,
UErrorCode &errorCode);
#endif /* U_HIDE_INTERNAL_API */
RuleBasedCollator(const RuleBasedCollator& other);
RuleBasedCollator(const uint8_t *bin, int32_t length,
const RuleBasedCollator *base,
UErrorCode &status);
virtual ~RuleBasedCollator();
RuleBasedCollator& operator=(const RuleBasedCollator& other);
virtual bool operator==(const Collator& other) const override;
virtual RuleBasedCollator* clone() const override;
virtual CollationElementIterator* createCollationElementIterator(
const UnicodeString& source) const;
virtual CollationElementIterator* createCollationElementIterator(
const CharacterIterator& source) const;
// Make deprecated versions of Collator::compare() visible.
using Collator::compare;
virtual UCollationResult compare(const UnicodeString& source,
const UnicodeString& target,
UErrorCode &status) const override;
virtual UCollationResult compare(const UnicodeString& source,
const UnicodeString& target,
int32_t length,
UErrorCode &status) const override;
virtual UCollationResult compare(const char16_t* source, int32_t sourceLength,
const char16_t* target, int32_t targetLength,
UErrorCode &status) const override;
virtual UCollationResult compare(UCharIterator &sIter,
UCharIterator &tIter,
UErrorCode &status) const override;
virtual UCollationResult compareUTF8(const StringPiece &source,
const StringPiece &target,
UErrorCode &status) const override;
virtual CollationKey& getCollationKey(const UnicodeString& source,
CollationKey& key,
UErrorCode& status) const override;
virtual CollationKey& getCollationKey(const char16_t *source,
int32_t sourceLength,
CollationKey& key,
UErrorCode& status) const override;
virtual int32_t hashCode() const override;
#ifndef U_FORCE_HIDE_DEPRECATED_API
virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const override;
#endif // U_FORCE_HIDE_DEPRECATED_API
const UnicodeString& getRules() const;
virtual void getVersion(UVersionInfo info) const override;
#ifndef U_HIDE_DEPRECATED_API
int32_t getMaxExpansion(int32_t order) const;
#endif /* U_HIDE_DEPRECATED_API */
virtual UClassID getDynamicClassID(void) const override;
static UClassID U_EXPORT2 getStaticClassID(void);
#ifndef U_HIDE_DEPRECATED_API
uint8_t *cloneRuleData(int32_t &length, UErrorCode &status) const;
#endif /* U_HIDE_DEPRECATED_API */
int32_t cloneBinary(uint8_t *buffer, int32_t capacity, UErrorCode &status) const;
void getRules(UColRuleOption delta, UnicodeString &buffer) const;
virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
UErrorCode &status) override;
virtual UColAttributeValue getAttribute(UColAttribute attr,
UErrorCode &status) const override;
virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCode) override;
virtual UColReorderCode getMaxVariable() const override;
#ifndef U_FORCE_HIDE_DEPRECATED_API
virtual uint32_t setVariableTop(const char16_t *varTop, int32_t len, UErrorCode &status) override;
virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) override;
virtual void setVariableTop(uint32_t varTop, UErrorCode &status) override;
#endif // U_FORCE_HIDE_DEPRECATED_API
virtual uint32_t getVariableTop(UErrorCode &status) const override;
virtual UnicodeSet *getTailoredSet(UErrorCode &status) const override;
virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result,
int32_t resultLength) const override;
virtual int32_t getSortKey(const char16_t *source, int32_t sourceLength,
uint8_t *result, int32_t resultLength) const override;
virtual int32_t getReorderCodes(int32_t *dest,
int32_t destCapacity,
UErrorCode& status) const override;
virtual void setReorderCodes(const int32_t* reorderCodes,
int32_t reorderCodesLength,
UErrorCode& status) override;
virtual UCollationResult internalCompareUTF8(
const char *left, int32_t leftLength,
const char *right, int32_t rightLength,
UErrorCode &errorCode) const override;
virtual int32_t internalGetShortDefinitionString(const char *locale,
char *buffer,
int32_t capacity,
UErrorCode &status) const override;
virtual int32_t internalNextSortKeyPart(
UCharIterator *iter, uint32_t state[2],
uint8_t *dest, int32_t count, UErrorCode &errorCode) const override;
// Do not enclose the default constructor with #ifndef U_HIDE_INTERNAL_API
RuleBasedCollator();
#ifndef U_HIDE_INTERNAL_API
const char *internalGetLocaleID(ULocDataLocaleType type, UErrorCode &errorCode) const;
void internalGetContractionsAndExpansions(
UnicodeSet *contractions, UnicodeSet *expansions,
UBool addPrefixes, UErrorCode &errorCode) const;
void internalAddContractions(UChar32 c, UnicodeSet &set, UErrorCode &errorCode) const;
void internalBuildTailoring(
const UnicodeString &rules,
int32_t strength,
UColAttributeValue decompositionMode,
UParseError *outParseError, UnicodeString *outReason,
UErrorCode &errorCode);
static inline RuleBasedCollator *rbcFromUCollator(UCollator *uc) {
return dynamic_cast<RuleBasedCollator *>(fromUCollator(uc));
}
static inline const RuleBasedCollator *rbcFromUCollator(const UCollator *uc) {
return dynamic_cast<const RuleBasedCollator *>(fromUCollator(uc));
}
void internalGetCEs(const UnicodeString &str, UVector64 &ces, UErrorCode &errorCode) const;
#endif // U_HIDE_INTERNAL_API
protected:
virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale) override;
private:
friend class CollationElementIterator;
friend class Collator;
RuleBasedCollator(const CollationCacheEntry *entry);
enum Attributes {
ATTR_VARIABLE_TOP = UCOL_ATTRIBUTE_COUNT,
ATTR_LIMIT
};
void adoptTailoring(CollationTailoring *t, UErrorCode &errorCode);
// Both lengths must be <0 or else both must be >=0.
UCollationResult doCompare(const char16_t *left, int32_t leftLength,
const char16_t *right, int32_t rightLength,
UErrorCode &errorCode) const;
UCollationResult doCompare(const uint8_t *left, int32_t leftLength,
const uint8_t *right, int32_t rightLength,
UErrorCode &errorCode) const;
void writeSortKey(const char16_t *s, int32_t length,
SortKeyByteSink &sink, UErrorCode &errorCode) const;
void writeIdenticalLevel(const char16_t *s, const char16_t *limit,
SortKeyByteSink &sink, UErrorCode &errorCode) const;
const CollationSettings &getDefaultSettings() const;
void setAttributeDefault(int32_t attribute) {
explicitlySetAttributes &= ~((uint32_t)1 << attribute);
}
void setAttributeExplicitly(int32_t attribute) {
explicitlySetAttributes |= (uint32_t)1 << attribute;
}
UBool attributeHasBeenSetExplicitly(int32_t attribute) const {
// assert(0 <= attribute < ATTR_LIMIT);
return (UBool)((explicitlySetAttributes & ((uint32_t)1 << attribute)) != 0);
}
UBool isUnsafe(UChar32 c) const;
static void U_CALLCONV computeMaxExpansions(const CollationTailoring *t, UErrorCode &errorCode);
UBool initMaxExpansions(UErrorCode &errorCode) const;
void setFastLatinOptions(CollationSettings &ownedSettings) const;
const CollationData *data;
const CollationSettings *settings; // reference-counted
const CollationTailoring *tailoring; // alias of cacheEntry->tailoring
const CollationCacheEntry *cacheEntry; // reference-counted
Locale validLocale;
uint32_t explicitlySetAttributes;
UBool actualLocaleIsSameAsValid;
};
U_NAMESPACE_END
#endif // !UCONFIG_NO_COLLATION
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // TBLCOLL_H
icu::CharacterIterator
Abstract class that defines an API for iteration on text objects.
Definition: chariter.h:361
icu::CollationElementIterator
The CollationElementIterator class is used as an iterator to walk through each character of an inte...
Definition: coleitr.h:121
icu::CollationKey
Collation keys are generated by the Collator class.
Definition: sortkey.h:101
icu::Collator
The Collator class performs locale-sensitive string comparison.
Definition: coll.h:167
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::Collator::fromUCollator
static Collator * fromUCollator(UCollator *uc)
Definition: coll.h:1184
icu::Collator::ECollationStrength
ECollationStrength
Base letter represents a primary difference.
Definition: coll.h:198
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::RuleBasedCollator
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition: tblcoll.h:115
icu::RuleBasedCollator::setVariableTop
virtual void setVariableTop(uint32_t varTop, UErrorCode &status) override
Sets the variable top to the specified primary weight.
icu::RuleBasedCollator::RuleBasedCollator
RuleBasedCollator(const UnicodeString &rules, UColAttributeValue decompositionMode, UErrorCode &status)
RuleBasedCollator constructor.
icu::RuleBasedCollator::internalCompareUTF8
virtual UCollationResult internalCompareUTF8(const char *left, int32_t leftLength, const char *right, int32_t rightLength, UErrorCode &errorCode) const override
Implements ucol_strcollUTF8().
icu::RuleBasedCollator::createCollationElementIterator
virtual CollationElementIterator * createCollationElementIterator(const CharacterIterator &source) const
Creates a collation element iterator for the source.
icu::RuleBasedCollator::getSortKey
virtual 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.
icu::RuleBasedCollator::operator=
RuleBasedCollator & operator=(const RuleBasedCollator &other)
Assignment operator.
icu::RuleBasedCollator::rbcFromUCollator
static RuleBasedCollator * rbcFromUCollator(UCollator *uc)
Definition: tblcoll.h:786
icu::RuleBasedCollator::rbcFromUCollator
static const RuleBasedCollator * rbcFromUCollator(const UCollator *uc)
Definition: tblcoll.h:790
icu::RuleBasedCollator::hashCode
virtual int32_t hashCode() const override
Generates the hash code for the rule-based collation object.
icu::RuleBasedCollator::getVariableTop
virtual uint32_t getVariableTop(UErrorCode &status) const override
Gets the variable top value of a Collator.
icu::RuleBasedCollator::RuleBasedCollator
RuleBasedCollator(const UnicodeString &rules, ECollationStrength collationStrength, UColAttributeValue decompositionMode, UErrorCode &status)
RuleBasedCollator constructor.
icu::RuleBasedCollator::setLocales
virtual void setLocales(const Locale &requestedLocale, const Locale &validLocale, const Locale &actualLocale) override
Used internally by registration to define the requested and valid locales.
icu::RuleBasedCollator::RuleBasedCollator
RuleBasedCollator(const uint8_t *bin, int32_t length, const RuleBasedCollator *base, UErrorCode &status)
Opens a collator from a collator binary image created using cloneBinary.
icu::RuleBasedCollator::getSortKey
virtual 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.
icu::RuleBasedCollator::RuleBasedCollator
RuleBasedCollator(const UnicodeString &rules, UParseError &parseError, UnicodeString &reason, UErrorCode &errorCode)
TODO: document & propose as public API.
icu::RuleBasedCollator::setVariableTop
virtual 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.
icu::RuleBasedCollator::setVariableTop
virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) override
Sets the variable top to the primary weight of the specified string.
icu::RuleBasedCollator::getReorderCodes
virtual int32_t getReorderCodes(int32_t *dest, int32_t destCapacity, UErrorCode &status) const override
Retrieves the reordering codes for this collator.
icu::RuleBasedCollator::getTailoredSet
virtual UnicodeSet * getTailoredSet(UErrorCode &status) const override
Get a UnicodeSet that contains all the characters and sequences tailored in this collator.
icu::RuleBasedCollator::compare
virtual UCollationResult compare(const UnicodeString &source, const UnicodeString &target, UErrorCode &status) const override
The comparison function compares the character data stored in two different strings.
icu::RuleBasedCollator::clone
virtual RuleBasedCollator * clone() const override
Makes a copy of this object.
icu::RuleBasedCollator::getStaticClassID
static UClassID getStaticClassID(void)
Returns the class ID for this class.
icu::RuleBasedCollator::internalBuildTailoring
void internalBuildTailoring(const UnicodeString &rules, int32_t strength, UColAttributeValue decompositionMode, UParseError *outParseError, UnicodeString *outReason, UErrorCode &errorCode)
Implements from-rule constructors, and ucol_openRules().
icu::RuleBasedCollator::internalAddContractions
void internalAddContractions(UChar32 c, UnicodeSet &set, UErrorCode &errorCode) const
Adds the contractions that start with character c to the set.
icu::RuleBasedCollator::getLocale
virtual Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const override
Gets the locale of the Collator.
icu::RuleBasedCollator::compare
virtual 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.
icu::RuleBasedCollator::internalGetContractionsAndExpansions
void internalGetContractionsAndExpansions(UnicodeSet *contractions, UnicodeSet *expansions, UBool addPrefixes, UErrorCode &errorCode) const
Implements ucol_getContractionsAndExpansions().
icu::RuleBasedCollator::operator==
virtual bool operator==(const Collator &other) const override
Returns true if argument is the same as this object.
icu::RuleBasedCollator::getRules
const UnicodeString & getRules() const
Gets the tailoring rules for this collator.
icu::RuleBasedCollator::~RuleBasedCollator
virtual ~RuleBasedCollator()
Destructor.
icu::RuleBasedCollator::setReorderCodes
virtual void setReorderCodes(const int32_t *reorderCodes, int32_t reorderCodesLength, UErrorCode &status) override
Sets the ordering of scripts for this collator.
icu::RuleBasedCollator::internalGetLocaleID
const char * internalGetLocaleID(ULocDataLocaleType type, UErrorCode &errorCode) const
Implements ucol_getLocaleByType().
icu::RuleBasedCollator::cloneBinary
int32_t cloneBinary(uint8_t *buffer, int32_t capacity, UErrorCode &status) const
Creates a binary image of a collator.
icu::RuleBasedCollator::getVersion
virtual void getVersion(UVersionInfo info) const override
Gets the version information for a Collator.
icu::RuleBasedCollator::internalNextSortKeyPart
virtual int32_t internalNextSortKeyPart(UCharIterator *iter, uint32_t state[2], uint8_t *dest, int32_t count, UErrorCode &errorCode) const override
Implements ucol_nextSortKeyPart().
icu::RuleBasedCollator::internalGetCEs
void internalGetCEs(const UnicodeString &str, UVector64 &ces, UErrorCode &errorCode) const
Appends the CEs for the string to the vector.
icu::RuleBasedCollator::getMaxExpansion
int32_t getMaxExpansion(int32_t order) const
Returns the maximum length of any expansion sequences that end with the specified comparison order.
icu::RuleBasedCollator::internalGetShortDefinitionString
virtual int32_t internalGetShortDefinitionString(const char *locale, char *buffer, int32_t capacity, UErrorCode &status) const override
Get the short definition string for a collator.
icu::RuleBasedCollator::createCollationElementIterator
virtual CollationElementIterator * createCollationElementIterator(const UnicodeString &source) const
Creates a collation element iterator for the source string.
icu::RuleBasedCollator::cloneRuleData
uint8_t * cloneRuleData(int32_t &length, UErrorCode &status) const
Do not use this method: The caller and the ICU library might use different heaps.
icu::RuleBasedCollator::RuleBasedCollator
RuleBasedCollator(const UnicodeString &rules, ECollationStrength collationStrength, UErrorCode &status)
RuleBasedCollator constructor.
icu::RuleBasedCollator::compare
virtual 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.
icu::RuleBasedCollator::RuleBasedCollator
RuleBasedCollator(const UnicodeString &rules, UErrorCode &status)
RuleBasedCollator constructor.
icu::RuleBasedCollator::getAttribute
virtual UColAttributeValue getAttribute(UColAttribute attr, UErrorCode &status) const override
Universal attribute getter.
icu::RuleBasedCollator::getDynamicClassID
virtual UClassID getDynamicClassID(void) const override
Returns a unique class ID POLYMORPHICALLY.
icu::RuleBasedCollator::RuleBasedCollator
RuleBasedCollator()
Only for use in ucol_openRules().
icu::RuleBasedCollator::getCollationKey
virtual 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...
icu::RuleBasedCollator::RuleBasedCollator
RuleBasedCollator(const RuleBasedCollator &other)
Copy constructor.
icu::RuleBasedCollator::getCollationKey
virtual 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....
icu::RuleBasedCollator::compareUTF8
virtual UCollationResult compareUTF8(const StringPiece &source, const StringPiece &target, UErrorCode &status) const override
Compares two UTF-8 strings using the Collator.
icu::RuleBasedCollator::getMaxVariable
virtual UColReorderCode getMaxVariable() const override
Returns the maximum reordering group whose characters are affected by UCOL_ALTERNATE_HANDLING.
icu::RuleBasedCollator::setAttribute
virtual void setAttribute(UColAttribute attr, UColAttributeValue value, UErrorCode &status) override
Universal attribute setter.
icu::RuleBasedCollator::compare
virtual UCollationResult compare(UCharIterator &sIter, UCharIterator &tIter, UErrorCode &status) const override
Compares two strings using the Collator.
icu::RuleBasedCollator::setMaxVariable
virtual Collator & setMaxVariable(UColReorderCode group, UErrorCode &errorCode) override
Sets the variable top to the top of the specified reordering group.
icu::RuleBasedCollator::getRules
void getRules(UColRuleOption delta, UnicodeString &buffer) const
Returns current rules.
icu::StringPiece
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:60
icu::UnicodeSet
A mutable set of Unicode characters and multicharacter strings.
Definition: uniset.h:285
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
coll.h
C++ API: Collation Service.
locid.h
C++ API: Locale ID object.
U_CALLCONV
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition: platform.h:866
UCharIterator
C API for code unit iteration.
Definition: uiter.h:341
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
ucol.h
C API: Collator.
UCollator
struct UCollator UCollator
structure representing a collator object instance
Definition: ucol.h:61
UColRuleOption
UColRuleOption
Options for retrieving the rule string.
Definition: ucol.h:372
UColAttribute
UColAttribute
Attributes that collation service understands.
Definition: ucol.h:245
UCOL_ATTRIBUTE_COUNT
@ UCOL_ATTRIBUTE_COUNT
One more than the highest normal UColAttribute value.
Definition: ucol.h:365
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
UColAttributeValue
UColAttributeValue
Enum containing attribute values for controlling collation behavior.
Definition: ucol.h:92
UColReorderCode
UColReorderCode
Enum containing the codes for reordering segments of the collation table that are not script codes.
Definition: ucol.h:149
uiter.h
C API: Unicode Character Iteration.
ULocDataLocaleType
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
Definition: uloc.h:338
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:435
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:301
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