jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ****************************************************************************** jpayne@69: * Copyright (C) 1996-2016, International Business Machines Corporation and jpayne@69: * others. All Rights Reserved. jpayne@69: ****************************************************************************** jpayne@69: */ jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C++ API: The RuleBasedCollator class implements the Collator abstract base class. jpayne@69: */ jpayne@69: jpayne@69: /** jpayne@69: * File tblcoll.h jpayne@69: * jpayne@69: * Created by: Helena Shih jpayne@69: * jpayne@69: * Modification History: jpayne@69: * jpayne@69: * Date Name Description jpayne@69: * 2/5/97 aliu Added streamIn and streamOut methods. Added jpayne@69: * constructor which reads RuleBasedCollator object from jpayne@69: * a binary file. Added writeToFile method which streams jpayne@69: * RuleBasedCollator out to a binary file. The streamIn jpayne@69: * and streamOut methods use istream and ostream objects jpayne@69: * in binary mode. jpayne@69: * 2/12/97 aliu Modified to use TableCollationData sub-object to jpayne@69: * hold invariant data. jpayne@69: * 2/13/97 aliu Moved several methods into this class from Collation. jpayne@69: * Added a private RuleBasedCollator(Locale&) constructor, jpayne@69: * to be used by Collator::createDefault(). General jpayne@69: * clean up. jpayne@69: * 2/20/97 helena Added clone, operator==, operator!=, operator=, and copy jpayne@69: * constructor and getDynamicClassID. jpayne@69: * 3/5/97 aliu Modified constructFromFile() to add parameter jpayne@69: * specifying whether or not binary loading is to be jpayne@69: * attempted. This is required for dynamic rule loading. jpayne@69: * 05/07/97 helena Added memory allocation error detection. jpayne@69: * 6/17/97 helena Added IDENTICAL strength for compare, changed getRules to jpayne@69: * use MergeCollation::getPattern. jpayne@69: * 6/20/97 helena Java class name change. jpayne@69: * 8/18/97 helena Added internal API documentation. jpayne@69: * 09/03/97 helena Added createCollationKeyValues(). jpayne@69: * 02/10/98 damiba Added compare with "length" parameter jpayne@69: * 08/05/98 erm Synched with 1.2 version of RuleBasedCollator.java jpayne@69: * 04/23/99 stephen Removed EDecompositionMode, merged with jpayne@69: * Normalizer::EMode jpayne@69: * 06/14/99 stephen Removed kResourceBundleSuffix jpayne@69: * 11/02/99 helena Collator performance enhancements. Eliminates the jpayne@69: * UnicodeString construction and special case for NO_OP. jpayne@69: * 11/23/99 srl More performance enhancements. Updates to NormalizerIterator jpayne@69: * internal state management. jpayne@69: * 12/15/99 aliu Update to support Thai collation. Move NormalizerIterator jpayne@69: * to implementation file. jpayne@69: * 01/29/01 synwee Modified into a C++ wrapper which calls C API jpayne@69: * (ucol.h) jpayne@69: * 2012-2014 markus Rewritten in C++ again. jpayne@69: */ jpayne@69: jpayne@69: #ifndef TBLCOLL_H jpayne@69: #define TBLCOLL_H jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: #if !UCONFIG_NO_COLLATION jpayne@69: jpayne@69: #include "unicode/coll.h" jpayne@69: #include "unicode/locid.h" jpayne@69: #include "unicode/uiter.h" jpayne@69: #include "unicode/ucol.h" jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: struct CollationCacheEntry; jpayne@69: struct CollationData; jpayne@69: struct CollationSettings; jpayne@69: struct CollationTailoring; jpayne@69: /** jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: class StringSearch; jpayne@69: /** jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: class CollationElementIterator; jpayne@69: class CollationKey; jpayne@69: class SortKeyByteSink; jpayne@69: class UnicodeSet; jpayne@69: class UnicodeString; jpayne@69: class UVector64; jpayne@69: jpayne@69: /** jpayne@69: * The RuleBasedCollator class provides the implementation of jpayne@69: * Collator, using data-driven tables. The user can create a customized jpayne@69: * table-based collation. jpayne@69: *

jpayne@69: * For more information about the collation service see jpayne@69: * the User Guide. jpayne@69: *

jpayne@69: * Collation service provides correct sorting orders for most locales supported in ICU. jpayne@69: * If specific data for a locale is not available, the orders eventually falls back jpayne@69: * to the CLDR root sort order. jpayne@69: *

jpayne@69: * Sort ordering may be customized by providing your own set of rules. For more on jpayne@69: * this subject see the jpayne@69: * Collation Customization section of the User Guide. jpayne@69: *

