Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:03

0001 // © 2016 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 /*
0004 ******************************************************************************
0005 *   Copyright (C) 1996-2016, International Business Machines
0006 *   Corporation and others.  All Rights Reserved.
0007 ******************************************************************************
0008 */
0009 
0010 /**
0011  * \file
0012  * \brief C++ API: Collation Service.
0013  */
0014 
0015 /**
0016 * File coll.h
0017 *
0018 * Created by: Helena Shih
0019 *
0020 * Modification History:
0021 *
0022 *  Date        Name        Description
0023 * 02/5/97      aliu        Modified createDefault to load collation data from
0024 *                          binary files when possible.  Added related methods
0025 *                          createCollationFromFile, chopLocale, createPathName.
0026 * 02/11/97     aliu        Added members addToCache, findInCache, and fgCache.
0027 * 02/12/97     aliu        Modified to create objects from RuleBasedCollator cache.
0028 *                          Moved cache out of Collation class.
0029 * 02/13/97     aliu        Moved several methods out of this class and into
0030 *                          RuleBasedCollator, with modifications.  Modified
0031 *                          createDefault() to call new RuleBasedCollator(Locale&)
0032 *                          constructor.  General clean up and documentation.
0033 * 02/20/97     helena      Added clone, operator==, operator!=, operator=, copy
0034 *                          constructor and getDynamicClassID.
0035 * 03/25/97     helena      Updated with platform independent data types.
0036 * 05/06/97     helena      Added memory allocation error detection.
0037 * 06/20/97     helena      Java class name change.
0038 * 09/03/97     helena      Added createCollationKeyValues().
0039 * 02/10/98     damiba      Added compare() with length as parameter.
0040 * 04/23/99     stephen     Removed EDecompositionMode, merged with
0041 *                          Normalizer::EMode.
0042 * 11/02/99     helena      Collator performance enhancements.  Eliminates the
0043 *                          UnicodeString construction and special case for NO_OP.
0044 * 11/23/99     srl         More performance enhancements. Inlining of
0045 *                          critical accessors.
0046 * 05/15/00     helena      Added version information API.
0047 * 01/29/01     synwee      Modified into a C++ wrapper which calls C apis
0048 *                          (ucol.h).
0049 * 2012-2014    markus      Rewritten in C++ again.
0050 */
0051 
0052 #ifndef COLL_H
0053 #define COLL_H
0054 
0055 #include "unicode/utypes.h"
0056 
0057 #if U_SHOW_CPLUSPLUS_API
0058 
0059 #if !UCONFIG_NO_COLLATION
0060 
0061 #include "unicode/uobject.h"
0062 #include "unicode/ucol.h"
0063 #include "unicode/unorm.h"
0064 #include "unicode/locid.h"
0065 #include "unicode/uniset.h"
0066 #include "unicode/umisc.h"
0067 #include "unicode/uiter.h"
0068 #include "unicode/stringpiece.h"
0069 
0070 U_NAMESPACE_BEGIN
0071 
0072 class StringEnumeration;
0073 
0074 #if !UCONFIG_NO_SERVICE
0075 /**
0076  * @stable ICU 2.6
0077  */
0078 class CollatorFactory;
0079 #endif
0080 
0081 /**
0082 * @stable ICU 2.0
0083 */
0084 class CollationKey;
0085 
0086 /**
0087 * The <code>Collator</code> class performs locale-sensitive string
0088 * comparison.<br>
0089 * You use this class to build searching and sorting routines for natural
0090 * language text.
0091 * <p>
0092 * <code>Collator</code> is an abstract base class. Subclasses implement
0093 * specific collation strategies. One subclass,
0094 * <code>RuleBasedCollator</code>, is currently provided and is applicable
0095 * to a wide set of languages. Other subclasses may be created to handle more
0096 * specialized needs.
0097 * <p>
0098 * Like other locale-sensitive classes, you can use the static factory method,
0099 * <code>createInstance</code>, to obtain the appropriate
0100 * <code>Collator</code> object for a given locale. You will only need to
0101 * look at the subclasses of <code>Collator</code> if you need to
0102 * understand the details of a particular collation strategy or if you need to
0103 * modify that strategy.
0104 * <p>
0105 * The following example shows how to compare two strings using the
0106 * <code>Collator</code> for the default locale.
0107 * \htmlonly<blockquote>\endhtmlonly
0108 * <pre>
0109 * \code
0110 * // Compare two strings in the default locale
0111 * UErrorCode success = U_ZERO_ERROR;
0112 * Collator* myCollator = Collator::createInstance(success);
0113 * if (myCollator->compare("abc", "ABC") < 0)
0114 *   cout << "abc is less than ABC" << endl;
0115 * else
0116 *   cout << "abc is greater than or equal to ABC" << endl;
0117 * \endcode
0118 * </pre>
0119 * \htmlonly</blockquote>\endhtmlonly
0120 * <p>
0121 * You can set a <code>Collator</code>'s <em>strength</em> attribute to
0122 * determine the level of difference considered significant in comparisons.
0123 * Five strengths are provided: <code>PRIMARY</code>, <code>SECONDARY</code>,
0124 * <code>TERTIARY</code>, <code>QUATERNARY</code> and <code>IDENTICAL</code>.
0125 * The exact assignment of strengths to language features is locale dependent.
0126 * For example, in Czech, "e" and "f" are considered primary differences,
0127 * while "e" and "\u00EA" are secondary differences, "e" and "E" are tertiary
0128 * differences and "e" and "e" are identical. The following shows how both case
0129 * and accents could be ignored for US English.
0130 * \htmlonly<blockquote>\endhtmlonly
0131 * <pre>
0132 * \code
0133 * //Get the Collator for US English and set its strength to PRIMARY
0134 * UErrorCode success = U_ZERO_ERROR;
0135 * Collator* usCollator = Collator::createInstance(Locale::getUS(), success);
0136 * usCollator->setStrength(Collator::PRIMARY);
0137 * if (usCollator->compare("abc", "ABC") == 0)
0138 *     cout << "'abc' and 'ABC' strings are equivalent with strength PRIMARY" << endl;
0139 * \endcode
0140 * </pre>
0141 * \htmlonly</blockquote>\endhtmlonly
0142 *
0143 * The <code>getSortKey</code> methods
0144 * convert a string to a series of bytes that can be compared bitwise against
0145 * other sort keys using <code>strcmp()</code>. Sort keys are written as
0146 * zero-terminated byte strings.
0147 *
0148 * Another set of APIs returns a <code>CollationKey</code> object that wraps
0149 * the sort key bytes instead of returning the bytes themselves.
0150 * </p>
0151 * <p>
0152 * <strong>Note:</strong> <code>Collator</code>s with different Locale,
0153 * and CollationStrength settings will return different sort
0154 * orders for the same set of strings. Locales have specific collation rules,
0155 * and the way in which secondary and tertiary differences are taken into
0156 * account, for example, will result in a different sorting order for same
0157 * strings.
0158 * </p>
0159 * @see         RuleBasedCollator
0160 * @see         CollationKey
0161 * @see         CollationElementIterator
0162 * @see         Locale
0163 * @see         Normalizer2
0164 * @version     2.0 11/15/01
0165 */
0166 
0167 class U_I18N_API Collator : public UObject {
0168 public:
0169 
0170     // Collator public enums -----------------------------------------------
0171 
0172     /**
0173      * Base letter represents a primary difference. Set comparison level to
0174      * PRIMARY to ignore secondary and tertiary differences.<br>
0175      * Use this to set the strength of a Collator object.<br>
0176      * Example of primary difference, "abc" &lt; "abd"
0177      *
0178      * Diacritical differences on the same base letter represent a secondary
0179      * difference. Set comparison level to SECONDARY to ignore tertiary
0180      * differences. Use this to set the strength of a Collator object.<br>
0181      * Example of secondary difference, "&auml;" >> "a".
0182      *
0183      * Uppercase and lowercase versions of the same character represents a
0184      * tertiary difference.  Set comparison level to TERTIARY to include all
0185      * comparison differences. Use this to set the strength of a Collator
0186      * object.<br>
0187      * Example of tertiary difference, "abc" &lt;&lt;&lt; "ABC".
0188      *
0189      * Two characters are considered "identical" when they have the same unicode
0190      * spellings.<br>
0191      * For example, "&auml;" == "&auml;".
0192      *
0193      * UCollationStrength is also used to determine the strength of sort keys
0194      * generated from Collator objects.
0195      * @stable ICU 2.0
0196      */
0197     enum ECollationStrength
0198     {
0199         PRIMARY    = UCOL_PRIMARY,  // 0
0200         SECONDARY  = UCOL_SECONDARY,  // 1
0201         TERTIARY   = UCOL_TERTIARY,  // 2
0202         QUATERNARY = UCOL_QUATERNARY,  // 3
0203         IDENTICAL  = UCOL_IDENTICAL  // 15
0204     };
0205 
0206 
0207     // Cannot use #ifndef U_HIDE_DEPRECATED_API for the following, it is
0208     // used by virtual methods that cannot have that conditional.
0209 #ifndef U_FORCE_HIDE_DEPRECATED_API
0210     /**
0211      * LESS is returned if source string is compared to be less than target
0212      * string in the compare() method.
0213      * EQUAL is returned if source string is compared to be equal to target
0214      * string in the compare() method.
0215      * GREATER is returned if source string is compared to be greater than
0216      * target string in the compare() method.
0217      * @see Collator#compare
0218      * @deprecated ICU 2.6. Use C enum UCollationResult defined in ucol.h
0219      */
0220     enum EComparisonResult
0221     {
0222         LESS = UCOL_LESS,  // -1
0223         EQUAL = UCOL_EQUAL,  // 0
0224         GREATER = UCOL_GREATER  // 1
0225     };
0226 #endif  // U_FORCE_HIDE_DEPRECATED_API
0227 
0228     // Collator public destructor -----------------------------------------
0229 
0230     /**
0231      * Destructor
0232      * @stable ICU 2.0
0233      */
0234     virtual ~Collator();
0235 
0236     // Collator public methods --------------------------------------------
0237 
0238     /**
0239      * Returns true if "other" is the same as "this".
0240      *
0241      * The base class implementation returns true if "other" has the same type/class as "this":
0242      * `typeid(*this) == typeid(other)`.
0243      *
0244      * Subclass implementations should do something like the following:
0245      *
0246      *     if (this == &other) { return true; }
0247      *     if (!Collator::operator==(other)) { return false; }  // not the same class
0248      *
0249      *     const MyCollator &o = (const MyCollator&)other;
0250      *     (compare this vs. o's subclass fields)
0251      *
0252      * @param other Collator object to be compared
0253      * @return true if other is the same as this.
0254      * @stable ICU 2.0
0255      */
0256     virtual bool operator==(const Collator& other) const;
0257 
0258     /**
0259      * Returns true if "other" is not the same as "this".
0260      * Calls ! operator==(const Collator&) const which works for all subclasses.
0261      * @param other Collator object to be compared
0262      * @return true if other is not the same as this.
0263      * @stable ICU 2.0
0264      */
0265     virtual bool operator!=(const Collator& other) const;
0266 
0267     /**
0268      * Makes a copy of this object.
0269      * @return a copy of this object, owned by the caller
0270      * @stable ICU 2.0
0271      */
0272     virtual Collator* clone() const = 0;
0273 
0274     /**
0275      * Creates the Collator object for the current default locale.
0276      * The default locale is determined by Locale::getDefault.
0277      * The UErrorCode& err parameter is used to return status information to the user.
0278      * To check whether the construction succeeded or not, you should check the
0279      * value of U_SUCCESS(err).  If you wish more detailed information, you can
0280      * check for informational error results which still indicate success.
0281      * U_USING_FALLBACK_ERROR indicates that a fall back locale was used. For
0282      * example, 'de_CH' was requested, but nothing was found there, so 'de' was
0283      * used. U_USING_DEFAULT_ERROR indicates that the default locale data was
0284      * used; neither the requested locale nor any of its fall back locales
0285      * could be found.
0286      * The caller owns the returned object and is responsible for deleting it.
0287      *
0288      * @param err    the error code status.
0289      * @return       the collation object of the default locale.(for example, en_US)
0290      * @see Locale#getDefault
0291      * @stable ICU 2.0
0292      */
0293     static Collator* U_EXPORT2 createInstance(UErrorCode&  err);
0294 
0295     /**
0296      * Gets the collation object for the desired locale. The
0297      * resource of the desired locale will be loaded.
0298      *
0299      * Locale::getRoot() is the base collation table and all other languages are
0300      * built on top of it with additional language-specific modifications.
0301      *
0302      * For some languages, multiple collation types are available;
0303      * for example, "de@collation=phonebook".
0304      * Starting with ICU 54, collation attributes can be specified via locale keywords as well,
0305      * in the old locale extension syntax ("el@colCaseFirst=upper")
0306      * or in language tag syntax ("el-u-kf-upper").
0307      * See <a href="https://unicode-org.github.io/icu/userguide/collation/api">User Guide: Collation API</a>.
0308      *
0309      * The UErrorCode& err parameter is used to return status information to the user.
0310      * To check whether the construction succeeded or not, you should check
0311      * the value of U_SUCCESS(err).  If you wish more detailed information, you
0312      * can check for informational error results which still indicate success.
0313      * U_USING_FALLBACK_ERROR indicates that a fall back locale was used.  For
0314      * example, 'de_CH' was requested, but nothing was found there, so 'de' was
0315      * used.  U_USING_DEFAULT_ERROR indicates that the default locale data was
0316      * used; neither the requested locale nor any of its fall back locales
0317      * could be found.
0318      *
0319      * The caller owns the returned object and is responsible for deleting it.
0320      * @param loc    The locale ID for which to open a collator.
0321      * @param err    the error code status.
0322      * @return       the created table-based collation object based on the desired
0323      *               locale.
0324      * @see Locale
0325      * @see ResourceLoader
0326      * @stable ICU 2.2
0327      */
0328     static Collator* U_EXPORT2 createInstance(const Locale& loc, UErrorCode& err);
0329 
0330 #ifndef U_FORCE_HIDE_DEPRECATED_API
0331     /**
0332      * The comparison function compares the character data stored in two
0333      * different strings. Returns information about whether a string is less
0334      * than, greater than or equal to another string.
0335      * @param source the source string to be compared with.
0336      * @param target the string that is to be compared with the source string.
0337      * @return Returns a byte value. GREATER if source is greater
0338      * than target; EQUAL if source is equal to target; LESS if source is less
0339      * than target
0340      * @deprecated ICU 2.6 use the overload with UErrorCode &
0341      */
0342     virtual EComparisonResult compare(const UnicodeString& source,
0343                                       const UnicodeString& target) const;
0344 #endif  // U_FORCE_HIDE_DEPRECATED_API
0345 
0346     /**
0347      * The comparison function compares the character data stored in two
0348      * different strings. Returns information about whether a string is less
0349      * than, greater than or equal to another string.
0350      * @param source the source string to be compared with.
0351      * @param target the string that is to be compared with the source string.
0352      * @param status possible error code
0353      * @return Returns an enum value. UCOL_GREATER if source is greater
0354      * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source is less
0355      * than target
0356      * @stable ICU 2.6
0357      */
0358     virtual UCollationResult compare(const UnicodeString& source,
0359                                       const UnicodeString& target,
0360                                       UErrorCode &status) const = 0;
0361 
0362 #ifndef U_FORCE_HIDE_DEPRECATED_API
0363     /**
0364      * Does the same thing as compare but limits the comparison to a specified
0365      * length
0366      * @param source the source string to be compared with.
0367      * @param target the string that is to be compared with the source string.
0368      * @param length the length the comparison is limited to
0369      * @return Returns a byte value. GREATER if source (up to the specified
0370      *         length) is greater than target; EQUAL if source (up to specified
0371      *         length) is equal to target; LESS if source (up to the specified
0372      *         length) is less  than target.
0373      * @deprecated ICU 2.6 use the overload with UErrorCode &
0374      */
0375     virtual EComparisonResult compare(const UnicodeString& source,
0376                                       const UnicodeString& target,
0377                                       int32_t length) const;
0378 #endif  // U_FORCE_HIDE_DEPRECATED_API
0379 
0380     /**
0381      * Does the same thing as compare but limits the comparison to a specified
0382      * length
0383      * @param source the source string to be compared with.
0384      * @param target the string that is to be compared with the source string.
0385      * @param length the length the comparison is limited to
0386      * @param status possible error code
0387      * @return Returns an enum value. UCOL_GREATER if source (up to the specified
0388      *         length) is greater than target; UCOL_EQUAL if source (up to specified
0389      *         length) is equal to target; UCOL_LESS if source (up to the specified
0390      *         length) is less  than target.
0391      * @stable ICU 2.6
0392      */
0393     virtual UCollationResult compare(const UnicodeString& source,
0394                                       const UnicodeString& target,
0395                                       int32_t length,
0396                                       UErrorCode &status) const = 0;
0397 
0398 #ifndef U_FORCE_HIDE_DEPRECATED_API
0399     /**
0400      * The comparison function compares the character data stored in two
0401      * different string arrays. Returns information about whether a string array
0402      * is less than, greater than or equal to another string array.
0403      * <p>Example of use:
0404      * <pre>
0405      * .       char16_t ABC[] = {0x41, 0x42, 0x43, 0};  // = "ABC"
0406      * .       char16_t abc[] = {0x61, 0x62, 0x63, 0};  // = "abc"
0407      * .       UErrorCode status = U_ZERO_ERROR;
0408      * .       Collator *myCollation =
0409      * .                         Collator::createInstance(Locale::getUS(), status);
0410      * .       if (U_FAILURE(status)) return;
0411      * .       myCollation->setStrength(Collator::PRIMARY);
0412      * .       // result would be Collator::EQUAL ("abc" == "ABC")
0413      * .       // (no primary difference between "abc" and "ABC")
0414      * .       Collator::EComparisonResult result =
0415      * .                             myCollation->compare(abc, 3, ABC, 3);
0416      * .       myCollation->setStrength(Collator::TERTIARY);
0417      * .       // result would be Collator::LESS ("abc" &lt;&lt;&lt; "ABC")
0418      * .       // (with tertiary difference between "abc" and "ABC")
0419      * .       result = myCollation->compare(abc, 3, ABC, 3);
0420      * </pre>
0421      * @param source the source string array to be compared with.
0422      * @param sourceLength the length of the source string array.  If this value
0423      *        is equal to -1, the string array is null-terminated.
0424      * @param target the string that is to be compared with the source string.
0425      * @param targetLength the length of the target string array.  If this value
0426      *        is equal to -1, the string array is null-terminated.
0427      * @return Returns a byte value. GREATER if source is greater than target;
0428      *         EQUAL if source is equal to target; LESS if source is less than
0429      *         target
0430      * @deprecated ICU 2.6 use the overload with UErrorCode &
0431      */
0432     virtual EComparisonResult compare(const char16_t* source, int32_t sourceLength,
0433                                       const char16_t* target, int32_t targetLength)
0434                                       const;
0435 #endif  // U_FORCE_HIDE_DEPRECATED_API
0436 
0437     /**
0438      * The comparison function compares the character data stored in two
0439      * different string arrays. Returns information about whether a string array
0440      * is less than, greater than or equal to another string array.
0441      * @param source the source string array to be compared with.
0442      * @param sourceLength the length of the source string array.  If this value
0443      *        is equal to -1, the string array is null-terminated.
0444      * @param target the string that is to be compared with the source string.
0445      * @param targetLength the length of the target string array.  If this value
0446      *        is equal to -1, the string array is null-terminated.
0447      * @param status possible error code
0448      * @return Returns an enum value. UCOL_GREATER if source is greater
0449      * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source is less
0450      * than target
0451      * @stable ICU 2.6
0452      */
0453     virtual UCollationResult compare(const char16_t* source, int32_t sourceLength,
0454                                       const char16_t* target, int32_t targetLength,
0455                                       UErrorCode &status) const = 0;
0456 
0457     /**
0458      * Compares two strings using the Collator.
0459      * Returns whether the first one compares less than/equal to/greater than
0460      * the second one.
0461      * This version takes UCharIterator input.
0462      * @param sIter the first ("source") string iterator
0463      * @param tIter the second ("target") string iterator
0464      * @param status ICU status
0465      * @return UCOL_LESS, UCOL_EQUAL or UCOL_GREATER
0466      * @stable ICU 4.2
0467      */
0468     virtual UCollationResult compare(UCharIterator &sIter,
0469                                      UCharIterator &tIter,
0470                                      UErrorCode &status) const;
0471 
0472     /**
0473      * Compares two UTF-8 strings using the Collator.
0474      * Returns whether the first one compares less than/equal to/greater than
0475      * the second one.
0476      * This version takes UTF-8 input.
0477      * Note that a StringPiece can be implicitly constructed
0478      * from a std::string or a NUL-terminated const char * string.
0479      * @param source the first UTF-8 string
0480      * @param target the second UTF-8 string
0481      * @param status ICU status
0482      * @return UCOL_LESS, UCOL_EQUAL or UCOL_GREATER
0483      * @stable ICU 4.2
0484      */
0485     virtual UCollationResult compareUTF8(const StringPiece &source,
0486                                          const StringPiece &target,
0487                                          UErrorCode &status) const;
0488 
0489     /**
0490      * Transforms the string into a series of characters that can be compared
0491      * with CollationKey::compareTo. It is not possible to restore the original
0492      * string from the chars in the sort key.
0493      * <p>Use CollationKey::equals or CollationKey::compare to compare the
0494      * generated sort keys.
0495      * If the source string is null, a null collation key will be returned.
0496      *
0497      * Note that sort keys are often less efficient than simply doing comparison.
0498      * For more details, see the ICU User Guide.
0499      *
0500      * @param source the source string to be transformed into a sort key.
0501      * @param key the collation key to be filled in
0502      * @param status the error code status.
0503      * @return the collation key of the string based on the collation rules.
0504      * @see CollationKey#compare
0505      * @stable ICU 2.0
0506      */
0507     virtual CollationKey& getCollationKey(const UnicodeString&  source,
0508                                           CollationKey& key,
0509                                           UErrorCode& status) const = 0;
0510 
0511     /**
0512      * Transforms the string into a series of characters that can be compared
0513      * with CollationKey::compareTo. It is not possible to restore the original
0514      * string from the chars in the sort key.
0515      * <p>Use CollationKey::equals or CollationKey::compare to compare the
0516      * generated sort keys.
0517      * <p>If the source string is null, a null collation key will be returned.
0518      *
0519      * Note that sort keys are often less efficient than simply doing comparison.
0520      * For more details, see the ICU User Guide.
0521      *
0522      * @param source the source string to be transformed into a sort key.
0523      * @param sourceLength length of the collation key
0524      * @param key the collation key to be filled in
0525      * @param status the error code status.
0526      * @return the collation key of the string based on the collation rules.
0527      * @see CollationKey#compare
0528      * @stable ICU 2.0
0529      */
0530     virtual CollationKey& getCollationKey(const char16_t*source,
0531                                           int32_t sourceLength,
0532                                           CollationKey& key,
0533                                           UErrorCode& status) const = 0;
0534     /**
0535      * Generates the hash code for the collation object
0536      * @stable ICU 2.0
0537      */
0538     virtual int32_t hashCode(void) const = 0;
0539 
0540 #ifndef U_FORCE_HIDE_DEPRECATED_API
0541     /**
0542      * Gets the locale of the Collator
0543      *
0544      * @param type can be either requested, valid or actual locale. For more
0545      *             information see the definition of ULocDataLocaleType in
0546      *             uloc.h
0547      * @param status the error code status.
0548      * @return locale where the collation data lives. If the collator
0549      *         was instantiated from rules, locale is empty.
0550      * @deprecated ICU 2.8 This API is under consideration for revision
0551      * in ICU 3.0.
0552      */
0553     virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0;
0554 #endif  // U_FORCE_HIDE_DEPRECATED_API
0555 
0556     /**
0557      * Convenience method for comparing two strings based on the collation rules.
0558      * @param source the source string to be compared with.
0559      * @param target the target string to be compared with.
0560      * @return true if the first string is greater than the second one,
0561      *         according to the collation rules. false, otherwise.
0562      * @see Collator#compare
0563      * @stable ICU 2.0
0564      */
0565     UBool greater(const UnicodeString& source, const UnicodeString& target)
0566                   const;
0567 
0568     /**
0569      * Convenience method for comparing two strings based on the collation rules.
0570      * @param source the source string to be compared with.
0571      * @param target the target string to be compared with.
0572      * @return true if the first string is greater than or equal to the second
0573      *         one, according to the collation rules. false, otherwise.
0574      * @see Collator#compare
0575      * @stable ICU 2.0
0576      */
0577     UBool greaterOrEqual(const UnicodeString& source,
0578                          const UnicodeString& target) const;
0579 
0580     /**
0581      * Convenience method for comparing two strings based on the collation rules.
0582      * @param source the source string to be compared with.
0583      * @param target the target string to be compared with.
0584      * @return true if the strings are equal according to the collation rules.
0585      *         false, otherwise.
0586      * @see Collator#compare
0587      * @stable ICU 2.0
0588      */
0589     UBool equals(const UnicodeString& source, const UnicodeString& target) const;
0590 
0591 #ifndef U_FORCE_HIDE_DEPRECATED_API
0592     /**
0593      * Determines the minimum strength that will be used in comparison or
0594      * transformation.
0595      * <p>E.g. with strength == SECONDARY, the tertiary difference is ignored
0596      * <p>E.g. with strength == PRIMARY, the secondary and tertiary difference
0597      * are ignored.
0598      * @return the current comparison level.
0599      * @see Collator#setStrength
0600      * @deprecated ICU 2.6 Use getAttribute(UCOL_STRENGTH...) instead
0601      */
0602     virtual ECollationStrength getStrength(void) const;
0603 
0604     /**
0605      * Sets the minimum strength to be used in comparison or transformation.
0606      * <p>Example of use:
0607      * <pre>
0608      *  \code
0609      *  UErrorCode status = U_ZERO_ERROR;
0610      *  Collator*myCollation = Collator::createInstance(Locale::getUS(), status);
0611      *  if (U_FAILURE(status)) return;
0612      *  myCollation->setStrength(Collator::PRIMARY);
0613      *  // result will be "abc" == "ABC"
0614      *  // tertiary differences will be ignored
0615      *  Collator::ComparisonResult result = myCollation->compare("abc", "ABC");
0616      * \endcode
0617      * </pre>
0618      * @see Collator#getStrength
0619      * @param newStrength the new comparison level.
0620      * @deprecated ICU 2.6 Use setAttribute(UCOL_STRENGTH...) instead
0621      */
0622     virtual void setStrength(ECollationStrength newStrength);
0623 #endif  // U_FORCE_HIDE_DEPRECATED_API
0624 
0625     /**
0626      * Retrieves the reordering codes for this collator.
0627      * @param dest The array to fill with the script ordering.
0628      * @param destCapacity The length of dest. If it is 0, then dest may be nullptr and the function
0629      *  will only return the length of the result without writing any codes (pre-flighting).
0630      * @param status A reference to an error code value, which must not indicate
0631      * a failure before the function call.
0632      * @return The length of the script ordering array.
0633      * @see ucol_setReorderCodes
0634      * @see Collator#getEquivalentReorderCodes
0635      * @see Collator#setReorderCodes
0636      * @see UScriptCode
0637      * @see UColReorderCode
0638      * @stable ICU 4.8
0639      */
0640      virtual int32_t getReorderCodes(int32_t *dest,
0641                                      int32_t destCapacity,
0642                                      UErrorCode& status) const;
0643 
0644     /**
0645      * Sets the ordering of scripts for this collator.
0646      *
0647      * <p>The reordering codes are a combination of script codes and reorder codes.
0648      * @param reorderCodes An array of script codes in the new order. This can be nullptr if the
0649      * length is also set to 0. An empty array will clear any reordering codes on the collator.
0650      * @param reorderCodesLength The length of reorderCodes.
0651      * @param status error code
0652      * @see ucol_setReorderCodes
0653      * @see Collator#getReorderCodes
0654      * @see Collator#getEquivalentReorderCodes
0655      * @see UScriptCode
0656      * @see UColReorderCode
0657      * @stable ICU 4.8
0658      */
0659      virtual void setReorderCodes(const int32_t* reorderCodes,
0660                                   int32_t reorderCodesLength,
0661                                   UErrorCode& status) ;
0662 
0663     /**
0664      * Retrieves the reorder codes that are grouped with the given reorder code. Some reorder
0665      * codes will be grouped and must reorder together.
0666      * Beginning with ICU 55, scripts only reorder together if they are primary-equal,
0667      * for example Hiragana and Katakana.
0668      *
0669      * @param reorderCode The reorder code to determine equivalence for.
0670      * @param dest The array to fill with the script equivalence reordering codes.
0671      * @param destCapacity The length of dest. If it is 0, then dest may be nullptr and the
0672      * function will only return the length of the result without writing any codes (pre-flighting).
0673      * @param status A reference to an error code value, which must not indicate
0674      * a failure before the function call.
0675      * @return The length of the of the reordering code equivalence array.
0676      * @see ucol_setReorderCodes
0677      * @see Collator#getReorderCodes
0678      * @see Collator#setReorderCodes
0679      * @see UScriptCode
0680      * @see UColReorderCode
0681      * @stable ICU 4.8
0682      */
0683     static int32_t U_EXPORT2 getEquivalentReorderCodes(int32_t reorderCode,
0684                                 int32_t* dest,
0685                                 int32_t destCapacity,
0686                                 UErrorCode& status);
0687 
0688     /**
0689      * Get name of the object for the desired Locale, in the desired language
0690      * @param objectLocale must be from getAvailableLocales
0691      * @param displayLocale specifies the desired locale for output
0692      * @param name the fill-in parameter of the return value
0693      * @return display-able name of the object for the object locale in the
0694      *         desired language
0695      * @stable ICU 2.0
0696      */
0697     static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
0698                                          const Locale& displayLocale,
0699                                          UnicodeString& name);
0700 
0701     /**
0702     * Get name of the object for the desired Locale, in the language of the
0703     * default locale.
0704     * @param objectLocale must be from getAvailableLocales
0705     * @param name the fill-in parameter of the return value
0706     * @return name of the object for the desired locale in the default language
0707     * @stable ICU 2.0
0708     */
0709     static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
0710                                          UnicodeString& name);
0711 
0712     /**
0713      * Get the set of Locales for which Collations are installed.
0714      *
0715      * <p>Note this does not include locales supported by registered collators.
0716      * If collators might have been registered, use the overload of getAvailableLocales
0717      * that returns a StringEnumeration.</p>
0718      *
0719      * @param count the output parameter of number of elements in the locale list
0720      * @return the list of available locales for which collations are installed
0721      * @stable ICU 2.0
0722      */
0723     static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
0724 
0725     /**
0726      * Return a StringEnumeration over the locales available at the time of the call,
0727      * including registered locales.  If a severe error occurs (such as out of memory
0728      * condition) this will return null. If there is no locale data, an empty enumeration
0729      * will be returned.
0730      * @return a StringEnumeration over the locales available at the time of the call
0731      * @stable ICU 2.6
0732      */
0733     static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
0734 
0735     /**
0736      * Create a string enumerator of all possible keywords that are relevant to
0737      * collation. At this point, the only recognized keyword for this
0738      * service is "collation".
0739      * @param status input-output error code
0740      * @return a string enumeration over locale strings. The caller is
0741      * responsible for closing the result.
0742      * @stable ICU 3.0
0743      */
0744     static StringEnumeration* U_EXPORT2 getKeywords(UErrorCode& status);
0745 
0746     /**
0747      * Given a keyword, create a string enumeration of all values
0748      * for that keyword that are currently in use.
0749      * @param keyword a particular keyword as enumerated by
0750      * ucol_getKeywords. If any other keyword is passed in, status is set
0751      * to U_ILLEGAL_ARGUMENT_ERROR.
0752      * @param status input-output error code
0753      * @return a string enumeration over collation keyword values, or nullptr
0754      * upon error. The caller is responsible for deleting the result.
0755      * @stable ICU 3.0
0756      */
0757     static StringEnumeration* U_EXPORT2 getKeywordValues(const char *keyword, UErrorCode& status);
0758 
0759     /**
0760      * Given a key and a locale, returns an array of string values in a preferred
0761      * order that would make a difference. These are all and only those values where
0762      * the open (creation) of the service with the locale formed from the input locale
0763      * plus input keyword and that value has different behavior than creation with the
0764      * input locale alone.
0765      * @param keyword        one of the keys supported by this service.  For now, only
0766      *                      "collation" is supported.
0767      * @param locale        the locale
0768      * @param commonlyUsed  if set to true it will return only commonly used values
0769      *                      with the given locale in preferred order.  Otherwise,
0770      *                      it will return all the available values for the locale.
0771      * @param status ICU status
0772      * @return a string enumeration over keyword values for the given key and the locale.
0773      * @stable ICU 4.2
0774      */
0775     static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* keyword, const Locale& locale,
0776                                                                     UBool commonlyUsed, UErrorCode& status);
0777 
0778     /**
0779      * Return the functionally equivalent locale for the given
0780      * requested locale, with respect to given keyword, for the
0781      * collation service.  If two locales return the same result, then
0782      * collators instantiated for these locales will behave
0783      * equivalently.  The converse is not always true; two collators
0784      * may in fact be equivalent, but return different results, due to
0785      * internal details.  The return result has no other meaning than
0786      * that stated above, and implies nothing as to the relationship
0787      * between the two locales.  This is intended for use by
0788      * applications who wish to cache collators, or otherwise reuse
0789      * collators when possible.  The functional equivalent may change
0790      * over time.  For more information, please see the <a
0791      * href="https://unicode-org.github.io/icu/userguide/locale#locales-and-services">
0792      * Locales and Services</a> section of the ICU User Guide.
0793      * @param keyword a particular keyword as enumerated by
0794      * ucol_getKeywords.
0795      * @param locale the requested locale
0796      * @param isAvailable reference to a fillin parameter that
0797      * indicates whether the requested locale was 'available' to the
0798      * collation service. A locale is defined as 'available' if it
0799      * physically exists within the collation locale data.
0800      * @param status reference to input-output error code
0801      * @return the functionally equivalent collation locale, or the root
0802      * locale upon error.
0803      * @stable ICU 3.0
0804      */
0805     static Locale U_EXPORT2 getFunctionalEquivalent(const char* keyword, const Locale& locale,
0806                                           UBool& isAvailable, UErrorCode& status);
0807 
0808 #if !UCONFIG_NO_SERVICE
0809     /**
0810      * Register a new Collator.  The collator will be adopted.
0811      * Because ICU may choose to cache collators internally, this must be
0812      * called at application startup, prior to any calls to
0813      * Collator::createInstance to avoid undefined behavior.
0814      * @param toAdopt the Collator instance to be adopted
0815      * @param locale the locale with which the collator will be associated
0816      * @param status the in/out status code, no special meanings are assigned
0817      * @return a registry key that can be used to unregister this collator
0818      * @stable ICU 2.6
0819      */
0820     static URegistryKey U_EXPORT2 registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status);
0821 
0822     /**
0823      * Register a new CollatorFactory.  The factory will be adopted.
0824      * Because ICU may choose to cache collators internally, this must be
0825      * called at application startup, prior to any calls to
0826      * Collator::createInstance to avoid undefined behavior.
0827      * @param toAdopt the CollatorFactory instance to be adopted
0828      * @param status the in/out status code, no special meanings are assigned
0829      * @return a registry key that can be used to unregister this collator
0830      * @stable ICU 2.6
0831      */
0832     static URegistryKey U_EXPORT2 registerFactory(CollatorFactory* toAdopt, UErrorCode& status);
0833 
0834     /**
0835      * Unregister a previously-registered Collator or CollatorFactory
0836      * using the key returned from the register call.  Key becomes
0837      * invalid after a successful call and should not be used again.
0838      * The object corresponding to the key will be deleted.
0839      * Because ICU may choose to cache collators internally, this should
0840      * be called during application shutdown, after all calls to
0841      * Collator::createInstance to avoid undefined behavior.
0842      * @param key the registry key returned by a previous call to registerInstance
0843      * @param status the in/out status code, no special meanings are assigned
0844      * @return true if the collator for the key was successfully unregistered
0845      * @stable ICU 2.6
0846      */
0847     static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
0848 #endif /* UCONFIG_NO_SERVICE */
0849 
0850     /**
0851      * Gets the version information for a Collator.
0852      * @param info the version # information, the result will be filled in
0853      * @stable ICU 2.0
0854      */
0855     virtual void getVersion(UVersionInfo info) const = 0;
0856 
0857     /**
0858      * Returns a unique class ID POLYMORPHICALLY. Pure virtual method.
0859      * This method is to implement a simple version of RTTI, since not all C++
0860      * compilers support genuine RTTI. Polymorphic operator==() and clone()
0861      * methods call this method.
0862      * @return The class ID for this object. All objects of a given class have
0863      *         the same class ID.  Objects of other classes have different class
0864      *         IDs.
0865      * @stable ICU 2.0
0866      */
0867     virtual UClassID getDynamicClassID(void) const override = 0;
0868 
0869     /**
0870      * Universal attribute setter
0871      * @param attr attribute type
0872      * @param value attribute value
0873      * @param status to indicate whether the operation went on smoothly or
0874      *        there were errors
0875      * @stable ICU 2.2
0876      */
0877     virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
0878                               UErrorCode &status) = 0;
0879 
0880     /**
0881      * Universal attribute getter
0882      * @param attr attribute type
0883      * @param status to indicate whether the operation went on smoothly or
0884      *        there were errors
0885      * @return attribute value
0886      * @stable ICU 2.2
0887      */
0888     virtual UColAttributeValue getAttribute(UColAttribute attr,
0889                                             UErrorCode &status) const = 0;
0890 
0891     /**
0892      * Sets the variable top to the top of the specified reordering group.
0893      * The variable top determines the highest-sorting character
0894      * which is affected by UCOL_ALTERNATE_HANDLING.
0895      * If that attribute is set to UCOL_NON_IGNORABLE, then the variable top has no effect.
0896      *
0897      * The base class implementation sets U_UNSUPPORTED_ERROR.
0898      * @param group one of UCOL_REORDER_CODE_SPACE, UCOL_REORDER_CODE_PUNCTUATION,
0899      *              UCOL_REORDER_CODE_SYMBOL, UCOL_REORDER_CODE_CURRENCY;
0900      *              or UCOL_REORDER_CODE_DEFAULT to restore the default max variable group
0901      * @param errorCode Standard ICU error code. Its input value must
0902      *                  pass the U_SUCCESS() test, or else the function returns
0903      *                  immediately. Check for U_FAILURE() on output or use with
0904      *                  function chaining. (See User Guide for details.)
0905      * @return *this
0906      * @see getMaxVariable
0907      * @stable ICU 53
0908      */
0909     virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCode);
0910 
0911     /**
0912      * Returns the maximum reordering group whose characters are affected by UCOL_ALTERNATE_HANDLING.
0913      *
0914      * The base class implementation returns UCOL_REORDER_CODE_PUNCTUATION.
0915      * @return the maximum variable reordering group.
0916      * @see setMaxVariable
0917      * @stable ICU 53
0918      */
0919     virtual UColReorderCode getMaxVariable() const;
0920 
0921 #ifndef U_FORCE_HIDE_DEPRECATED_API
0922     /**
0923      * Sets the variable top to the primary weight of the specified string.
0924      *
0925      * Beginning with ICU 53, the variable top is pinned to
0926      * the top of one of the supported reordering groups,
0927      * and it must not be beyond the last of those groups.
0928      * See setMaxVariable().
0929      * @param varTop one or more (if contraction) char16_ts to which the variable top should be set
0930      * @param len length of variable top string. If -1 it is considered to be zero terminated.
0931      * @param status error code. If error code is set, the return value is undefined. Errors set by this function are: <br>
0932      *    U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction<br>
0933      *    U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond
0934      *    the last reordering group supported by setMaxVariable()
0935      * @return variable top primary weight
0936      * @deprecated ICU 53 Call setMaxVariable() instead.
0937      */
0938     virtual uint32_t setVariableTop(const char16_t *varTop, int32_t len, UErrorCode &status) = 0;
0939 
0940     /**
0941      * Sets the variable top to the primary weight of the specified string.
0942      *
0943      * Beginning with ICU 53, the variable top is pinned to
0944      * the top of one of the supported reordering groups,
0945      * and it must not be beyond the last of those groups.
0946      * See setMaxVariable().
0947      * @param varTop a UnicodeString size 1 or more (if contraction) of char16_ts to which the variable top should be set
0948      * @param status error code. If error code is set, the return value is undefined. Errors set by this function are: <br>
0949      *    U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction<br>
0950      *    U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond
0951      *    the last reordering group supported by setMaxVariable()
0952      * @return variable top primary weight
0953      * @deprecated ICU 53 Call setMaxVariable() instead.
0954      */
0955     virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) = 0;
0956 
0957     /**
0958      * Sets the variable top to the specified primary weight.
0959      *
0960      * Beginning with ICU 53, the variable top is pinned to
0961      * the top of one of the supported reordering groups,
0962      * and it must not be beyond the last of those groups.
0963      * See setMaxVariable().
0964      * @param varTop primary weight, as returned by setVariableTop or ucol_getVariableTop
0965      * @param status error code
0966      * @deprecated ICU 53 Call setMaxVariable() instead.
0967      */
0968     virtual void setVariableTop(uint32_t varTop, UErrorCode &status) = 0;
0969 #endif  // U_FORCE_HIDE_DEPRECATED_API
0970 
0971     /**
0972      * Gets the variable top value of a Collator.
0973      * @param status error code (not changed by function). If error code is set, the return value is undefined.
0974      * @return the variable top primary weight
0975      * @see getMaxVariable
0976      * @stable ICU 2.0
0977      */
0978     virtual uint32_t getVariableTop(UErrorCode &status) const = 0;
0979 
0980     /**
0981      * Get a UnicodeSet that contains all the characters and sequences
0982      * tailored in this collator.
0983      * @param status      error code of the operation
0984      * @return a pointer to a UnicodeSet object containing all the
0985      *         code points and sequences that may sort differently than
0986      *         in the root collator. The object must be disposed of by using delete
0987      * @stable ICU 2.4
0988      */
0989     virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
0990 
0991 #ifndef U_FORCE_HIDE_DEPRECATED_API
0992     /**
0993      * Same as clone().
0994      * The base class implementation simply calls clone().
0995      * @return a copy of this object, owned by the caller
0996      * @see clone()
0997      * @deprecated ICU 50 no need to have two methods for cloning
0998      */
0999     virtual Collator* safeClone() const;
1000 #endif  // U_FORCE_HIDE_DEPRECATED_API
1001 
1002     /**
1003      * Get the sort key as an array of bytes from a UnicodeString.
1004      * Sort key byte arrays are zero-terminated and can be compared using
1005      * strcmp().
1006      *
1007      * Note that sort keys are often less efficient than simply doing comparison.
1008      * For more details, see the ICU User Guide.
1009      *
1010      * @param source string to be processed.
1011      * @param result buffer to store result in. If nullptr, number of bytes needed
1012      *        will be returned.
1013      * @param resultLength length of the result buffer. If if not enough the
1014      *        buffer will be filled to capacity.
1015      * @return Number of bytes needed for storing the sort key
1016      * @stable ICU 2.2
1017      */
1018     virtual int32_t getSortKey(const UnicodeString& source,
1019                               uint8_t* result,
1020                               int32_t resultLength) const = 0;
1021 
1022     /**
1023      * Get the sort key as an array of bytes from a char16_t buffer.
1024      * Sort key byte arrays are zero-terminated and can be compared using
1025      * strcmp().
1026      *
1027      * Note that sort keys are often less efficient than simply doing comparison.
1028      * For more details, see the ICU User Guide.
1029      *
1030      * @param source string to be processed.
1031      * @param sourceLength length of string to be processed.
1032      *        If -1, the string is 0 terminated and length will be decided by the
1033      *        function.
1034      * @param result buffer to store result in. If nullptr, number of bytes needed
1035      *        will be returned.
1036      * @param resultLength length of the result buffer. If if not enough the
1037      *        buffer will be filled to capacity.
1038      * @return Number of bytes needed for storing the sort key
1039      * @stable ICU 2.2
1040      */
1041     virtual int32_t getSortKey(const char16_t*source, int32_t sourceLength,
1042                                uint8_t*result, int32_t resultLength) const = 0;
1043 
1044     /**
1045      * Produce a bound for a given sortkey and a number of levels.
1046      * Return value is always the number of bytes needed, regardless of
1047      * whether the result buffer was big enough or even valid.<br>
1048      * Resulting bounds can be used to produce a range of strings that are
1049      * between upper and lower bounds. For example, if bounds are produced
1050      * for a sortkey of string "smith", strings between upper and lower
1051      * bounds with one level would include "Smith", "SMITH", "sMiTh".<br>
1052      * There are two upper bounds that can be produced. If UCOL_BOUND_UPPER
1053      * is produced, strings matched would be as above. However, if bound
1054      * produced using UCOL_BOUND_UPPER_LONG is used, the above example will
1055      * also match "Smithsonian" and similar.<br>
1056      * For more on usage, see example in cintltst/capitst.c in procedure
1057      * TestBounds.
1058      * Sort keys may be compared using <TT>strcmp</TT>.
1059      * @param source The source sortkey.
1060      * @param sourceLength The length of source, or -1 if null-terminated.
1061      *                     (If an unmodified sortkey is passed, it is always null
1062      *                      terminated).
1063      * @param boundType Type of bound required. It can be UCOL_BOUND_LOWER, which
1064      *                  produces a lower inclusive bound, UCOL_BOUND_UPPER, that
1065      *                  produces upper bound that matches strings of the same length
1066      *                  or UCOL_BOUND_UPPER_LONG that matches strings that have the
1067      *                  same starting substring as the source string.
1068      * @param noOfLevels  Number of levels required in the resulting bound (for most
1069      *                    uses, the recommended value is 1). See users guide for
1070      *                    explanation on number of levels a sortkey can have.
1071      * @param result A pointer to a buffer to receive the resulting sortkey.
1072      * @param resultLength The maximum size of result.
1073      * @param status Used for returning error code if something went wrong. If the
1074      *               number of levels requested is higher than the number of levels
1075      *               in the source key, a warning (U_SORT_KEY_TOO_SHORT_WARNING) is
1076      *               issued.
1077      * @return The size needed to fully store the bound.
1078      * @see ucol_keyHashCode
1079      * @stable ICU 2.1
1080      */
1081     static int32_t U_EXPORT2 getBound(const uint8_t       *source,
1082             int32_t             sourceLength,
1083             UColBoundMode       boundType,
1084             uint32_t            noOfLevels,
1085             uint8_t             *result,
1086             int32_t             resultLength,
1087             UErrorCode          &status);
1088 
1089 
1090 protected:
1091 
1092     // Collator protected constructors -------------------------------------
1093 
1094     /**
1095     * Default constructor.
1096     * Constructor is different from the old default Collator constructor.
1097     * The task for determining the default collation strength and normalization
1098     * mode is left to the child class.
1099     * @stable ICU 2.0
1100     */
1101     Collator();
1102 
1103 #ifndef U_HIDE_DEPRECATED_API
1104     /**
1105     * Constructor.
1106     * Empty constructor, does not handle the arguments.
1107     * This constructor is done for backward compatibility with 1.7 and 1.8.
1108     * The task for handling the argument collation strength and normalization
1109     * mode is left to the child class.
1110     * @param collationStrength collation strength
1111     * @param decompositionMode
1112     * @deprecated ICU 2.4. Subclasses should use the default constructor
1113     * instead and handle the strength and normalization mode themselves.
1114     */
1115     Collator(UCollationStrength collationStrength,
1116              UNormalizationMode decompositionMode);
1117 #endif  /* U_HIDE_DEPRECATED_API */
1118 
1119     /**
1120     * Copy constructor.
1121     * @param other Collator object to be copied from
1122     * @stable ICU 2.0
1123     */
1124     Collator(const Collator& other);
1125 
1126 public:
1127    /**
1128     * Used internally by registration to define the requested and valid locales.
1129     * @param requestedLocale the requested locale
1130     * @param validLocale the valid locale
1131     * @param actualLocale the actual locale
1132     * @internal
1133     */
1134     virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
1135 
1136     /** Get the short definition string for a collator. This internal API harvests the collator's
1137      *  locale and the attribute set and produces a string that can be used for opening
1138      *  a collator with the same attributes using the ucol_openFromShortString API.
1139      *  This string will be normalized.
1140      *  The structure and the syntax of the string is defined in the "Naming collators"
1141      *  section of the users guide:
1142      *  https://unicode-org.github.io/icu/userguide/collation/concepts#collator-naming-scheme
1143      *  This function supports preflighting.
1144      *
1145      *  This is internal, and intended to be used with delegate converters.
1146      *
1147      *  @param locale a locale that will appear as a collators locale in the resulting
1148      *                short string definition. If nullptr, the locale will be harvested
1149      *                from the collator.
1150      *  @param buffer space to hold the resulting string
1151      *  @param capacity capacity of the buffer
1152      *  @param status for returning errors. All the preflighting errors are featured
1153      *  @return length of the resulting string
1154      *  @see ucol_openFromShortString
1155      *  @see ucol_normalizeShortDefinitionString
1156      *  @see ucol_getShortDefinitionString
1157      *  @internal
1158      */
1159     virtual int32_t internalGetShortDefinitionString(const char *locale,
1160                                                      char *buffer,
1161                                                      int32_t capacity,
1162                                                      UErrorCode &status) const;
1163 
1164     /**
1165      * Implements ucol_strcollUTF8().
1166      * @internal
1167      */
1168     virtual UCollationResult internalCompareUTF8(
1169             const char *left, int32_t leftLength,
1170             const char *right, int32_t rightLength,
1171             UErrorCode &errorCode) const;
1172 
1173     /**
1174      * Implements ucol_nextSortKeyPart().
1175      * @internal
1176      */
1177     virtual int32_t
1178     internalNextSortKeyPart(
1179             UCharIterator *iter, uint32_t state[2],
1180             uint8_t *dest, int32_t count, UErrorCode &errorCode) const;
1181 
1182 #ifndef U_HIDE_INTERNAL_API
1183     /** @internal */
1184     static inline Collator *fromUCollator(UCollator *uc) {
1185         return reinterpret_cast<Collator *>(uc);
1186     }
1187     /** @internal */
1188     static inline const Collator *fromUCollator(const UCollator *uc) {
1189         return reinterpret_cast<const Collator *>(uc);
1190     }
1191     /** @internal */
1192     inline UCollator *toUCollator() {
1193         return reinterpret_cast<UCollator *>(this);
1194     }
1195     /** @internal */
1196     inline const UCollator *toUCollator() const {
1197         return reinterpret_cast<const UCollator *>(this);
1198     }
1199 #endif  // U_HIDE_INTERNAL_API
1200 
1201 private:
1202     /**
1203      * Assignment operator. Private for now.
1204      */
1205     Collator& operator=(const Collator& other) = delete;
1206 
1207     friend class CFactory;
1208     friend class SimpleCFactory;
1209     friend class ICUCollatorFactory;
1210     friend class ICUCollatorService;
1211     static Collator* makeInstance(const Locale& desiredLocale,
1212                                   UErrorCode& status);
1213 };
1214 
1215 #if !UCONFIG_NO_SERVICE
1216 /**
1217  * A factory, used with registerFactory, the creates multiple collators and provides
1218  * display names for them.  A factory supports some number of locales-- these are the
1219  * locales for which it can create collators.  The factory can be visible, in which
1220  * case the supported locales will be enumerated by getAvailableLocales, or invisible,
1221  * in which they are not.  Invisible locales are still supported, they are just not
1222  * listed by getAvailableLocales.
1223  * <p>
1224  * If standard locale display names are sufficient, Collator instances can
1225  * be registered using registerInstance instead.</p>
1226  * <p>
1227  * Note: if the collators are to be used from C APIs, they must be instances
1228  * of RuleBasedCollator.</p>
1229  *
1230  * @stable ICU 2.6
1231  */
1232 class U_I18N_API CollatorFactory : public UObject {
1233 public:
1234 
1235     /**
1236      * Destructor
1237      * @stable ICU 3.0
1238      */
1239     virtual ~CollatorFactory();
1240 
1241     /**
1242      * Return true if this factory is visible.  Default is true.
1243      * If not visible, the locales supported by this factory will not
1244      * be listed by getAvailableLocales.
1245      * @return true if the factory is visible.
1246      * @stable ICU 2.6
1247      */
1248     virtual UBool visible(void) const;
1249 
1250     /**
1251      * Return a collator for the provided locale.  If the locale
1252      * is not supported, return nullptr.
1253      * @param loc the locale identifying the collator to be created.
1254      * @return a new collator if the locale is supported, otherwise nullptr.
1255      * @stable ICU 2.6
1256      */
1257     virtual Collator* createCollator(const Locale& loc) = 0;
1258 
1259     /**
1260      * Return the name of the collator for the objectLocale, localized for the displayLocale.
1261      * If objectLocale is not supported, or the factory is not visible, set the result string
1262      * to bogus.
1263      * @param objectLocale the locale identifying the collator
1264      * @param displayLocale the locale for which the display name of the collator should be localized
1265      * @param result an output parameter for the display name, set to bogus if not supported.
1266      * @return the display name
1267      * @stable ICU 2.6
1268      */
1269     virtual  UnicodeString& getDisplayName(const Locale& objectLocale,
1270                                            const Locale& displayLocale,
1271                                            UnicodeString& result);
1272 
1273     /**
1274      * Return an array of all the locale names directly supported by this factory.
1275      * The number of names is returned in count.  This array is owned by the factory.
1276      * Its contents must never change.
1277      * @param count output parameter for the number of locales supported by the factory
1278      * @param status the in/out error code
1279      * @return a pointer to an array of count UnicodeStrings.
1280      * @stable ICU 2.6
1281      */
1282     virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
1283 };
1284 #endif /* UCONFIG_NO_SERVICE */
1285 
1286 // Collator inline methods -----------------------------------------------
1287 
1288 U_NAMESPACE_END
1289 
1290 #endif /* #if !UCONFIG_NO_COLLATION */
1291 
1292 #endif /* U_SHOW_CPLUSPLUS_API */
1293 
1294 #endif