jpayne@69: * Note, RuleBasedCollator is not to be subclassed. jpayne@69: * @see Collator jpayne@69: */ jpayne@69: class U_I18N_API RuleBasedCollator : public Collator { jpayne@69: public: jpayne@69: /** jpayne@69: * RuleBasedCollator constructor. This takes the table rules and builds a jpayne@69: * collation table out of them. Please see RuleBasedCollator class jpayne@69: * description for more details on the collation rule syntax. jpayne@69: * @param rules the collation rules to build the collation table from. jpayne@69: * @param status reporting a success or an error. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: RuleBasedCollator(const UnicodeString& rules, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * RuleBasedCollator constructor. This takes the table rules and builds a jpayne@69: * collation table out of them. Please see RuleBasedCollator class jpayne@69: * description for more details on the collation rule syntax. jpayne@69: * @param rules the collation rules to build the collation table from. jpayne@69: * @param collationStrength strength for comparison jpayne@69: * @param status reporting a success or an error. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: RuleBasedCollator(const UnicodeString& rules, jpayne@69: ECollationStrength collationStrength, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * RuleBasedCollator constructor. This takes the table rules and builds a jpayne@69: * collation table out of them. Please see RuleBasedCollator class jpayne@69: * description for more details on the collation rule syntax. jpayne@69: * @param rules the collation rules to build the collation table from. jpayne@69: * @param decompositionMode the normalisation mode jpayne@69: * @param status reporting a success or an error. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: RuleBasedCollator(const UnicodeString& rules, jpayne@69: UColAttributeValue decompositionMode, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * RuleBasedCollator constructor. This takes the table rules and builds a jpayne@69: * collation table out of them. Please see RuleBasedCollator class jpayne@69: * description for more details on the collation rule syntax. jpayne@69: * @param rules the collation rules to build the collation table from. jpayne@69: * @param collationStrength strength for comparison jpayne@69: * @param decompositionMode the normalisation mode jpayne@69: * @param status reporting a success or an error. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: RuleBasedCollator(const UnicodeString& rules, jpayne@69: ECollationStrength collationStrength, jpayne@69: UColAttributeValue decompositionMode, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * TODO: document & propose as public API jpayne@69: * @internal jpayne@69: */ jpayne@69: RuleBasedCollator(const UnicodeString &rules, jpayne@69: UParseError &parseError, UnicodeString &reason, jpayne@69: UErrorCode &errorCode); jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: /** jpayne@69: * Copy constructor. jpayne@69: * @param other the RuleBasedCollator object to be copied jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: RuleBasedCollator(const RuleBasedCollator& other); jpayne@69: jpayne@69: jpayne@69: /** Opens a collator from a collator binary image created using jpayne@69: * cloneBinary. Binary image used in instantiation of the jpayne@69: * collator remains owned by the user and should stay around for jpayne@69: * the lifetime of the collator. The API also takes a base collator jpayne@69: * which must be the root collator. jpayne@69: * @param bin binary image owned by the user and required through the jpayne@69: * lifetime of the collator jpayne@69: * @param length size of the image. If negative, the API will try to jpayne@69: * figure out the length of the image jpayne@69: * @param base Base collator, for lookup of untailored characters. jpayne@69: * Must be the root collator, must not be NULL. jpayne@69: * The base is required to be present through the lifetime of the collator. jpayne@69: * @param status for catching errors jpayne@69: * @return newly created collator jpayne@69: * @see cloneBinary jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: RuleBasedCollator(const uint8_t *bin, int32_t length, jpayne@69: const RuleBasedCollator *base, jpayne@69: UErrorCode &status); jpayne@69: jpayne@69: /** jpayne@69: * Destructor. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual ~RuleBasedCollator(); jpayne@69: jpayne@69: /** jpayne@69: * Assignment operator. jpayne@69: * @param other other RuleBasedCollator object to copy from. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: RuleBasedCollator& operator=(const RuleBasedCollator& other); jpayne@69: jpayne@69: /** jpayne@69: * Returns true if argument is the same as this object. jpayne@69: * @param other Collator object to be compared. jpayne@69: * @return true if arguments is the same as this object. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual UBool operator==(const Collator& other) const; jpayne@69: jpayne@69: /** jpayne@69: * Makes a copy of this object. jpayne@69: * @return a copy of this object, owned by the caller jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual RuleBasedCollator* clone() const; jpayne@69: jpayne@69: /** jpayne@69: * Creates a collation element iterator for the source string. The caller of jpayne@69: * this method is responsible for the memory management of the return jpayne@69: * pointer. jpayne@69: * @param source the string over which the CollationElementIterator will jpayne@69: * iterate. jpayne@69: * @return the collation element iterator of the source string using this as jpayne@69: * the based Collator. jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: virtual CollationElementIterator* createCollationElementIterator( jpayne@69: const UnicodeString& source) const; jpayne@69: jpayne@69: /** jpayne@69: * Creates a collation element iterator for the source. The caller of this jpayne@69: * method is responsible for the memory management of the returned pointer. jpayne@69: * @param source the CharacterIterator which produces the characters over jpayne@69: * which the CollationElementItgerator will iterate. jpayne@69: * @return the collation element iterator of the source using this as the jpayne@69: * based Collator. jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: virtual CollationElementIterator* createCollationElementIterator( jpayne@69: const CharacterIterator& source) const; jpayne@69: jpayne@69: // Make deprecated versions of Collator::compare() visible. jpayne@69: using Collator::compare; jpayne@69: jpayne@69: /** jpayne@69: * The comparison function compares the character data stored in two jpayne@69: * different strings. Returns information about whether a string is less jpayne@69: * than, greater than or equal to another string. jpayne@69: * @param source the source string to be compared with. jpayne@69: * @param target the string that is to be compared with the source string. jpayne@69: * @param status possible error code jpayne@69: * @return Returns an enum value. UCOL_GREATER if source is greater jpayne@69: * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source is less jpayne@69: * than target jpayne@69: * @stable ICU 2.6 jpayne@69: **/ jpayne@69: virtual UCollationResult compare(const UnicodeString& source, jpayne@69: const UnicodeString& target, jpayne@69: UErrorCode &status) const; jpayne@69: jpayne@69: /** jpayne@69: * Does the same thing as compare but limits the comparison to a specified jpayne@69: * length jpayne@69: * @param source the source string to be compared with. jpayne@69: * @param target the string that is to be compared with the source string. jpayne@69: * @param length the length the comparison is limited to jpayne@69: * @param status possible error code jpayne@69: * @return Returns an enum value. UCOL_GREATER if source (up to the specified jpayne@69: * length) is greater than target; UCOL_EQUAL if source (up to specified jpayne@69: * length) is equal to target; UCOL_LESS if source (up to the specified jpayne@69: * length) is less than target. jpayne@69: * @stable ICU 2.6 jpayne@69: */ jpayne@69: virtual UCollationResult compare(const UnicodeString& source, jpayne@69: const UnicodeString& target, jpayne@69: int32_t length, jpayne@69: UErrorCode &status) const; jpayne@69: jpayne@69: /** jpayne@69: * The comparison function compares the character data stored in two jpayne@69: * different string arrays. Returns information about whether a string array jpayne@69: * is less than, greater than or equal to another string array. jpayne@69: * @param source the source string array to be compared with. jpayne@69: * @param sourceLength the length of the source string array. If this value jpayne@69: * is equal to -1, the string array is null-terminated. jpayne@69: * @param target the string that is to be compared with the source string. jpayne@69: * @param targetLength the length of the target string array. If this value jpayne@69: * is equal to -1, the string array is null-terminated. jpayne@69: * @param status possible error code jpayne@69: * @return Returns an enum value. UCOL_GREATER if source is greater jpayne@69: * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source is less jpayne@69: * than target jpayne@69: * @stable ICU 2.6 jpayne@69: */ jpayne@69: virtual UCollationResult compare(const char16_t* source, int32_t sourceLength, jpayne@69: const char16_t* target, int32_t targetLength, jpayne@69: UErrorCode &status) const; jpayne@69: jpayne@69: /** jpayne@69: * Compares two strings using the Collator. jpayne@69: * Returns whether the first one compares less than/equal to/greater than jpayne@69: * the second one. jpayne@69: * This version takes UCharIterator input. jpayne@69: * @param sIter the first ("source") string iterator jpayne@69: * @param tIter the second ("target") string iterator jpayne@69: * @param status ICU status jpayne@69: * @return UCOL_LESS, UCOL_EQUAL or UCOL_GREATER jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: virtual UCollationResult compare(UCharIterator &sIter, jpayne@69: UCharIterator &tIter, jpayne@69: UErrorCode &status) const; jpayne@69: jpayne@69: /** jpayne@69: * Compares two UTF-8 strings using the Collator. jpayne@69: * Returns whether the first one compares less than/equal to/greater than jpayne@69: * the second one. jpayne@69: * This version takes UTF-8 input. jpayne@69: * Note that a StringPiece can be implicitly constructed jpayne@69: * from a std::string or a NUL-terminated const char * string. jpayne@69: * @param source the first UTF-8 string jpayne@69: * @param target the second UTF-8 string jpayne@69: * @param status ICU status jpayne@69: * @return UCOL_LESS, UCOL_EQUAL or UCOL_GREATER jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: virtual UCollationResult compareUTF8(const StringPiece &source, jpayne@69: const StringPiece &target, jpayne@69: UErrorCode &status) const; jpayne@69: jpayne@69: /** jpayne@69: * Transforms the string into a series of characters jpayne@69: * that can be compared with CollationKey.compare(). jpayne@69: * jpayne@69: * Note that sort keys are often less efficient than simply doing comparison. jpayne@69: * For more details, see the ICU User Guide. jpayne@69: * jpayne@69: * @param source the source string. jpayne@69: * @param key the transformed key of the source string. jpayne@69: * @param status the error code status. jpayne@69: * @return the transformed key. jpayne@69: * @see CollationKey jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual CollationKey& getCollationKey(const UnicodeString& source, jpayne@69: CollationKey& key, jpayne@69: UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Transforms a specified region of the string into a series of characters jpayne@69: * that can be compared with CollationKey.compare. jpayne@69: * jpayne@69: * Note that sort keys are often less efficient than simply doing comparison. jpayne@69: * For more details, see the ICU User Guide. jpayne@69: * jpayne@69: * @param source the source string. jpayne@69: * @param sourceLength the length of the source string. jpayne@69: * @param key the transformed key of the source string. jpayne@69: * @param status the error code status. jpayne@69: * @return the transformed key. jpayne@69: * @see CollationKey jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual CollationKey& getCollationKey(const char16_t *source, jpayne@69: int32_t sourceLength, jpayne@69: CollationKey& key, jpayne@69: UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Generates the hash code for the rule-based collation object. jpayne@69: * @return the hash code. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int32_t hashCode() const; jpayne@69: jpayne@69: #ifndef U_FORCE_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * Gets the locale of the Collator jpayne@69: * @param type can be either requested, valid or actual locale. For more jpayne@69: * information see the definition of ULocDataLocaleType in jpayne@69: * uloc.h jpayne@69: * @param status the error code status. jpayne@69: * @return locale where the collation data lives. If the collator jpayne@69: * was instantiated from rules, locale is empty. jpayne@69: * @deprecated ICU 2.8 likely to change in ICU 3.0, based on feedback jpayne@69: */ jpayne@69: virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; jpayne@69: #endif // U_FORCE_HIDE_DEPRECATED_API jpayne@69: jpayne@69: /** jpayne@69: * Gets the tailoring rules for this collator. jpayne@69: * @return the collation tailoring from which this collator was created jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: const UnicodeString& getRules() const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the version information for a Collator. jpayne@69: * @param info the version # information, the result will be filled in jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void getVersion(UVersionInfo info) const; jpayne@69: jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * Returns the maximum length of any expansion sequences that end with the jpayne@69: * specified comparison order. jpayne@69: * jpayne@69: * This is specific to the kind of collation element values and sequences jpayne@69: * returned by the CollationElementIterator. jpayne@69: * Call CollationElementIterator::getMaxExpansion() instead. jpayne@69: * jpayne@69: * @param order a collation order returned by CollationElementIterator::previous jpayne@69: * or CollationElementIterator::next. jpayne@69: * @return maximum size of the expansion sequences ending with the collation jpayne@69: * element, or 1 if the collation element does not occur at the end of jpayne@69: * any expansion sequence jpayne@69: * @see CollationElementIterator#getMaxExpansion jpayne@69: * @deprecated ICU 51 Use CollationElementIterator::getMaxExpansion() instead. jpayne@69: */ jpayne@69: int32_t getMaxExpansion(int32_t order) const; jpayne@69: #endif /* U_HIDE_DEPRECATED_API */ jpayne@69: jpayne@69: /** jpayne@69: * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This jpayne@69: * method is to implement a simple version of RTTI, since not all C++ jpayne@69: * compilers support genuine RTTI. Polymorphic operator==() and clone() jpayne@69: * methods call this method. jpayne@69: * @return The class ID for this object. All objects of a given class have jpayne@69: * the same class ID. Objects of other classes have different class jpayne@69: * IDs. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual UClassID getDynamicClassID(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the class ID for this class. This is useful only for comparing to jpayne@69: * a return value from getDynamicClassID(). For example: jpayne@69: *

jpayne@69:      * Base* polymorphic_pointer = createPolymorphicObject();
jpayne@69:      * if (polymorphic_pointer->getDynamicClassID() ==
jpayne@69:      *                                          Derived::getStaticClassID()) ...
jpayne@69:      * 
jpayne@69: * @return The class ID for all objects of this class. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(void); jpayne@69: jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * Do not use this method: The caller and the ICU library might use different heaps. jpayne@69: * Use cloneBinary() instead which writes to caller-provided memory. jpayne@69: * jpayne@69: * Returns a binary format of this collator. jpayne@69: * @param length Returns the length of the data, in bytes jpayne@69: * @param status the error code status. jpayne@69: * @return memory, owned by the caller, of size 'length' bytes. jpayne@69: * @deprecated ICU 52. Use cloneBinary() instead. jpayne@69: */ jpayne@69: uint8_t *cloneRuleData(int32_t &length, UErrorCode &status) const; jpayne@69: #endif /* U_HIDE_DEPRECATED_API */ jpayne@69: jpayne@69: /** Creates a binary image of a collator. This binary image can be stored and jpayne@69: * later used to instantiate a collator using ucol_openBinary. jpayne@69: * This API supports preflighting. jpayne@69: * @param buffer a fill-in buffer to receive the binary image jpayne@69: * @param capacity capacity of the destination buffer jpayne@69: * @param status for catching errors jpayne@69: * @return size of the image jpayne@69: * @see ucol_openBinary jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: int32_t cloneBinary(uint8_t *buffer, int32_t capacity, UErrorCode &status) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns current rules. Delta defines whether full rules are returned or jpayne@69: * just the tailoring. jpayne@69: * jpayne@69: * getRules(void) should normally be used instead. jpayne@69: * See http://userguide.icu-project.org/collation/customization#TOC-Building-on-Existing-Locales jpayne@69: * @param delta one of UCOL_TAILORING_ONLY, UCOL_FULL_RULES. jpayne@69: * @param buffer UnicodeString to store the result rules jpayne@69: * @stable ICU 2.2 jpayne@69: * @see UCOL_FULL_RULES jpayne@69: */ jpayne@69: void getRules(UColRuleOption delta, UnicodeString &buffer) const; jpayne@69: jpayne@69: /** jpayne@69: * Universal attribute setter jpayne@69: * @param attr attribute type jpayne@69: * @param value attribute value jpayne@69: * @param status to indicate whether the operation went on smoothly or there were errors jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: virtual void setAttribute(UColAttribute attr, UColAttributeValue value, jpayne@69: UErrorCode &status); jpayne@69: jpayne@69: /** jpayne@69: * Universal attribute getter. jpayne@69: * @param attr attribute type jpayne@69: * @param status to indicate whether the operation went on smoothly or there were errors jpayne@69: * @return attribute value jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: virtual UColAttributeValue getAttribute(UColAttribute attr, jpayne@69: UErrorCode &status) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets the variable top to the top of the specified reordering group. jpayne@69: * The variable top determines the highest-sorting character jpayne@69: * which is affected by UCOL_ALTERNATE_HANDLING. jpayne@69: * If that attribute is set to UCOL_NON_IGNORABLE, then the variable top has no effect. jpayne@69: * @param group one of UCOL_REORDER_CODE_SPACE, UCOL_REORDER_CODE_PUNCTUATION, jpayne@69: * UCOL_REORDER_CODE_SYMBOL, UCOL_REORDER_CODE_CURRENCY; jpayne@69: * or UCOL_REORDER_CODE_DEFAULT to restore the default max variable group jpayne@69: * @param errorCode Standard ICU error code. Its input value must jpayne@69: * pass the U_SUCCESS() test, or else the function returns jpayne@69: * immediately. Check for U_FAILURE() on output or use with jpayne@69: * function chaining. (See User Guide for details.) jpayne@69: * @return *this jpayne@69: * @see getMaxVariable jpayne@69: * @stable ICU 53 jpayne@69: */ jpayne@69: virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCode); jpayne@69: jpayne@69: /** jpayne@69: * Returns the maximum reordering group whose characters are affected by UCOL_ALTERNATE_HANDLING. jpayne@69: * @return the maximum variable reordering group. jpayne@69: * @see setMaxVariable jpayne@69: * @stable ICU 53 jpayne@69: */ jpayne@69: virtual UColReorderCode getMaxVariable() const; jpayne@69: jpayne@69: #ifndef U_FORCE_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * Sets the variable top to the primary weight of the specified string. jpayne@69: * jpayne@69: * Beginning with ICU 53, the variable top is pinned to jpayne@69: * the top of one of the supported reordering groups, jpayne@69: * and it must not be beyond the last of those groups. jpayne@69: * See setMaxVariable(). jpayne@69: * @param varTop one or more (if contraction) char16_ts to which the variable top should be set jpayne@69: * @param len length of variable top string. If -1 it is considered to be zero terminated. jpayne@69: * @param status error code. If error code is set, the return value is undefined. Errors set by this function are:
jpayne@69: * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction
jpayne@69: * U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond jpayne@69: * the last reordering group supported by setMaxVariable() jpayne@69: * @return variable top primary weight jpayne@69: * @deprecated ICU 53 Call setMaxVariable() instead. jpayne@69: */ jpayne@69: virtual uint32_t setVariableTop(const char16_t *varTop, int32_t len, UErrorCode &status); jpayne@69: jpayne@69: /** jpayne@69: * Sets the variable top to the primary weight of the specified string. jpayne@69: * jpayne@69: * Beginning with ICU 53, the variable top is pinned to jpayne@69: * the top of one of the supported reordering groups, jpayne@69: * and it must not be beyond the last of those groups. jpayne@69: * See setMaxVariable(). jpayne@69: * @param varTop a UnicodeString size 1 or more (if contraction) of char16_ts to which the variable top should be set jpayne@69: * @param status error code. If error code is set, the return value is undefined. Errors set by this function are:
jpayne@69: * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction
jpayne@69: * U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond jpayne@69: * the last reordering group supported by setMaxVariable() jpayne@69: * @return variable top primary weight jpayne@69: * @deprecated ICU 53 Call setMaxVariable() instead. jpayne@69: */ jpayne@69: virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status); jpayne@69: jpayne@69: /** jpayne@69: * Sets the variable top to the specified primary weight. jpayne@69: * jpayne@69: * Beginning with ICU 53, the variable top is pinned to jpayne@69: * the top of one of the supported reordering groups, jpayne@69: * and it must not be beyond the last of those groups. jpayne@69: * See setMaxVariable(). jpayne@69: * @param varTop primary weight, as returned by setVariableTop or ucol_getVariableTop jpayne@69: * @param status error code jpayne@69: * @deprecated ICU 53 Call setMaxVariable() instead. jpayne@69: */ jpayne@69: virtual void setVariableTop(uint32_t varTop, UErrorCode &status); jpayne@69: #endif // U_FORCE_HIDE_DEPRECATED_API jpayne@69: jpayne@69: /** jpayne@69: * Gets the variable top value of a Collator. jpayne@69: * @param status error code (not changed by function). If error code is set, the return value is undefined. jpayne@69: * @return the variable top primary weight jpayne@69: * @see getMaxVariable jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual uint32_t getVariableTop(UErrorCode &status) const; jpayne@69: jpayne@69: /** jpayne@69: * Get a UnicodeSet that contains all the characters and sequences tailored in jpayne@69: * this collator. jpayne@69: * @param status error code of the operation jpayne@69: * @return a pointer to a UnicodeSet object containing all the jpayne@69: * code points and sequences that may sort differently than jpayne@69: * in the root collator. The object must be disposed of by using delete jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: virtual UnicodeSet *getTailoredSet(UErrorCode &status) const; jpayne@69: jpayne@69: /** jpayne@69: * Get the sort key as an array of bytes from a UnicodeString. jpayne@69: * jpayne@69: * Note that sort keys are often less efficient than simply doing comparison. jpayne@69: * For more details, see the ICU User Guide. jpayne@69: * jpayne@69: * @param source string to be processed. jpayne@69: * @param result buffer to store result in. If NULL, number of bytes needed jpayne@69: * will be returned. jpayne@69: * @param resultLength length of the result buffer. If if not enough the jpayne@69: * buffer will be filled to capacity. jpayne@69: * @return Number of bytes needed for storing the sort key jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result, jpayne@69: int32_t resultLength) const; jpayne@69: jpayne@69: /** jpayne@69: * Get the sort key as an array of bytes from a char16_t buffer. jpayne@69: * jpayne@69: * Note that sort keys are often less efficient than simply doing comparison. jpayne@69: * For more details, see the ICU User Guide. jpayne@69: * jpayne@69: * @param source string to be processed. jpayne@69: * @param sourceLength length of string to be processed. If -1, the string jpayne@69: * is 0 terminated and length will be decided by the function. jpayne@69: * @param result buffer to store result in. If NULL, number of bytes needed jpayne@69: * will be returned. jpayne@69: * @param resultLength length of the result buffer. If if not enough the jpayne@69: * buffer will be filled to capacity. jpayne@69: * @return Number of bytes needed for storing the sort key jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: virtual int32_t getSortKey(const char16_t *source, int32_t sourceLength, jpayne@69: uint8_t *result, int32_t resultLength) const; jpayne@69: jpayne@69: /** jpayne@69: * Retrieves the reordering codes for this collator. jpayne@69: * @param dest The array to fill with the script ordering. jpayne@69: * @param destCapacity The length of dest. If it is 0, then dest may be NULL and the function jpayne@69: * will only return the length of the result without writing any codes (pre-flighting). jpayne@69: * @param status A reference to an error code value, which must not indicate jpayne@69: * a failure before the function call. jpayne@69: * @return The length of the script ordering array. jpayne@69: * @see ucol_setReorderCodes jpayne@69: * @see Collator#getEquivalentReorderCodes jpayne@69: * @see Collator#setReorderCodes jpayne@69: * @stable ICU 4.8 jpayne@69: */ jpayne@69: virtual int32_t getReorderCodes(int32_t *dest, jpayne@69: int32_t destCapacity, jpayne@69: UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets the ordering of scripts for this collator. jpayne@69: * @param reorderCodes An array of script codes in the new order. This can be NULL if the jpayne@69: * length is also set to 0. An empty array will clear any reordering codes on the collator. jpayne@69: * @param reorderCodesLength The length of reorderCodes. jpayne@69: * @param status error code jpayne@69: * @see ucol_setReorderCodes jpayne@69: * @see Collator#getReorderCodes jpayne@69: * @see Collator#getEquivalentReorderCodes jpayne@69: * @stable ICU 4.8 jpayne@69: */ jpayne@69: virtual void setReorderCodes(const int32_t* reorderCodes, jpayne@69: int32_t reorderCodesLength, jpayne@69: UErrorCode& status) ; jpayne@69: jpayne@69: /** jpayne@69: * Implements ucol_strcollUTF8(). jpayne@69: * @internal jpayne@69: */ jpayne@69: virtual UCollationResult internalCompareUTF8( jpayne@69: const char *left, int32_t leftLength, jpayne@69: const char *right, int32_t rightLength, jpayne@69: UErrorCode &errorCode) const; jpayne@69: jpayne@69: /** Get the short definition string for a collator. This internal API harvests the collator's jpayne@69: * locale and the attribute set and produces a string that can be used for opening jpayne@69: * a collator with the same attributes using the ucol_openFromShortString API. jpayne@69: * This string will be normalized. jpayne@69: * The structure and the syntax of the string is defined in the "Naming collators" jpayne@69: * section of the users guide: jpayne@69: * http://userguide.icu-project.org/collation/concepts#TOC-Collator-naming-scheme jpayne@69: * This function supports preflighting. jpayne@69: * jpayne@69: * This is internal, and intended to be used with delegate converters. jpayne@69: * jpayne@69: * @param locale a locale that will appear as a collators locale in the resulting jpayne@69: * short string definition. If NULL, the locale will be harvested jpayne@69: * from the collator. jpayne@69: * @param buffer space to hold the resulting string jpayne@69: * @param capacity capacity of the buffer jpayne@69: * @param status for returning errors. All the preflighting errors are featured jpayne@69: * @return length of the resulting string jpayne@69: * @see ucol_openFromShortString jpayne@69: * @see ucol_normalizeShortDefinitionString jpayne@69: * @see ucol_getShortDefinitionString jpayne@69: * @internal jpayne@69: */ jpayne@69: virtual int32_t internalGetShortDefinitionString(const char *locale, jpayne@69: char *buffer, jpayne@69: int32_t capacity, jpayne@69: UErrorCode &status) const; jpayne@69: jpayne@69: /** jpayne@69: * Implements ucol_nextSortKeyPart(). jpayne@69: * @internal jpayne@69: */ jpayne@69: virtual int32_t internalNextSortKeyPart( jpayne@69: UCharIterator *iter, uint32_t state[2], jpayne@69: uint8_t *dest, int32_t count, UErrorCode &errorCode) const; jpayne@69: jpayne@69: // Do not enclose the default constructor with #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Only for use in ucol_openRules(). jpayne@69: * @internal jpayne@69: */ jpayne@69: RuleBasedCollator(); jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Implements ucol_getLocaleByType(). jpayne@69: * Needed because the lifetime of the locale ID string must match that of the collator. jpayne@69: * getLocale() returns a copy of a Locale, with minimal lifetime in a C wrapper. jpayne@69: * @internal jpayne@69: */ jpayne@69: const char *internalGetLocaleID(ULocDataLocaleType type, UErrorCode &errorCode) const; jpayne@69: jpayne@69: /** jpayne@69: * Implements ucol_getContractionsAndExpansions(). jpayne@69: * Gets this collator's sets of contraction strings and/or jpayne@69: * characters and strings that map to multiple collation elements (expansions). jpayne@69: * If addPrefixes is TRUE, then contractions that are expressed as jpayne@69: * prefix/pre-context rules are included. jpayne@69: * @param contractions if not NULL, the set to hold the contractions jpayne@69: * @param expansions if not NULL, the set to hold the expansions jpayne@69: * @param addPrefixes include prefix contextual mappings jpayne@69: * @param errorCode in/out ICU error code jpayne@69: * @internal jpayne@69: */ jpayne@69: void internalGetContractionsAndExpansions( jpayne@69: UnicodeSet *contractions, UnicodeSet *expansions, jpayne@69: UBool addPrefixes, UErrorCode &errorCode) const; jpayne@69: jpayne@69: /** jpayne@69: * Adds the contractions that start with character c to the set. jpayne@69: * Ignores prefixes. Used by AlphabeticIndex. jpayne@69: * @internal jpayne@69: */ jpayne@69: void internalAddContractions(UChar32 c, UnicodeSet &set, UErrorCode &errorCode) const; jpayne@69: jpayne@69: /** jpayne@69: * Implements from-rule constructors, and ucol_openRules(). jpayne@69: * @internal jpayne@69: */ jpayne@69: void internalBuildTailoring( jpayne@69: const UnicodeString &rules, jpayne@69: int32_t strength, jpayne@69: UColAttributeValue decompositionMode, jpayne@69: UParseError *outParseError, UnicodeString *outReason, jpayne@69: UErrorCode &errorCode); jpayne@69: jpayne@69: /** @internal */ jpayne@69: static inline RuleBasedCollator *rbcFromUCollator(UCollator *uc) { jpayne@69: return dynamic_cast(fromUCollator(uc)); jpayne@69: } jpayne@69: /** @internal */ jpayne@69: static inline const RuleBasedCollator *rbcFromUCollator(const UCollator *uc) { jpayne@69: return dynamic_cast(fromUCollator(uc)); jpayne@69: } jpayne@69: jpayne@69: /** jpayne@69: * Appends the CEs for the string to the vector. jpayne@69: * @internal for tests & tools jpayne@69: */ jpayne@69: void internalGetCEs(const UnicodeString &str, UVector64 &ces, UErrorCode &errorCode) const; jpayne@69: #endif // U_HIDE_INTERNAL_API jpayne@69: jpayne@69: protected: jpayne@69: /** jpayne@69: * Used internally by registration to define the requested and valid locales. jpayne@69: * @param requestedLocale the requested locale jpayne@69: * @param validLocale the valid locale jpayne@69: * @param actualLocale the actual locale jpayne@69: * @internal jpayne@69: */ jpayne@69: virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale); jpayne@69: jpayne@69: private: jpayne@69: friend class CollationElementIterator; jpayne@69: friend class Collator; jpayne@69: jpayne@69: RuleBasedCollator(const CollationCacheEntry *entry); jpayne@69: jpayne@69: /** jpayne@69: * Enumeration of attributes that are relevant for short definition strings jpayne@69: * (e.g., ucol_getShortDefinitionString()). jpayne@69: * Effectively extends UColAttribute. jpayne@69: */ jpayne@69: enum Attributes { jpayne@69: ATTR_VARIABLE_TOP = UCOL_ATTRIBUTE_COUNT, jpayne@69: ATTR_LIMIT jpayne@69: }; jpayne@69: jpayne@69: void adoptTailoring(CollationTailoring *t, UErrorCode &errorCode); jpayne@69: jpayne@69: // Both lengths must be <0 or else both must be >=0. jpayne@69: UCollationResult doCompare(const char16_t *left, int32_t leftLength, jpayne@69: const char16_t *right, int32_t rightLength, jpayne@69: UErrorCode &errorCode) const; jpayne@69: UCollationResult doCompare(const uint8_t *left, int32_t leftLength, jpayne@69: const uint8_t *right, int32_t rightLength, jpayne@69: UErrorCode &errorCode) const; jpayne@69: jpayne@69: void writeSortKey(const char16_t *s, int32_t length, jpayne@69: SortKeyByteSink &sink, UErrorCode &errorCode) const; jpayne@69: jpayne@69: void writeIdenticalLevel(const char16_t *s, const char16_t *limit, jpayne@69: SortKeyByteSink &sink, UErrorCode &errorCode) const; jpayne@69: jpayne@69: const CollationSettings &getDefaultSettings() const; jpayne@69: jpayne@69: void setAttributeDefault(int32_t attribute) { jpayne@69: explicitlySetAttributes &= ~((uint32_t)1 << attribute); jpayne@69: } jpayne@69: void setAttributeExplicitly(int32_t attribute) { jpayne@69: explicitlySetAttributes |= (uint32_t)1 << attribute; jpayne@69: } jpayne@69: UBool attributeHasBeenSetExplicitly(int32_t attribute) const { jpayne@69: // assert(0 <= attribute < ATTR_LIMIT); jpayne@69: return (UBool)((explicitlySetAttributes & ((uint32_t)1 << attribute)) != 0); jpayne@69: } jpayne@69: jpayne@69: /** jpayne@69: * Tests whether a character is "unsafe" for use as a collation starting point. jpayne@69: * jpayne@69: * @param c code point or code unit jpayne@69: * @return TRUE if c is unsafe jpayne@69: * @see CollationElementIterator#setOffset(int) jpayne@69: */ jpayne@69: UBool isUnsafe(UChar32 c) const; jpayne@69: jpayne@69: static void U_CALLCONV computeMaxExpansions(const CollationTailoring *t, UErrorCode &errorCode); jpayne@69: UBool initMaxExpansions(UErrorCode &errorCode) const; jpayne@69: jpayne@69: void setFastLatinOptions(CollationSettings &ownedSettings) const; jpayne@69: jpayne@69: const CollationData *data; jpayne@69: const CollationSettings *settings; // reference-counted jpayne@69: const CollationTailoring *tailoring; // alias of cacheEntry->tailoring jpayne@69: const CollationCacheEntry *cacheEntry; // reference-counted jpayne@69: Locale validLocale; jpayne@69: uint32_t explicitlySetAttributes; jpayne@69: jpayne@69: UBool actualLocaleIsSameAsValid; jpayne@69: }; jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif // !UCONFIG_NO_COLLATION jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif // TBLCOLL_H