xref: /aosp_15_r20/external/icu/libicu/cts_headers/unicode/coll.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
5*0e209d39SAndroid Build Coastguard Worker *   Copyright (C) 1996-2016, International Business Machines
6*0e209d39SAndroid Build Coastguard Worker *   Corporation and others.  All Rights Reserved.
7*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
8*0e209d39SAndroid Build Coastguard Worker */
9*0e209d39SAndroid Build Coastguard Worker 
10*0e209d39SAndroid Build Coastguard Worker /**
11*0e209d39SAndroid Build Coastguard Worker  * \file
12*0e209d39SAndroid Build Coastguard Worker  * \brief C++ API: Collation Service.
13*0e209d39SAndroid Build Coastguard Worker  */
14*0e209d39SAndroid Build Coastguard Worker 
15*0e209d39SAndroid Build Coastguard Worker /**
16*0e209d39SAndroid Build Coastguard Worker * File coll.h
17*0e209d39SAndroid Build Coastguard Worker *
18*0e209d39SAndroid Build Coastguard Worker * Created by: Helena Shih
19*0e209d39SAndroid Build Coastguard Worker *
20*0e209d39SAndroid Build Coastguard Worker * Modification History:
21*0e209d39SAndroid Build Coastguard Worker *
22*0e209d39SAndroid Build Coastguard Worker *  Date        Name        Description
23*0e209d39SAndroid Build Coastguard Worker * 02/5/97      aliu        Modified createDefault to load collation data from
24*0e209d39SAndroid Build Coastguard Worker *                          binary files when possible.  Added related methods
25*0e209d39SAndroid Build Coastguard Worker *                          createCollationFromFile, chopLocale, createPathName.
26*0e209d39SAndroid Build Coastguard Worker * 02/11/97     aliu        Added members addToCache, findInCache, and fgCache.
27*0e209d39SAndroid Build Coastguard Worker * 02/12/97     aliu        Modified to create objects from RuleBasedCollator cache.
28*0e209d39SAndroid Build Coastguard Worker *                          Moved cache out of Collation class.
29*0e209d39SAndroid Build Coastguard Worker * 02/13/97     aliu        Moved several methods out of this class and into
30*0e209d39SAndroid Build Coastguard Worker *                          RuleBasedCollator, with modifications.  Modified
31*0e209d39SAndroid Build Coastguard Worker *                          createDefault() to call new RuleBasedCollator(Locale&)
32*0e209d39SAndroid Build Coastguard Worker *                          constructor.  General clean up and documentation.
33*0e209d39SAndroid Build Coastguard Worker * 02/20/97     helena      Added clone, operator==, operator!=, operator=, copy
34*0e209d39SAndroid Build Coastguard Worker *                          constructor and getDynamicClassID.
35*0e209d39SAndroid Build Coastguard Worker * 03/25/97     helena      Updated with platform independent data types.
36*0e209d39SAndroid Build Coastguard Worker * 05/06/97     helena      Added memory allocation error detection.
37*0e209d39SAndroid Build Coastguard Worker * 06/20/97     helena      Java class name change.
38*0e209d39SAndroid Build Coastguard Worker * 09/03/97     helena      Added createCollationKeyValues().
39*0e209d39SAndroid Build Coastguard Worker * 02/10/98     damiba      Added compare() with length as parameter.
40*0e209d39SAndroid Build Coastguard Worker * 04/23/99     stephen     Removed EDecompositionMode, merged with
41*0e209d39SAndroid Build Coastguard Worker *                          Normalizer::EMode.
42*0e209d39SAndroid Build Coastguard Worker * 11/02/99     helena      Collator performance enhancements.  Eliminates the
43*0e209d39SAndroid Build Coastguard Worker *                          UnicodeString construction and special case for NO_OP.
44*0e209d39SAndroid Build Coastguard Worker * 11/23/99     srl         More performance enhancements. Inlining of
45*0e209d39SAndroid Build Coastguard Worker *                          critical accessors.
46*0e209d39SAndroid Build Coastguard Worker * 05/15/00     helena      Added version information API.
47*0e209d39SAndroid Build Coastguard Worker * 01/29/01     synwee      Modified into a C++ wrapper which calls C apis
48*0e209d39SAndroid Build Coastguard Worker *                          (ucol.h).
49*0e209d39SAndroid Build Coastguard Worker * 2012-2014    markus      Rewritten in C++ again.
50*0e209d39SAndroid Build Coastguard Worker */
51*0e209d39SAndroid Build Coastguard Worker 
52*0e209d39SAndroid Build Coastguard Worker #ifndef COLL_H
53*0e209d39SAndroid Build Coastguard Worker #define COLL_H
54*0e209d39SAndroid Build Coastguard Worker 
55*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
56*0e209d39SAndroid Build Coastguard Worker 
57*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
58*0e209d39SAndroid Build Coastguard Worker 
59*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_COLLATION
60*0e209d39SAndroid Build Coastguard Worker 
61*0e209d39SAndroid Build Coastguard Worker #include "unicode/uobject.h"
62*0e209d39SAndroid Build Coastguard Worker #include "unicode/ucol.h"
63*0e209d39SAndroid Build Coastguard Worker #include "unicode/unorm.h"
64*0e209d39SAndroid Build Coastguard Worker #include "unicode/locid.h"
65*0e209d39SAndroid Build Coastguard Worker #include "unicode/uniset.h"
66*0e209d39SAndroid Build Coastguard Worker #include "unicode/umisc.h"
67*0e209d39SAndroid Build Coastguard Worker #include "unicode/uiter.h"
68*0e209d39SAndroid Build Coastguard Worker #include "unicode/stringpiece.h"
69*0e209d39SAndroid Build Coastguard Worker 
70*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
71*0e209d39SAndroid Build Coastguard Worker 
72*0e209d39SAndroid Build Coastguard Worker class StringEnumeration;
73*0e209d39SAndroid Build Coastguard Worker 
74*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_SERVICE
75*0e209d39SAndroid Build Coastguard Worker /**
76*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.6
77*0e209d39SAndroid Build Coastguard Worker  */
78*0e209d39SAndroid Build Coastguard Worker class CollatorFactory;
79*0e209d39SAndroid Build Coastguard Worker #endif
80*0e209d39SAndroid Build Coastguard Worker 
81*0e209d39SAndroid Build Coastguard Worker /**
82*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
83*0e209d39SAndroid Build Coastguard Worker */
84*0e209d39SAndroid Build Coastguard Worker class CollationKey;
85*0e209d39SAndroid Build Coastguard Worker 
86*0e209d39SAndroid Build Coastguard Worker /**
87*0e209d39SAndroid Build Coastguard Worker * The <code>Collator</code> class performs locale-sensitive string
88*0e209d39SAndroid Build Coastguard Worker * comparison.<br>
89*0e209d39SAndroid Build Coastguard Worker * You use this class to build searching and sorting routines for natural
90*0e209d39SAndroid Build Coastguard Worker * language text.
91*0e209d39SAndroid Build Coastguard Worker * <p>
92*0e209d39SAndroid Build Coastguard Worker * <code>Collator</code> is an abstract base class. Subclasses implement
93*0e209d39SAndroid Build Coastguard Worker * specific collation strategies. One subclass,
94*0e209d39SAndroid Build Coastguard Worker * <code>RuleBasedCollator</code>, is currently provided and is applicable
95*0e209d39SAndroid Build Coastguard Worker * to a wide set of languages. Other subclasses may be created to handle more
96*0e209d39SAndroid Build Coastguard Worker * specialized needs.
97*0e209d39SAndroid Build Coastguard Worker * <p>
98*0e209d39SAndroid Build Coastguard Worker * Like other locale-sensitive classes, you can use the static factory method,
99*0e209d39SAndroid Build Coastguard Worker * <code>createInstance</code>, to obtain the appropriate
100*0e209d39SAndroid Build Coastguard Worker * <code>Collator</code> object for a given locale. You will only need to
101*0e209d39SAndroid Build Coastguard Worker * look at the subclasses of <code>Collator</code> if you need to
102*0e209d39SAndroid Build Coastguard Worker * understand the details of a particular collation strategy or if you need to
103*0e209d39SAndroid Build Coastguard Worker * modify that strategy.
104*0e209d39SAndroid Build Coastguard Worker * <p>
105*0e209d39SAndroid Build Coastguard Worker * The following example shows how to compare two strings using the
106*0e209d39SAndroid Build Coastguard Worker * <code>Collator</code> for the default locale.
107*0e209d39SAndroid Build Coastguard Worker * \htmlonly<blockquote>\endhtmlonly
108*0e209d39SAndroid Build Coastguard Worker * <pre>
109*0e209d39SAndroid Build Coastguard Worker * \code
110*0e209d39SAndroid Build Coastguard Worker * // Compare two strings in the default locale
111*0e209d39SAndroid Build Coastguard Worker * UErrorCode success = U_ZERO_ERROR;
112*0e209d39SAndroid Build Coastguard Worker * Collator* myCollator = Collator::createInstance(success);
113*0e209d39SAndroid Build Coastguard Worker * if (myCollator->compare("abc", "ABC") < 0)
114*0e209d39SAndroid Build Coastguard Worker *   cout << "abc is less than ABC" << endl;
115*0e209d39SAndroid Build Coastguard Worker * else
116*0e209d39SAndroid Build Coastguard Worker *   cout << "abc is greater than or equal to ABC" << endl;
117*0e209d39SAndroid Build Coastguard Worker * \endcode
118*0e209d39SAndroid Build Coastguard Worker * </pre>
119*0e209d39SAndroid Build Coastguard Worker * \htmlonly</blockquote>\endhtmlonly
120*0e209d39SAndroid Build Coastguard Worker * <p>
121*0e209d39SAndroid Build Coastguard Worker * You can set a <code>Collator</code>'s <em>strength</em> attribute to
122*0e209d39SAndroid Build Coastguard Worker * determine the level of difference considered significant in comparisons.
123*0e209d39SAndroid Build Coastguard Worker * Five strengths are provided: <code>PRIMARY</code>, <code>SECONDARY</code>,
124*0e209d39SAndroid Build Coastguard Worker * <code>TERTIARY</code>, <code>QUATERNARY</code> and <code>IDENTICAL</code>.
125*0e209d39SAndroid Build Coastguard Worker * The exact assignment of strengths to language features is locale dependent.
126*0e209d39SAndroid Build Coastguard Worker * For example, in Czech, "e" and "f" are considered primary differences,
127*0e209d39SAndroid Build Coastguard Worker * while "e" and "\u00EA" are secondary differences, "e" and "E" are tertiary
128*0e209d39SAndroid Build Coastguard Worker * differences and "e" and "e" are identical. The following shows how both case
129*0e209d39SAndroid Build Coastguard Worker * and accents could be ignored for US English.
130*0e209d39SAndroid Build Coastguard Worker * \htmlonly<blockquote>\endhtmlonly
131*0e209d39SAndroid Build Coastguard Worker * <pre>
132*0e209d39SAndroid Build Coastguard Worker * \code
133*0e209d39SAndroid Build Coastguard Worker * //Get the Collator for US English and set its strength to PRIMARY
134*0e209d39SAndroid Build Coastguard Worker * UErrorCode success = U_ZERO_ERROR;
135*0e209d39SAndroid Build Coastguard Worker * Collator* usCollator = Collator::createInstance(Locale::getUS(), success);
136*0e209d39SAndroid Build Coastguard Worker * usCollator->setStrength(Collator::PRIMARY);
137*0e209d39SAndroid Build Coastguard Worker * if (usCollator->compare("abc", "ABC") == 0)
138*0e209d39SAndroid Build Coastguard Worker *     cout << "'abc' and 'ABC' strings are equivalent with strength PRIMARY" << endl;
139*0e209d39SAndroid Build Coastguard Worker * \endcode
140*0e209d39SAndroid Build Coastguard Worker * </pre>
141*0e209d39SAndroid Build Coastguard Worker * \htmlonly</blockquote>\endhtmlonly
142*0e209d39SAndroid Build Coastguard Worker *
143*0e209d39SAndroid Build Coastguard Worker * The <code>getSortKey</code> methods
144*0e209d39SAndroid Build Coastguard Worker * convert a string to a series of bytes that can be compared bitwise against
145*0e209d39SAndroid Build Coastguard Worker * other sort keys using <code>strcmp()</code>. Sort keys are written as
146*0e209d39SAndroid Build Coastguard Worker * zero-terminated byte strings.
147*0e209d39SAndroid Build Coastguard Worker *
148*0e209d39SAndroid Build Coastguard Worker * Another set of APIs returns a <code>CollationKey</code> object that wraps
149*0e209d39SAndroid Build Coastguard Worker * the sort key bytes instead of returning the bytes themselves.
150*0e209d39SAndroid Build Coastguard Worker * </p>
151*0e209d39SAndroid Build Coastguard Worker * <p>
152*0e209d39SAndroid Build Coastguard Worker * <strong>Note:</strong> <code>Collator</code>s with different Locale,
153*0e209d39SAndroid Build Coastguard Worker * and CollationStrength settings will return different sort
154*0e209d39SAndroid Build Coastguard Worker * orders for the same set of strings. Locales have specific collation rules,
155*0e209d39SAndroid Build Coastguard Worker * and the way in which secondary and tertiary differences are taken into
156*0e209d39SAndroid Build Coastguard Worker * account, for example, will result in a different sorting order for same
157*0e209d39SAndroid Build Coastguard Worker * strings.
158*0e209d39SAndroid Build Coastguard Worker * </p>
159*0e209d39SAndroid Build Coastguard Worker * @see         RuleBasedCollator
160*0e209d39SAndroid Build Coastguard Worker * @see         CollationKey
161*0e209d39SAndroid Build Coastguard Worker * @see         CollationElementIterator
162*0e209d39SAndroid Build Coastguard Worker * @see         Locale
163*0e209d39SAndroid Build Coastguard Worker * @see         Normalizer2
164*0e209d39SAndroid Build Coastguard Worker * @version     2.0 11/15/01
165*0e209d39SAndroid Build Coastguard Worker */
166*0e209d39SAndroid Build Coastguard Worker 
167*0e209d39SAndroid Build Coastguard Worker class U_I18N_API Collator : public UObject {
168*0e209d39SAndroid Build Coastguard Worker public:
169*0e209d39SAndroid Build Coastguard Worker 
170*0e209d39SAndroid Build Coastguard Worker     // Collator public enums -----------------------------------------------
171*0e209d39SAndroid Build Coastguard Worker 
172*0e209d39SAndroid Build Coastguard Worker     /**
173*0e209d39SAndroid Build Coastguard Worker      * Base letter represents a primary difference. Set comparison level to
174*0e209d39SAndroid Build Coastguard Worker      * PRIMARY to ignore secondary and tertiary differences.<br>
175*0e209d39SAndroid Build Coastguard Worker      * Use this to set the strength of a Collator object.<br>
176*0e209d39SAndroid Build Coastguard Worker      * Example of primary difference, "abc" &lt; "abd"
177*0e209d39SAndroid Build Coastguard Worker      *
178*0e209d39SAndroid Build Coastguard Worker      * Diacritical differences on the same base letter represent a secondary
179*0e209d39SAndroid Build Coastguard Worker      * difference. Set comparison level to SECONDARY to ignore tertiary
180*0e209d39SAndroid Build Coastguard Worker      * differences. Use this to set the strength of a Collator object.<br>
181*0e209d39SAndroid Build Coastguard Worker      * Example of secondary difference, "&auml;" >> "a".
182*0e209d39SAndroid Build Coastguard Worker      *
183*0e209d39SAndroid Build Coastguard Worker      * Uppercase and lowercase versions of the same character represents a
184*0e209d39SAndroid Build Coastguard Worker      * tertiary difference.  Set comparison level to TERTIARY to include all
185*0e209d39SAndroid Build Coastguard Worker      * comparison differences. Use this to set the strength of a Collator
186*0e209d39SAndroid Build Coastguard Worker      * object.<br>
187*0e209d39SAndroid Build Coastguard Worker      * Example of tertiary difference, "abc" &lt;&lt;&lt; "ABC".
188*0e209d39SAndroid Build Coastguard Worker      *
189*0e209d39SAndroid Build Coastguard Worker      * Two characters are considered "identical" when they have the same unicode
190*0e209d39SAndroid Build Coastguard Worker      * spellings.<br>
191*0e209d39SAndroid Build Coastguard Worker      * For example, "&auml;" == "&auml;".
192*0e209d39SAndroid Build Coastguard Worker      *
193*0e209d39SAndroid Build Coastguard Worker      * UCollationStrength is also used to determine the strength of sort keys
194*0e209d39SAndroid Build Coastguard Worker      * generated from Collator objects.
195*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
196*0e209d39SAndroid Build Coastguard Worker      */
197*0e209d39SAndroid Build Coastguard Worker     enum ECollationStrength
198*0e209d39SAndroid Build Coastguard Worker     {
199*0e209d39SAndroid Build Coastguard Worker         PRIMARY    = UCOL_PRIMARY,  // 0
200*0e209d39SAndroid Build Coastguard Worker         SECONDARY  = UCOL_SECONDARY,  // 1
201*0e209d39SAndroid Build Coastguard Worker         TERTIARY   = UCOL_TERTIARY,  // 2
202*0e209d39SAndroid Build Coastguard Worker         QUATERNARY = UCOL_QUATERNARY,  // 3
203*0e209d39SAndroid Build Coastguard Worker         IDENTICAL  = UCOL_IDENTICAL  // 15
204*0e209d39SAndroid Build Coastguard Worker     };
205*0e209d39SAndroid Build Coastguard Worker 
206*0e209d39SAndroid Build Coastguard Worker 
207*0e209d39SAndroid Build Coastguard Worker     // Cannot use #ifndef U_HIDE_DEPRECATED_API for the following, it is
208*0e209d39SAndroid Build Coastguard Worker     // used by virtual methods that cannot have that conditional.
209*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
210*0e209d39SAndroid Build Coastguard Worker     /**
211*0e209d39SAndroid Build Coastguard Worker      * LESS is returned if source string is compared to be less than target
212*0e209d39SAndroid Build Coastguard Worker      * string in the compare() method.
213*0e209d39SAndroid Build Coastguard Worker      * EQUAL is returned if source string is compared to be equal to target
214*0e209d39SAndroid Build Coastguard Worker      * string in the compare() method.
215*0e209d39SAndroid Build Coastguard Worker      * GREATER is returned if source string is compared to be greater than
216*0e209d39SAndroid Build Coastguard Worker      * target string in the compare() method.
217*0e209d39SAndroid Build Coastguard Worker      * @see Collator#compare
218*0e209d39SAndroid Build Coastguard Worker      * @deprecated ICU 2.6. Use C enum UCollationResult defined in ucol.h
219*0e209d39SAndroid Build Coastguard Worker      */
220*0e209d39SAndroid Build Coastguard Worker     enum EComparisonResult
221*0e209d39SAndroid Build Coastguard Worker     {
222*0e209d39SAndroid Build Coastguard Worker         LESS = UCOL_LESS,  // -1
223*0e209d39SAndroid Build Coastguard Worker         EQUAL = UCOL_EQUAL,  // 0
224*0e209d39SAndroid Build Coastguard Worker         GREATER = UCOL_GREATER  // 1
225*0e209d39SAndroid Build Coastguard Worker     };
226*0e209d39SAndroid Build Coastguard Worker #endif  // U_FORCE_HIDE_DEPRECATED_API
227*0e209d39SAndroid Build Coastguard Worker 
228*0e209d39SAndroid Build Coastguard Worker     // Collator public destructor -----------------------------------------
229*0e209d39SAndroid Build Coastguard Worker 
230*0e209d39SAndroid Build Coastguard Worker     /**
231*0e209d39SAndroid Build Coastguard Worker      * Destructor
232*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
233*0e209d39SAndroid Build Coastguard Worker      */
234*0e209d39SAndroid Build Coastguard Worker     virtual ~Collator();
235*0e209d39SAndroid Build Coastguard Worker 
236*0e209d39SAndroid Build Coastguard Worker     // Collator public methods --------------------------------------------
237*0e209d39SAndroid Build Coastguard Worker 
238*0e209d39SAndroid Build Coastguard Worker     /**
239*0e209d39SAndroid Build Coastguard Worker      * Returns true if "other" is the same as "this".
240*0e209d39SAndroid Build Coastguard Worker      *
241*0e209d39SAndroid Build Coastguard Worker      * The base class implementation returns true if "other" has the same type/class as "this":
242*0e209d39SAndroid Build Coastguard Worker      * `typeid(*this) == typeid(other)`.
243*0e209d39SAndroid Build Coastguard Worker      *
244*0e209d39SAndroid Build Coastguard Worker      * Subclass implementations should do something like the following:
245*0e209d39SAndroid Build Coastguard Worker      *
246*0e209d39SAndroid Build Coastguard Worker      *     if (this == &other) { return true; }
247*0e209d39SAndroid Build Coastguard Worker      *     if (!Collator::operator==(other)) { return false; }  // not the same class
248*0e209d39SAndroid Build Coastguard Worker      *
249*0e209d39SAndroid Build Coastguard Worker      *     const MyCollator &o = (const MyCollator&)other;
250*0e209d39SAndroid Build Coastguard Worker      *     (compare this vs. o's subclass fields)
251*0e209d39SAndroid Build Coastguard Worker      *
252*0e209d39SAndroid Build Coastguard Worker      * @param other Collator object to be compared
253*0e209d39SAndroid Build Coastguard Worker      * @return true if other is the same as this.
254*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
255*0e209d39SAndroid Build Coastguard Worker      */
256*0e209d39SAndroid Build Coastguard Worker     virtual bool operator==(const Collator& other) const;
257*0e209d39SAndroid Build Coastguard Worker 
258*0e209d39SAndroid Build Coastguard Worker     /**
259*0e209d39SAndroid Build Coastguard Worker      * Returns true if "other" is not the same as "this".
260*0e209d39SAndroid Build Coastguard Worker      * Calls ! operator==(const Collator&) const which works for all subclasses.
261*0e209d39SAndroid Build Coastguard Worker      * @param other Collator object to be compared
262*0e209d39SAndroid Build Coastguard Worker      * @return true if other is not the same as this.
263*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
264*0e209d39SAndroid Build Coastguard Worker      */
265*0e209d39SAndroid Build Coastguard Worker     virtual bool operator!=(const Collator& other) const;
266*0e209d39SAndroid Build Coastguard Worker 
267*0e209d39SAndroid Build Coastguard Worker     /**
268*0e209d39SAndroid Build Coastguard Worker      * Makes a copy of this object.
269*0e209d39SAndroid Build Coastguard Worker      * @return a copy of this object, owned by the caller
270*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
271*0e209d39SAndroid Build Coastguard Worker      */
272*0e209d39SAndroid Build Coastguard Worker     virtual Collator* clone() const = 0;
273*0e209d39SAndroid Build Coastguard Worker 
274*0e209d39SAndroid Build Coastguard Worker     /**
275*0e209d39SAndroid Build Coastguard Worker      * Creates the Collator object for the current default locale.
276*0e209d39SAndroid Build Coastguard Worker      * The default locale is determined by Locale::getDefault.
277*0e209d39SAndroid Build Coastguard Worker      * The UErrorCode& err parameter is used to return status information to the user.
278*0e209d39SAndroid Build Coastguard Worker      * To check whether the construction succeeded or not, you should check the
279*0e209d39SAndroid Build Coastguard Worker      * value of U_SUCCESS(err).  If you wish more detailed information, you can
280*0e209d39SAndroid Build Coastguard Worker      * check for informational error results which still indicate success.
281*0e209d39SAndroid Build Coastguard Worker      * U_USING_FALLBACK_ERROR indicates that a fall back locale was used. For
282*0e209d39SAndroid Build Coastguard Worker      * example, 'de_CH' was requested, but nothing was found there, so 'de' was
283*0e209d39SAndroid Build Coastguard Worker      * used. U_USING_DEFAULT_ERROR indicates that the default locale data was
284*0e209d39SAndroid Build Coastguard Worker      * used; neither the requested locale nor any of its fall back locales
285*0e209d39SAndroid Build Coastguard Worker      * could be found.
286*0e209d39SAndroid Build Coastguard Worker      * The caller owns the returned object and is responsible for deleting it.
287*0e209d39SAndroid Build Coastguard Worker      *
288*0e209d39SAndroid Build Coastguard Worker      * @param err    the error code status.
289*0e209d39SAndroid Build Coastguard Worker      * @return       the collation object of the default locale.(for example, en_US)
290*0e209d39SAndroid Build Coastguard Worker      * @see Locale#getDefault
291*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
292*0e209d39SAndroid Build Coastguard Worker      */
293*0e209d39SAndroid Build Coastguard Worker     static Collator* U_EXPORT2 createInstance(UErrorCode&  err);
294*0e209d39SAndroid Build Coastguard Worker 
295*0e209d39SAndroid Build Coastguard Worker     /**
296*0e209d39SAndroid Build Coastguard Worker      * Gets the collation object for the desired locale. The
297*0e209d39SAndroid Build Coastguard Worker      * resource of the desired locale will be loaded.
298*0e209d39SAndroid Build Coastguard Worker      *
299*0e209d39SAndroid Build Coastguard Worker      * Locale::getRoot() is the base collation table and all other languages are
300*0e209d39SAndroid Build Coastguard Worker      * built on top of it with additional language-specific modifications.
301*0e209d39SAndroid Build Coastguard Worker      *
302*0e209d39SAndroid Build Coastguard Worker      * For some languages, multiple collation types are available;
303*0e209d39SAndroid Build Coastguard Worker      * for example, "de@collation=phonebook".
304*0e209d39SAndroid Build Coastguard Worker      * Starting with ICU 54, collation attributes can be specified via locale keywords as well,
305*0e209d39SAndroid Build Coastguard Worker      * in the old locale extension syntax ("el@colCaseFirst=upper")
306*0e209d39SAndroid Build Coastguard Worker      * or in language tag syntax ("el-u-kf-upper").
307*0e209d39SAndroid Build Coastguard Worker      * See <a href="https://unicode-org.github.io/icu/userguide/collation/api">User Guide: Collation API</a>.
308*0e209d39SAndroid Build Coastguard Worker      *
309*0e209d39SAndroid Build Coastguard Worker      * The UErrorCode& err parameter is used to return status information to the user.
310*0e209d39SAndroid Build Coastguard Worker      * To check whether the construction succeeded or not, you should check
311*0e209d39SAndroid Build Coastguard Worker      * the value of U_SUCCESS(err).  If you wish more detailed information, you
312*0e209d39SAndroid Build Coastguard Worker      * can check for informational error results which still indicate success.
313*0e209d39SAndroid Build Coastguard Worker      * U_USING_FALLBACK_ERROR indicates that a fall back locale was used.  For
314*0e209d39SAndroid Build Coastguard Worker      * example, 'de_CH' was requested, but nothing was found there, so 'de' was
315*0e209d39SAndroid Build Coastguard Worker      * used.  U_USING_DEFAULT_ERROR indicates that the default locale data was
316*0e209d39SAndroid Build Coastguard Worker      * used; neither the requested locale nor any of its fall back locales
317*0e209d39SAndroid Build Coastguard Worker      * could be found.
318*0e209d39SAndroid Build Coastguard Worker      *
319*0e209d39SAndroid Build Coastguard Worker      * The caller owns the returned object and is responsible for deleting it.
320*0e209d39SAndroid Build Coastguard Worker      * @param loc    The locale ID for which to open a collator.
321*0e209d39SAndroid Build Coastguard Worker      * @param err    the error code status.
322*0e209d39SAndroid Build Coastguard Worker      * @return       the created table-based collation object based on the desired
323*0e209d39SAndroid Build Coastguard Worker      *               locale.
324*0e209d39SAndroid Build Coastguard Worker      * @see Locale
325*0e209d39SAndroid Build Coastguard Worker      * @see ResourceLoader
326*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.2
327*0e209d39SAndroid Build Coastguard Worker      */
328*0e209d39SAndroid Build Coastguard Worker     static Collator* U_EXPORT2 createInstance(const Locale& loc, UErrorCode& err);
329*0e209d39SAndroid Build Coastguard Worker 
330*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
331*0e209d39SAndroid Build Coastguard Worker     /**
332*0e209d39SAndroid Build Coastguard Worker      * The comparison function compares the character data stored in two
333*0e209d39SAndroid Build Coastguard Worker      * different strings. Returns information about whether a string is less
334*0e209d39SAndroid Build Coastguard Worker      * than, greater than or equal to another string.
335*0e209d39SAndroid Build Coastguard Worker      * @param source the source string to be compared with.
336*0e209d39SAndroid Build Coastguard Worker      * @param target the string that is to be compared with the source string.
337*0e209d39SAndroid Build Coastguard Worker      * @return Returns a byte value. GREATER if source is greater
338*0e209d39SAndroid Build Coastguard Worker      * than target; EQUAL if source is equal to target; LESS if source is less
339*0e209d39SAndroid Build Coastguard Worker      * than target
340*0e209d39SAndroid Build Coastguard Worker      * @deprecated ICU 2.6 use the overload with UErrorCode &
341*0e209d39SAndroid Build Coastguard Worker      */
342*0e209d39SAndroid Build Coastguard Worker     virtual EComparisonResult compare(const UnicodeString& source,
343*0e209d39SAndroid Build Coastguard Worker                                       const UnicodeString& target) const;
344*0e209d39SAndroid Build Coastguard Worker #endif  // U_FORCE_HIDE_DEPRECATED_API
345*0e209d39SAndroid Build Coastguard Worker 
346*0e209d39SAndroid Build Coastguard Worker     /**
347*0e209d39SAndroid Build Coastguard Worker      * The comparison function compares the character data stored in two
348*0e209d39SAndroid Build Coastguard Worker      * different strings. Returns information about whether a string is less
349*0e209d39SAndroid Build Coastguard Worker      * than, greater than or equal to another string.
350*0e209d39SAndroid Build Coastguard Worker      * @param source the source string to be compared with.
351*0e209d39SAndroid Build Coastguard Worker      * @param target the string that is to be compared with the source string.
352*0e209d39SAndroid Build Coastguard Worker      * @param status possible error code
353*0e209d39SAndroid Build Coastguard Worker      * @return Returns an enum value. UCOL_GREATER if source is greater
354*0e209d39SAndroid Build Coastguard Worker      * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source is less
355*0e209d39SAndroid Build Coastguard Worker      * than target
356*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.6
357*0e209d39SAndroid Build Coastguard Worker      */
358*0e209d39SAndroid Build Coastguard Worker     virtual UCollationResult compare(const UnicodeString& source,
359*0e209d39SAndroid Build Coastguard Worker                                       const UnicodeString& target,
360*0e209d39SAndroid Build Coastguard Worker                                       UErrorCode &status) const = 0;
361*0e209d39SAndroid Build Coastguard Worker 
362*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
363*0e209d39SAndroid Build Coastguard Worker     /**
364*0e209d39SAndroid Build Coastguard Worker      * Does the same thing as compare but limits the comparison to a specified
365*0e209d39SAndroid Build Coastguard Worker      * length
366*0e209d39SAndroid Build Coastguard Worker      * @param source the source string to be compared with.
367*0e209d39SAndroid Build Coastguard Worker      * @param target the string that is to be compared with the source string.
368*0e209d39SAndroid Build Coastguard Worker      * @param length the length the comparison is limited to
369*0e209d39SAndroid Build Coastguard Worker      * @return Returns a byte value. GREATER if source (up to the specified
370*0e209d39SAndroid Build Coastguard Worker      *         length) is greater than target; EQUAL if source (up to specified
371*0e209d39SAndroid Build Coastguard Worker      *         length) is equal to target; LESS if source (up to the specified
372*0e209d39SAndroid Build Coastguard Worker      *         length) is less  than target.
373*0e209d39SAndroid Build Coastguard Worker      * @deprecated ICU 2.6 use the overload with UErrorCode &
374*0e209d39SAndroid Build Coastguard Worker      */
375*0e209d39SAndroid Build Coastguard Worker     virtual EComparisonResult compare(const UnicodeString& source,
376*0e209d39SAndroid Build Coastguard Worker                                       const UnicodeString& target,
377*0e209d39SAndroid Build Coastguard Worker                                       int32_t length) const;
378*0e209d39SAndroid Build Coastguard Worker #endif  // U_FORCE_HIDE_DEPRECATED_API
379*0e209d39SAndroid Build Coastguard Worker 
380*0e209d39SAndroid Build Coastguard Worker     /**
381*0e209d39SAndroid Build Coastguard Worker      * Does the same thing as compare but limits the comparison to a specified
382*0e209d39SAndroid Build Coastguard Worker      * length
383*0e209d39SAndroid Build Coastguard Worker      * @param source the source string to be compared with.
384*0e209d39SAndroid Build Coastguard Worker      * @param target the string that is to be compared with the source string.
385*0e209d39SAndroid Build Coastguard Worker      * @param length the length the comparison is limited to
386*0e209d39SAndroid Build Coastguard Worker      * @param status possible error code
387*0e209d39SAndroid Build Coastguard Worker      * @return Returns an enum value. UCOL_GREATER if source (up to the specified
388*0e209d39SAndroid Build Coastguard Worker      *         length) is greater than target; UCOL_EQUAL if source (up to specified
389*0e209d39SAndroid Build Coastguard Worker      *         length) is equal to target; UCOL_LESS if source (up to the specified
390*0e209d39SAndroid Build Coastguard Worker      *         length) is less  than target.
391*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.6
392*0e209d39SAndroid Build Coastguard Worker      */
393*0e209d39SAndroid Build Coastguard Worker     virtual UCollationResult compare(const UnicodeString& source,
394*0e209d39SAndroid Build Coastguard Worker                                       const UnicodeString& target,
395*0e209d39SAndroid Build Coastguard Worker                                       int32_t length,
396*0e209d39SAndroid Build Coastguard Worker                                       UErrorCode &status) const = 0;
397*0e209d39SAndroid Build Coastguard Worker 
398*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
399*0e209d39SAndroid Build Coastguard Worker     /**
400*0e209d39SAndroid Build Coastguard Worker      * The comparison function compares the character data stored in two
401*0e209d39SAndroid Build Coastguard Worker      * different string arrays. Returns information about whether a string array
402*0e209d39SAndroid Build Coastguard Worker      * is less than, greater than or equal to another string array.
403*0e209d39SAndroid Build Coastguard Worker      * <p>Example of use:
404*0e209d39SAndroid Build Coastguard Worker      * <pre>
405*0e209d39SAndroid Build Coastguard Worker      * .       char16_t ABC[] = {0x41, 0x42, 0x43, 0};  // = "ABC"
406*0e209d39SAndroid Build Coastguard Worker      * .       char16_t abc[] = {0x61, 0x62, 0x63, 0};  // = "abc"
407*0e209d39SAndroid Build Coastguard Worker      * .       UErrorCode status = U_ZERO_ERROR;
408*0e209d39SAndroid Build Coastguard Worker      * .       Collator *myCollation =
409*0e209d39SAndroid Build Coastguard Worker      * .                         Collator::createInstance(Locale::getUS(), status);
410*0e209d39SAndroid Build Coastguard Worker      * .       if (U_FAILURE(status)) return;
411*0e209d39SAndroid Build Coastguard Worker      * .       myCollation->setStrength(Collator::PRIMARY);
412*0e209d39SAndroid Build Coastguard Worker      * .       // result would be Collator::EQUAL ("abc" == "ABC")
413*0e209d39SAndroid Build Coastguard Worker      * .       // (no primary difference between "abc" and "ABC")
414*0e209d39SAndroid Build Coastguard Worker      * .       Collator::EComparisonResult result =
415*0e209d39SAndroid Build Coastguard Worker      * .                             myCollation->compare(abc, 3, ABC, 3);
416*0e209d39SAndroid Build Coastguard Worker      * .       myCollation->setStrength(Collator::TERTIARY);
417*0e209d39SAndroid Build Coastguard Worker      * .       // result would be Collator::LESS ("abc" &lt;&lt;&lt; "ABC")
418*0e209d39SAndroid Build Coastguard Worker      * .       // (with tertiary difference between "abc" and "ABC")
419*0e209d39SAndroid Build Coastguard Worker      * .       result = myCollation->compare(abc, 3, ABC, 3);
420*0e209d39SAndroid Build Coastguard Worker      * </pre>
421*0e209d39SAndroid Build Coastguard Worker      * @param source the source string array to be compared with.
422*0e209d39SAndroid Build Coastguard Worker      * @param sourceLength the length of the source string array.  If this value
423*0e209d39SAndroid Build Coastguard Worker      *        is equal to -1, the string array is null-terminated.
424*0e209d39SAndroid Build Coastguard Worker      * @param target the string that is to be compared with the source string.
425*0e209d39SAndroid Build Coastguard Worker      * @param targetLength the length of the target string array.  If this value
426*0e209d39SAndroid Build Coastguard Worker      *        is equal to -1, the string array is null-terminated.
427*0e209d39SAndroid Build Coastguard Worker      * @return Returns a byte value. GREATER if source is greater than target;
428*0e209d39SAndroid Build Coastguard Worker      *         EQUAL if source is equal to target; LESS if source is less than
429*0e209d39SAndroid Build Coastguard Worker      *         target
430*0e209d39SAndroid Build Coastguard Worker      * @deprecated ICU 2.6 use the overload with UErrorCode &
431*0e209d39SAndroid Build Coastguard Worker      */
432*0e209d39SAndroid Build Coastguard Worker     virtual EComparisonResult compare(const char16_t* source, int32_t sourceLength,
433*0e209d39SAndroid Build Coastguard Worker                                       const char16_t* target, int32_t targetLength)
434*0e209d39SAndroid Build Coastguard Worker                                       const;
435*0e209d39SAndroid Build Coastguard Worker #endif  // U_FORCE_HIDE_DEPRECATED_API
436*0e209d39SAndroid Build Coastguard Worker 
437*0e209d39SAndroid Build Coastguard Worker     /**
438*0e209d39SAndroid Build Coastguard Worker      * The comparison function compares the character data stored in two
439*0e209d39SAndroid Build Coastguard Worker      * different string arrays. Returns information about whether a string array
440*0e209d39SAndroid Build Coastguard Worker      * is less than, greater than or equal to another string array.
441*0e209d39SAndroid Build Coastguard Worker      * @param source the source string array to be compared with.
442*0e209d39SAndroid Build Coastguard Worker      * @param sourceLength the length of the source string array.  If this value
443*0e209d39SAndroid Build Coastguard Worker      *        is equal to -1, the string array is null-terminated.
444*0e209d39SAndroid Build Coastguard Worker      * @param target the string that is to be compared with the source string.
445*0e209d39SAndroid Build Coastguard Worker      * @param targetLength the length of the target string array.  If this value
446*0e209d39SAndroid Build Coastguard Worker      *        is equal to -1, the string array is null-terminated.
447*0e209d39SAndroid Build Coastguard Worker      * @param status possible error code
448*0e209d39SAndroid Build Coastguard Worker      * @return Returns an enum value. UCOL_GREATER if source is greater
449*0e209d39SAndroid Build Coastguard Worker      * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source is less
450*0e209d39SAndroid Build Coastguard Worker      * than target
451*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.6
452*0e209d39SAndroid Build Coastguard Worker      */
453*0e209d39SAndroid Build Coastguard Worker     virtual UCollationResult compare(const char16_t* source, int32_t sourceLength,
454*0e209d39SAndroid Build Coastguard Worker                                       const char16_t* target, int32_t targetLength,
455*0e209d39SAndroid Build Coastguard Worker                                       UErrorCode &status) const = 0;
456*0e209d39SAndroid Build Coastguard Worker 
457*0e209d39SAndroid Build Coastguard Worker     /**
458*0e209d39SAndroid Build Coastguard Worker      * Compares two strings using the Collator.
459*0e209d39SAndroid Build Coastguard Worker      * Returns whether the first one compares less than/equal to/greater than
460*0e209d39SAndroid Build Coastguard Worker      * the second one.
461*0e209d39SAndroid Build Coastguard Worker      * This version takes UCharIterator input.
462*0e209d39SAndroid Build Coastguard Worker      * @param sIter the first ("source") string iterator
463*0e209d39SAndroid Build Coastguard Worker      * @param tIter the second ("target") string iterator
464*0e209d39SAndroid Build Coastguard Worker      * @param status ICU status
465*0e209d39SAndroid Build Coastguard Worker      * @return UCOL_LESS, UCOL_EQUAL or UCOL_GREATER
466*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.2
467*0e209d39SAndroid Build Coastguard Worker      */
468*0e209d39SAndroid Build Coastguard Worker     virtual UCollationResult compare(UCharIterator &sIter,
469*0e209d39SAndroid Build Coastguard Worker                                      UCharIterator &tIter,
470*0e209d39SAndroid Build Coastguard Worker                                      UErrorCode &status) const;
471*0e209d39SAndroid Build Coastguard Worker 
472*0e209d39SAndroid Build Coastguard Worker     /**
473*0e209d39SAndroid Build Coastguard Worker      * Compares two UTF-8 strings using the Collator.
474*0e209d39SAndroid Build Coastguard Worker      * Returns whether the first one compares less than/equal to/greater than
475*0e209d39SAndroid Build Coastguard Worker      * the second one.
476*0e209d39SAndroid Build Coastguard Worker      * This version takes UTF-8 input.
477*0e209d39SAndroid Build Coastguard Worker      * Note that a StringPiece can be implicitly constructed
478*0e209d39SAndroid Build Coastguard Worker      * from a std::string or a NUL-terminated const char * string.
479*0e209d39SAndroid Build Coastguard Worker      * @param source the first UTF-8 string
480*0e209d39SAndroid Build Coastguard Worker      * @param target the second UTF-8 string
481*0e209d39SAndroid Build Coastguard Worker      * @param status ICU status
482*0e209d39SAndroid Build Coastguard Worker      * @return UCOL_LESS, UCOL_EQUAL or UCOL_GREATER
483*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.2
484*0e209d39SAndroid Build Coastguard Worker      */
485*0e209d39SAndroid Build Coastguard Worker     virtual UCollationResult compareUTF8(const StringPiece &source,
486*0e209d39SAndroid Build Coastguard Worker                                          const StringPiece &target,
487*0e209d39SAndroid Build Coastguard Worker                                          UErrorCode &status) const;
488*0e209d39SAndroid Build Coastguard Worker 
489*0e209d39SAndroid Build Coastguard Worker     /**
490*0e209d39SAndroid Build Coastguard Worker      * Transforms the string into a series of characters that can be compared
491*0e209d39SAndroid Build Coastguard Worker      * with CollationKey::compareTo. It is not possible to restore the original
492*0e209d39SAndroid Build Coastguard Worker      * string from the chars in the sort key.
493*0e209d39SAndroid Build Coastguard Worker      * <p>Use CollationKey::equals or CollationKey::compare to compare the
494*0e209d39SAndroid Build Coastguard Worker      * generated sort keys.
495*0e209d39SAndroid Build Coastguard Worker      * If the source string is null, a null collation key will be returned.
496*0e209d39SAndroid Build Coastguard Worker      *
497*0e209d39SAndroid Build Coastguard Worker      * Note that sort keys are often less efficient than simply doing comparison.
498*0e209d39SAndroid Build Coastguard Worker      * For more details, see the ICU User Guide.
499*0e209d39SAndroid Build Coastguard Worker      *
500*0e209d39SAndroid Build Coastguard Worker      * @param source the source string to be transformed into a sort key.
501*0e209d39SAndroid Build Coastguard Worker      * @param key the collation key to be filled in
502*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
503*0e209d39SAndroid Build Coastguard Worker      * @return the collation key of the string based on the collation rules.
504*0e209d39SAndroid Build Coastguard Worker      * @see CollationKey#compare
505*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
506*0e209d39SAndroid Build Coastguard Worker      */
507*0e209d39SAndroid Build Coastguard Worker     virtual CollationKey& getCollationKey(const UnicodeString&  source,
508*0e209d39SAndroid Build Coastguard Worker                                           CollationKey& key,
509*0e209d39SAndroid Build Coastguard Worker                                           UErrorCode& status) const = 0;
510*0e209d39SAndroid Build Coastguard Worker 
511*0e209d39SAndroid Build Coastguard Worker     /**
512*0e209d39SAndroid Build Coastguard Worker      * Transforms the string into a series of characters that can be compared
513*0e209d39SAndroid Build Coastguard Worker      * with CollationKey::compareTo. It is not possible to restore the original
514*0e209d39SAndroid Build Coastguard Worker      * string from the chars in the sort key.
515*0e209d39SAndroid Build Coastguard Worker      * <p>Use CollationKey::equals or CollationKey::compare to compare the
516*0e209d39SAndroid Build Coastguard Worker      * generated sort keys.
517*0e209d39SAndroid Build Coastguard Worker      * <p>If the source string is null, a null collation key will be returned.
518*0e209d39SAndroid Build Coastguard Worker      *
519*0e209d39SAndroid Build Coastguard Worker      * Note that sort keys are often less efficient than simply doing comparison.
520*0e209d39SAndroid Build Coastguard Worker      * For more details, see the ICU User Guide.
521*0e209d39SAndroid Build Coastguard Worker      *
522*0e209d39SAndroid Build Coastguard Worker      * @param source the source string to be transformed into a sort key.
523*0e209d39SAndroid Build Coastguard Worker      * @param sourceLength length of the collation key
524*0e209d39SAndroid Build Coastguard Worker      * @param key the collation key to be filled in
525*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
526*0e209d39SAndroid Build Coastguard Worker      * @return the collation key of the string based on the collation rules.
527*0e209d39SAndroid Build Coastguard Worker      * @see CollationKey#compare
528*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
529*0e209d39SAndroid Build Coastguard Worker      */
530*0e209d39SAndroid Build Coastguard Worker     virtual CollationKey& getCollationKey(const char16_t*source,
531*0e209d39SAndroid Build Coastguard Worker                                           int32_t sourceLength,
532*0e209d39SAndroid Build Coastguard Worker                                           CollationKey& key,
533*0e209d39SAndroid Build Coastguard Worker                                           UErrorCode& status) const = 0;
534*0e209d39SAndroid Build Coastguard Worker     /**
535*0e209d39SAndroid Build Coastguard Worker      * Generates the hash code for the collation object
536*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
537*0e209d39SAndroid Build Coastguard Worker      */
538*0e209d39SAndroid Build Coastguard Worker     virtual int32_t hashCode() const = 0;
539*0e209d39SAndroid Build Coastguard Worker 
540*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
541*0e209d39SAndroid Build Coastguard Worker     /**
542*0e209d39SAndroid Build Coastguard Worker      * Gets the locale of the Collator
543*0e209d39SAndroid Build Coastguard Worker      *
544*0e209d39SAndroid Build Coastguard Worker      * @param type can be either requested, valid or actual locale. For more
545*0e209d39SAndroid Build Coastguard Worker      *             information see the definition of ULocDataLocaleType in
546*0e209d39SAndroid Build Coastguard Worker      *             uloc.h
547*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
548*0e209d39SAndroid Build Coastguard Worker      * @return locale where the collation data lives. If the collator
549*0e209d39SAndroid Build Coastguard Worker      *         was instantiated from rules, locale is empty.
550*0e209d39SAndroid Build Coastguard Worker      * @deprecated ICU 2.8 This API is under consideration for revision
551*0e209d39SAndroid Build Coastguard Worker      * in ICU 3.0.
552*0e209d39SAndroid Build Coastguard Worker      */
553*0e209d39SAndroid Build Coastguard Worker     virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0;
554*0e209d39SAndroid Build Coastguard Worker #endif  // U_FORCE_HIDE_DEPRECATED_API
555*0e209d39SAndroid Build Coastguard Worker 
556*0e209d39SAndroid Build Coastguard Worker     /**
557*0e209d39SAndroid Build Coastguard Worker      * Convenience method for comparing two strings based on the collation rules.
558*0e209d39SAndroid Build Coastguard Worker      * @param source the source string to be compared with.
559*0e209d39SAndroid Build Coastguard Worker      * @param target the target string to be compared with.
560*0e209d39SAndroid Build Coastguard Worker      * @return true if the first string is greater than the second one,
561*0e209d39SAndroid Build Coastguard Worker      *         according to the collation rules. false, otherwise.
562*0e209d39SAndroid Build Coastguard Worker      * @see Collator#compare
563*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
564*0e209d39SAndroid Build Coastguard Worker      */
565*0e209d39SAndroid Build Coastguard Worker     UBool greater(const UnicodeString& source, const UnicodeString& target)
566*0e209d39SAndroid Build Coastguard Worker                   const;
567*0e209d39SAndroid Build Coastguard Worker 
568*0e209d39SAndroid Build Coastguard Worker     /**
569*0e209d39SAndroid Build Coastguard Worker      * Convenience method for comparing two strings based on the collation rules.
570*0e209d39SAndroid Build Coastguard Worker      * @param source the source string to be compared with.
571*0e209d39SAndroid Build Coastguard Worker      * @param target the target string to be compared with.
572*0e209d39SAndroid Build Coastguard Worker      * @return true if the first string is greater than or equal to the second
573*0e209d39SAndroid Build Coastguard Worker      *         one, according to the collation rules. false, otherwise.
574*0e209d39SAndroid Build Coastguard Worker      * @see Collator#compare
575*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
576*0e209d39SAndroid Build Coastguard Worker      */
577*0e209d39SAndroid Build Coastguard Worker     UBool greaterOrEqual(const UnicodeString& source,
578*0e209d39SAndroid Build Coastguard Worker                          const UnicodeString& target) const;
579*0e209d39SAndroid Build Coastguard Worker 
580*0e209d39SAndroid Build Coastguard Worker     /**
581*0e209d39SAndroid Build Coastguard Worker      * Convenience method for comparing two strings based on the collation rules.
582*0e209d39SAndroid Build Coastguard Worker      * @param source the source string to be compared with.
583*0e209d39SAndroid Build Coastguard Worker      * @param target the target string to be compared with.
584*0e209d39SAndroid Build Coastguard Worker      * @return true if the strings are equal according to the collation rules.
585*0e209d39SAndroid Build Coastguard Worker      *         false, otherwise.
586*0e209d39SAndroid Build Coastguard Worker      * @see Collator#compare
587*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
588*0e209d39SAndroid Build Coastguard Worker      */
589*0e209d39SAndroid Build Coastguard Worker     UBool equals(const UnicodeString& source, const UnicodeString& target) const;
590*0e209d39SAndroid Build Coastguard Worker 
591*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
592*0e209d39SAndroid Build Coastguard Worker     /**
593*0e209d39SAndroid Build Coastguard Worker      * Determines the minimum strength that will be used in comparison or
594*0e209d39SAndroid Build Coastguard Worker      * transformation.
595*0e209d39SAndroid Build Coastguard Worker      * <p>E.g. with strength == SECONDARY, the tertiary difference is ignored
596*0e209d39SAndroid Build Coastguard Worker      * <p>E.g. with strength == PRIMARY, the secondary and tertiary difference
597*0e209d39SAndroid Build Coastguard Worker      * are ignored.
598*0e209d39SAndroid Build Coastguard Worker      * @return the current comparison level.
599*0e209d39SAndroid Build Coastguard Worker      * @see Collator#setStrength
600*0e209d39SAndroid Build Coastguard Worker      * @deprecated ICU 2.6 Use getAttribute(UCOL_STRENGTH...) instead
601*0e209d39SAndroid Build Coastguard Worker      */
602*0e209d39SAndroid Build Coastguard Worker     virtual ECollationStrength getStrength() const;
603*0e209d39SAndroid Build Coastguard Worker 
604*0e209d39SAndroid Build Coastguard Worker     /**
605*0e209d39SAndroid Build Coastguard Worker      * Sets the minimum strength to be used in comparison or transformation.
606*0e209d39SAndroid Build Coastguard Worker      * <p>Example of use:
607*0e209d39SAndroid Build Coastguard Worker      * <pre>
608*0e209d39SAndroid Build Coastguard Worker      *  \code
609*0e209d39SAndroid Build Coastguard Worker      *  UErrorCode status = U_ZERO_ERROR;
610*0e209d39SAndroid Build Coastguard Worker      *  Collator*myCollation = Collator::createInstance(Locale::getUS(), status);
611*0e209d39SAndroid Build Coastguard Worker      *  if (U_FAILURE(status)) return;
612*0e209d39SAndroid Build Coastguard Worker      *  myCollation->setStrength(Collator::PRIMARY);
613*0e209d39SAndroid Build Coastguard Worker      *  // result will be "abc" == "ABC"
614*0e209d39SAndroid Build Coastguard Worker      *  // tertiary differences will be ignored
615*0e209d39SAndroid Build Coastguard Worker      *  Collator::ComparisonResult result = myCollation->compare("abc", "ABC");
616*0e209d39SAndroid Build Coastguard Worker      * \endcode
617*0e209d39SAndroid Build Coastguard Worker      * </pre>
618*0e209d39SAndroid Build Coastguard Worker      * @see Collator#getStrength
619*0e209d39SAndroid Build Coastguard Worker      * @param newStrength the new comparison level.
620*0e209d39SAndroid Build Coastguard Worker      * @deprecated ICU 2.6 Use setAttribute(UCOL_STRENGTH...) instead
621*0e209d39SAndroid Build Coastguard Worker      */
622*0e209d39SAndroid Build Coastguard Worker     virtual void setStrength(ECollationStrength newStrength);
623*0e209d39SAndroid Build Coastguard Worker #endif  // U_FORCE_HIDE_DEPRECATED_API
624*0e209d39SAndroid Build Coastguard Worker 
625*0e209d39SAndroid Build Coastguard Worker     /**
626*0e209d39SAndroid Build Coastguard Worker      * Retrieves the reordering codes for this collator.
627*0e209d39SAndroid Build Coastguard Worker      * @param dest The array to fill with the script ordering.
628*0e209d39SAndroid Build Coastguard Worker      * @param destCapacity The length of dest. If it is 0, then dest may be nullptr and the function
629*0e209d39SAndroid Build Coastguard Worker      *  will only return the length of the result without writing any codes (pre-flighting).
630*0e209d39SAndroid Build Coastguard Worker      * @param status A reference to an error code value, which must not indicate
631*0e209d39SAndroid Build Coastguard Worker      * a failure before the function call.
632*0e209d39SAndroid Build Coastguard Worker      * @return The length of the script ordering array.
633*0e209d39SAndroid Build Coastguard Worker      * @see ucol_setReorderCodes
634*0e209d39SAndroid Build Coastguard Worker      * @see Collator#getEquivalentReorderCodes
635*0e209d39SAndroid Build Coastguard Worker      * @see Collator#setReorderCodes
636*0e209d39SAndroid Build Coastguard Worker      * @see UScriptCode
637*0e209d39SAndroid Build Coastguard Worker      * @see UColReorderCode
638*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
639*0e209d39SAndroid Build Coastguard Worker      */
640*0e209d39SAndroid Build Coastguard Worker      virtual int32_t getReorderCodes(int32_t *dest,
641*0e209d39SAndroid Build Coastguard Worker                                      int32_t destCapacity,
642*0e209d39SAndroid Build Coastguard Worker                                      UErrorCode& status) const;
643*0e209d39SAndroid Build Coastguard Worker 
644*0e209d39SAndroid Build Coastguard Worker     /**
645*0e209d39SAndroid Build Coastguard Worker      * Sets the ordering of scripts for this collator.
646*0e209d39SAndroid Build Coastguard Worker      *
647*0e209d39SAndroid Build Coastguard Worker      * <p>The reordering codes are a combination of script codes and reorder codes.
648*0e209d39SAndroid Build Coastguard Worker      * @param reorderCodes An array of script codes in the new order. This can be nullptr if the
649*0e209d39SAndroid Build Coastguard Worker      * length is also set to 0. An empty array will clear any reordering codes on the collator.
650*0e209d39SAndroid Build Coastguard Worker      * @param reorderCodesLength The length of reorderCodes.
651*0e209d39SAndroid Build Coastguard Worker      * @param status error code
652*0e209d39SAndroid Build Coastguard Worker      * @see ucol_setReorderCodes
653*0e209d39SAndroid Build Coastguard Worker      * @see Collator#getReorderCodes
654*0e209d39SAndroid Build Coastguard Worker      * @see Collator#getEquivalentReorderCodes
655*0e209d39SAndroid Build Coastguard Worker      * @see UScriptCode
656*0e209d39SAndroid Build Coastguard Worker      * @see UColReorderCode
657*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
658*0e209d39SAndroid Build Coastguard Worker      */
659*0e209d39SAndroid Build Coastguard Worker      virtual void setReorderCodes(const int32_t* reorderCodes,
660*0e209d39SAndroid Build Coastguard Worker                                   int32_t reorderCodesLength,
661*0e209d39SAndroid Build Coastguard Worker                                   UErrorCode& status) ;
662*0e209d39SAndroid Build Coastguard Worker 
663*0e209d39SAndroid Build Coastguard Worker     /**
664*0e209d39SAndroid Build Coastguard Worker      * Retrieves the reorder codes that are grouped with the given reorder code. Some reorder
665*0e209d39SAndroid Build Coastguard Worker      * codes will be grouped and must reorder together.
666*0e209d39SAndroid Build Coastguard Worker      * Beginning with ICU 55, scripts only reorder together if they are primary-equal,
667*0e209d39SAndroid Build Coastguard Worker      * for example Hiragana and Katakana.
668*0e209d39SAndroid Build Coastguard Worker      *
669*0e209d39SAndroid Build Coastguard Worker      * @param reorderCode The reorder code to determine equivalence for.
670*0e209d39SAndroid Build Coastguard Worker      * @param dest The array to fill with the script equivalence reordering codes.
671*0e209d39SAndroid Build Coastguard Worker      * @param destCapacity The length of dest. If it is 0, then dest may be nullptr and the
672*0e209d39SAndroid Build Coastguard Worker      * function will only return the length of the result without writing any codes (pre-flighting).
673*0e209d39SAndroid Build Coastguard Worker      * @param status A reference to an error code value, which must not indicate
674*0e209d39SAndroid Build Coastguard Worker      * a failure before the function call.
675*0e209d39SAndroid Build Coastguard Worker      * @return The length of the of the reordering code equivalence array.
676*0e209d39SAndroid Build Coastguard Worker      * @see ucol_setReorderCodes
677*0e209d39SAndroid Build Coastguard Worker      * @see Collator#getReorderCodes
678*0e209d39SAndroid Build Coastguard Worker      * @see Collator#setReorderCodes
679*0e209d39SAndroid Build Coastguard Worker      * @see UScriptCode
680*0e209d39SAndroid Build Coastguard Worker      * @see UColReorderCode
681*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
682*0e209d39SAndroid Build Coastguard Worker      */
683*0e209d39SAndroid Build Coastguard Worker     static int32_t U_EXPORT2 getEquivalentReorderCodes(int32_t reorderCode,
684*0e209d39SAndroid Build Coastguard Worker                                 int32_t* dest,
685*0e209d39SAndroid Build Coastguard Worker                                 int32_t destCapacity,
686*0e209d39SAndroid Build Coastguard Worker                                 UErrorCode& status);
687*0e209d39SAndroid Build Coastguard Worker 
688*0e209d39SAndroid Build Coastguard Worker     /**
689*0e209d39SAndroid Build Coastguard Worker      * Get name of the object for the desired Locale, in the desired language
690*0e209d39SAndroid Build Coastguard Worker      * @param objectLocale must be from getAvailableLocales
691*0e209d39SAndroid Build Coastguard Worker      * @param displayLocale specifies the desired locale for output
692*0e209d39SAndroid Build Coastguard Worker      * @param name the fill-in parameter of the return value
693*0e209d39SAndroid Build Coastguard Worker      * @return display-able name of the object for the object locale in the
694*0e209d39SAndroid Build Coastguard Worker      *         desired language
695*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
696*0e209d39SAndroid Build Coastguard Worker      */
697*0e209d39SAndroid Build Coastguard Worker     static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
698*0e209d39SAndroid Build Coastguard Worker                                          const Locale& displayLocale,
699*0e209d39SAndroid Build Coastguard Worker                                          UnicodeString& name);
700*0e209d39SAndroid Build Coastguard Worker 
701*0e209d39SAndroid Build Coastguard Worker     /**
702*0e209d39SAndroid Build Coastguard Worker     * Get name of the object for the desired Locale, in the language of the
703*0e209d39SAndroid Build Coastguard Worker     * default locale.
704*0e209d39SAndroid Build Coastguard Worker     * @param objectLocale must be from getAvailableLocales
705*0e209d39SAndroid Build Coastguard Worker     * @param name the fill-in parameter of the return value
706*0e209d39SAndroid Build Coastguard Worker     * @return name of the object for the desired locale in the default language
707*0e209d39SAndroid Build Coastguard Worker     * @stable ICU 2.0
708*0e209d39SAndroid Build Coastguard Worker     */
709*0e209d39SAndroid Build Coastguard Worker     static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
710*0e209d39SAndroid Build Coastguard Worker                                          UnicodeString& name);
711*0e209d39SAndroid Build Coastguard Worker 
712*0e209d39SAndroid Build Coastguard Worker     /**
713*0e209d39SAndroid Build Coastguard Worker      * Get the set of Locales for which Collations are installed.
714*0e209d39SAndroid Build Coastguard Worker      *
715*0e209d39SAndroid Build Coastguard Worker      * <p>Note this does not include locales supported by registered collators.
716*0e209d39SAndroid Build Coastguard Worker      * If collators might have been registered, use the overload of getAvailableLocales
717*0e209d39SAndroid Build Coastguard Worker      * that returns a StringEnumeration.</p>
718*0e209d39SAndroid Build Coastguard Worker      *
719*0e209d39SAndroid Build Coastguard Worker      * @param count the output parameter of number of elements in the locale list
720*0e209d39SAndroid Build Coastguard Worker      * @return the list of available locales for which collations are installed
721*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
722*0e209d39SAndroid Build Coastguard Worker      */
723*0e209d39SAndroid Build Coastguard Worker     static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
724*0e209d39SAndroid Build Coastguard Worker 
725*0e209d39SAndroid Build Coastguard Worker     /**
726*0e209d39SAndroid Build Coastguard Worker      * Return a StringEnumeration over the locales available at the time of the call,
727*0e209d39SAndroid Build Coastguard Worker      * including registered locales.  If a severe error occurs (such as out of memory
728*0e209d39SAndroid Build Coastguard Worker      * condition) this will return null. If there is no locale data, an empty enumeration
729*0e209d39SAndroid Build Coastguard Worker      * will be returned.
730*0e209d39SAndroid Build Coastguard Worker      * @return a StringEnumeration over the locales available at the time of the call
731*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.6
732*0e209d39SAndroid Build Coastguard Worker      */
733*0e209d39SAndroid Build Coastguard Worker     static StringEnumeration* U_EXPORT2 getAvailableLocales();
734*0e209d39SAndroid Build Coastguard Worker 
735*0e209d39SAndroid Build Coastguard Worker     /**
736*0e209d39SAndroid Build Coastguard Worker      * Create a string enumerator of all possible keywords that are relevant to
737*0e209d39SAndroid Build Coastguard Worker      * collation. At this point, the only recognized keyword for this
738*0e209d39SAndroid Build Coastguard Worker      * service is "collation".
739*0e209d39SAndroid Build Coastguard Worker      * @param status input-output error code
740*0e209d39SAndroid Build Coastguard Worker      * @return a string enumeration over locale strings. The caller is
741*0e209d39SAndroid Build Coastguard Worker      * responsible for closing the result.
742*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 3.0
743*0e209d39SAndroid Build Coastguard Worker      */
744*0e209d39SAndroid Build Coastguard Worker     static StringEnumeration* U_EXPORT2 getKeywords(UErrorCode& status);
745*0e209d39SAndroid Build Coastguard Worker 
746*0e209d39SAndroid Build Coastguard Worker     /**
747*0e209d39SAndroid Build Coastguard Worker      * Given a keyword, create a string enumeration of all values
748*0e209d39SAndroid Build Coastguard Worker      * for that keyword that are currently in use.
749*0e209d39SAndroid Build Coastguard Worker      * @param keyword a particular keyword as enumerated by
750*0e209d39SAndroid Build Coastguard Worker      * ucol_getKeywords. If any other keyword is passed in, status is set
751*0e209d39SAndroid Build Coastguard Worker      * to U_ILLEGAL_ARGUMENT_ERROR.
752*0e209d39SAndroid Build Coastguard Worker      * @param status input-output error code
753*0e209d39SAndroid Build Coastguard Worker      * @return a string enumeration over collation keyword values, or nullptr
754*0e209d39SAndroid Build Coastguard Worker      * upon error. The caller is responsible for deleting the result.
755*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 3.0
756*0e209d39SAndroid Build Coastguard Worker      */
757*0e209d39SAndroid Build Coastguard Worker     static StringEnumeration* U_EXPORT2 getKeywordValues(const char *keyword, UErrorCode& status);
758*0e209d39SAndroid Build Coastguard Worker 
759*0e209d39SAndroid Build Coastguard Worker     /**
760*0e209d39SAndroid Build Coastguard Worker      * Given a key and a locale, returns an array of string values in a preferred
761*0e209d39SAndroid Build Coastguard Worker      * order that would make a difference. These are all and only those values where
762*0e209d39SAndroid Build Coastguard Worker      * the open (creation) of the service with the locale formed from the input locale
763*0e209d39SAndroid Build Coastguard Worker      * plus input keyword and that value has different behavior than creation with the
764*0e209d39SAndroid Build Coastguard Worker      * input locale alone.
765*0e209d39SAndroid Build Coastguard Worker      * @param keyword        one of the keys supported by this service.  For now, only
766*0e209d39SAndroid Build Coastguard Worker      *                      "collation" is supported.
767*0e209d39SAndroid Build Coastguard Worker      * @param locale        the locale
768*0e209d39SAndroid Build Coastguard Worker      * @param commonlyUsed  if set to true it will return only commonly used values
769*0e209d39SAndroid Build Coastguard Worker      *                      with the given locale in preferred order.  Otherwise,
770*0e209d39SAndroid Build Coastguard Worker      *                      it will return all the available values for the locale.
771*0e209d39SAndroid Build Coastguard Worker      * @param status ICU status
772*0e209d39SAndroid Build Coastguard Worker      * @return a string enumeration over keyword values for the given key and the locale.
773*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.2
774*0e209d39SAndroid Build Coastguard Worker      */
775*0e209d39SAndroid Build Coastguard Worker     static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* keyword, const Locale& locale,
776*0e209d39SAndroid Build Coastguard Worker                                                                     UBool commonlyUsed, UErrorCode& status);
777*0e209d39SAndroid Build Coastguard Worker 
778*0e209d39SAndroid Build Coastguard Worker     /**
779*0e209d39SAndroid Build Coastguard Worker      * Return the functionally equivalent locale for the given
780*0e209d39SAndroid Build Coastguard Worker      * requested locale, with respect to given keyword, for the
781*0e209d39SAndroid Build Coastguard Worker      * collation service.  If two locales return the same result, then
782*0e209d39SAndroid Build Coastguard Worker      * collators instantiated for these locales will behave
783*0e209d39SAndroid Build Coastguard Worker      * equivalently.  The converse is not always true; two collators
784*0e209d39SAndroid Build Coastguard Worker      * may in fact be equivalent, but return different results, due to
785*0e209d39SAndroid Build Coastguard Worker      * internal details.  The return result has no other meaning than
786*0e209d39SAndroid Build Coastguard Worker      * that stated above, and implies nothing as to the relationship
787*0e209d39SAndroid Build Coastguard Worker      * between the two locales.  This is intended for use by
788*0e209d39SAndroid Build Coastguard Worker      * applications who wish to cache collators, or otherwise reuse
789*0e209d39SAndroid Build Coastguard Worker      * collators when possible.  The functional equivalent may change
790*0e209d39SAndroid Build Coastguard Worker      * over time.  For more information, please see the <a
791*0e209d39SAndroid Build Coastguard Worker      * href="https://unicode-org.github.io/icu/userguide/locale#locales-and-services">
792*0e209d39SAndroid Build Coastguard Worker      * Locales and Services</a> section of the ICU User Guide.
793*0e209d39SAndroid Build Coastguard Worker      * @param keyword a particular keyword as enumerated by
794*0e209d39SAndroid Build Coastguard Worker      * ucol_getKeywords.
795*0e209d39SAndroid Build Coastguard Worker      * @param locale the requested locale
796*0e209d39SAndroid Build Coastguard Worker      * @param isAvailable reference to a fillin parameter that
797*0e209d39SAndroid Build Coastguard Worker      * indicates whether the requested locale was 'available' to the
798*0e209d39SAndroid Build Coastguard Worker      * collation service. A locale is defined as 'available' if it
799*0e209d39SAndroid Build Coastguard Worker      * physically exists within the collation locale data.
800*0e209d39SAndroid Build Coastguard Worker      * @param status reference to input-output error code
801*0e209d39SAndroid Build Coastguard Worker      * @return the functionally equivalent collation locale, or the root
802*0e209d39SAndroid Build Coastguard Worker      * locale upon error.
803*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 3.0
804*0e209d39SAndroid Build Coastguard Worker      */
805*0e209d39SAndroid Build Coastguard Worker     static Locale U_EXPORT2 getFunctionalEquivalent(const char* keyword, const Locale& locale,
806*0e209d39SAndroid Build Coastguard Worker                                           UBool& isAvailable, UErrorCode& status);
807*0e209d39SAndroid Build Coastguard Worker 
808*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_SERVICE
809*0e209d39SAndroid Build Coastguard Worker     /**
810*0e209d39SAndroid Build Coastguard Worker      * Register a new Collator.  The collator will be adopted.
811*0e209d39SAndroid Build Coastguard Worker      * Because ICU may choose to cache collators internally, this must be
812*0e209d39SAndroid Build Coastguard Worker      * called at application startup, prior to any calls to
813*0e209d39SAndroid Build Coastguard Worker      * Collator::createInstance to avoid undefined behavior.
814*0e209d39SAndroid Build Coastguard Worker      * @param toAdopt the Collator instance to be adopted
815*0e209d39SAndroid Build Coastguard Worker      * @param locale the locale with which the collator will be associated
816*0e209d39SAndroid Build Coastguard Worker      * @param status the in/out status code, no special meanings are assigned
817*0e209d39SAndroid Build Coastguard Worker      * @return a registry key that can be used to unregister this collator
818*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.6
819*0e209d39SAndroid Build Coastguard Worker      */
820*0e209d39SAndroid Build Coastguard Worker     static URegistryKey U_EXPORT2 registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status);
821*0e209d39SAndroid Build Coastguard Worker 
822*0e209d39SAndroid Build Coastguard Worker     /**
823*0e209d39SAndroid Build Coastguard Worker      * Register a new CollatorFactory.  The factory will be adopted.
824*0e209d39SAndroid Build Coastguard Worker      * Because ICU may choose to cache collators internally, this must be
825*0e209d39SAndroid Build Coastguard Worker      * called at application startup, prior to any calls to
826*0e209d39SAndroid Build Coastguard Worker      * Collator::createInstance to avoid undefined behavior.
827*0e209d39SAndroid Build Coastguard Worker      * @param toAdopt the CollatorFactory instance to be adopted
828*0e209d39SAndroid Build Coastguard Worker      * @param status the in/out status code, no special meanings are assigned
829*0e209d39SAndroid Build Coastguard Worker      * @return a registry key that can be used to unregister this collator
830*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.6
831*0e209d39SAndroid Build Coastguard Worker      */
832*0e209d39SAndroid Build Coastguard Worker     static URegistryKey U_EXPORT2 registerFactory(CollatorFactory* toAdopt, UErrorCode& status);
833*0e209d39SAndroid Build Coastguard Worker 
834*0e209d39SAndroid Build Coastguard Worker     /**
835*0e209d39SAndroid Build Coastguard Worker      * Unregister a previously-registered Collator or CollatorFactory
836*0e209d39SAndroid Build Coastguard Worker      * using the key returned from the register call.  Key becomes
837*0e209d39SAndroid Build Coastguard Worker      * invalid after a successful call and should not be used again.
838*0e209d39SAndroid Build Coastguard Worker      * The object corresponding to the key will be deleted.
839*0e209d39SAndroid Build Coastguard Worker      * Because ICU may choose to cache collators internally, this should
840*0e209d39SAndroid Build Coastguard Worker      * be called during application shutdown, after all calls to
841*0e209d39SAndroid Build Coastguard Worker      * Collator::createInstance to avoid undefined behavior.
842*0e209d39SAndroid Build Coastguard Worker      * @param key the registry key returned by a previous call to registerInstance
843*0e209d39SAndroid Build Coastguard Worker      * @param status the in/out status code, no special meanings are assigned
844*0e209d39SAndroid Build Coastguard Worker      * @return true if the collator for the key was successfully unregistered
845*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.6
846*0e209d39SAndroid Build Coastguard Worker      */
847*0e209d39SAndroid Build Coastguard Worker     static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
848*0e209d39SAndroid Build Coastguard Worker #endif /* UCONFIG_NO_SERVICE */
849*0e209d39SAndroid Build Coastguard Worker 
850*0e209d39SAndroid Build Coastguard Worker     /**
851*0e209d39SAndroid Build Coastguard Worker      * Gets the version information for a Collator.
852*0e209d39SAndroid Build Coastguard Worker      * @param info the version # information, the result will be filled in
853*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
854*0e209d39SAndroid Build Coastguard Worker      */
855*0e209d39SAndroid Build Coastguard Worker     virtual void getVersion(UVersionInfo info) const = 0;
856*0e209d39SAndroid Build Coastguard Worker 
857*0e209d39SAndroid Build Coastguard Worker     /**
858*0e209d39SAndroid Build Coastguard Worker      * Returns a unique class ID POLYMORPHICALLY. Pure virtual method.
859*0e209d39SAndroid Build Coastguard Worker      * This method is to implement a simple version of RTTI, since not all C++
860*0e209d39SAndroid Build Coastguard Worker      * compilers support genuine RTTI. Polymorphic operator==() and clone()
861*0e209d39SAndroid Build Coastguard Worker      * methods call this method.
862*0e209d39SAndroid Build Coastguard Worker      * @return The class ID for this object. All objects of a given class have
863*0e209d39SAndroid Build Coastguard Worker      *         the same class ID.  Objects of other classes have different class
864*0e209d39SAndroid Build Coastguard Worker      *         IDs.
865*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
866*0e209d39SAndroid Build Coastguard Worker      */
867*0e209d39SAndroid Build Coastguard Worker     virtual UClassID getDynamicClassID() const override = 0;
868*0e209d39SAndroid Build Coastguard Worker 
869*0e209d39SAndroid Build Coastguard Worker     /**
870*0e209d39SAndroid Build Coastguard Worker      * Universal attribute setter
871*0e209d39SAndroid Build Coastguard Worker      * @param attr attribute type
872*0e209d39SAndroid Build Coastguard Worker      * @param value attribute value
873*0e209d39SAndroid Build Coastguard Worker      * @param status to indicate whether the operation went on smoothly or
874*0e209d39SAndroid Build Coastguard Worker      *        there were errors
875*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.2
876*0e209d39SAndroid Build Coastguard Worker      */
877*0e209d39SAndroid Build Coastguard Worker     virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
878*0e209d39SAndroid Build Coastguard Worker                               UErrorCode &status) = 0;
879*0e209d39SAndroid Build Coastguard Worker 
880*0e209d39SAndroid Build Coastguard Worker     /**
881*0e209d39SAndroid Build Coastguard Worker      * Universal attribute getter
882*0e209d39SAndroid Build Coastguard Worker      * @param attr attribute type
883*0e209d39SAndroid Build Coastguard Worker      * @param status to indicate whether the operation went on smoothly or
884*0e209d39SAndroid Build Coastguard Worker      *        there were errors
885*0e209d39SAndroid Build Coastguard Worker      * @return attribute value
886*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.2
887*0e209d39SAndroid Build Coastguard Worker      */
888*0e209d39SAndroid Build Coastguard Worker     virtual UColAttributeValue getAttribute(UColAttribute attr,
889*0e209d39SAndroid Build Coastguard Worker                                             UErrorCode &status) const = 0;
890*0e209d39SAndroid Build Coastguard Worker 
891*0e209d39SAndroid Build Coastguard Worker     /**
892*0e209d39SAndroid Build Coastguard Worker      * Sets the variable top to the top of the specified reordering group.
893*0e209d39SAndroid Build Coastguard Worker      * The variable top determines the highest-sorting character
894*0e209d39SAndroid Build Coastguard Worker      * which is affected by UCOL_ALTERNATE_HANDLING.
895*0e209d39SAndroid Build Coastguard Worker      * If that attribute is set to UCOL_NON_IGNORABLE, then the variable top has no effect.
896*0e209d39SAndroid Build Coastguard Worker      *
897*0e209d39SAndroid Build Coastguard Worker      * The base class implementation sets U_UNSUPPORTED_ERROR.
898*0e209d39SAndroid Build Coastguard Worker      * @param group one of UCOL_REORDER_CODE_SPACE, UCOL_REORDER_CODE_PUNCTUATION,
899*0e209d39SAndroid Build Coastguard Worker      *              UCOL_REORDER_CODE_SYMBOL, UCOL_REORDER_CODE_CURRENCY;
900*0e209d39SAndroid Build Coastguard Worker      *              or UCOL_REORDER_CODE_DEFAULT to restore the default max variable group
901*0e209d39SAndroid Build Coastguard Worker      * @param errorCode Standard ICU error code. Its input value must
902*0e209d39SAndroid Build Coastguard Worker      *                  pass the U_SUCCESS() test, or else the function returns
903*0e209d39SAndroid Build Coastguard Worker      *                  immediately. Check for U_FAILURE() on output or use with
904*0e209d39SAndroid Build Coastguard Worker      *                  function chaining. (See User Guide for details.)
905*0e209d39SAndroid Build Coastguard Worker      * @return *this
906*0e209d39SAndroid Build Coastguard Worker      * @see getMaxVariable
907*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 53
908*0e209d39SAndroid Build Coastguard Worker      */
909*0e209d39SAndroid Build Coastguard Worker     virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCode);
910*0e209d39SAndroid Build Coastguard Worker 
911*0e209d39SAndroid Build Coastguard Worker     /**
912*0e209d39SAndroid Build Coastguard Worker      * Returns the maximum reordering group whose characters are affected by UCOL_ALTERNATE_HANDLING.
913*0e209d39SAndroid Build Coastguard Worker      *
914*0e209d39SAndroid Build Coastguard Worker      * The base class implementation returns UCOL_REORDER_CODE_PUNCTUATION.
915*0e209d39SAndroid Build Coastguard Worker      * @return the maximum variable reordering group.
916*0e209d39SAndroid Build Coastguard Worker      * @see setMaxVariable
917*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 53
918*0e209d39SAndroid Build Coastguard Worker      */
919*0e209d39SAndroid Build Coastguard Worker     virtual UColReorderCode getMaxVariable() const;
920*0e209d39SAndroid Build Coastguard Worker 
921*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
922*0e209d39SAndroid Build Coastguard Worker     /**
923*0e209d39SAndroid Build Coastguard Worker      * Sets the variable top to the primary weight of the specified string.
924*0e209d39SAndroid Build Coastguard Worker      *
925*0e209d39SAndroid Build Coastguard Worker      * Beginning with ICU 53, the variable top is pinned to
926*0e209d39SAndroid Build Coastguard Worker      * the top of one of the supported reordering groups,
927*0e209d39SAndroid Build Coastguard Worker      * and it must not be beyond the last of those groups.
928*0e209d39SAndroid Build Coastguard Worker      * See setMaxVariable().
929*0e209d39SAndroid Build Coastguard Worker      * @param varTop one or more (if contraction) char16_ts to which the variable top should be set
930*0e209d39SAndroid Build Coastguard Worker      * @param len length of variable top string. If -1 it is considered to be zero terminated.
931*0e209d39SAndroid Build Coastguard Worker      * @param status error code. If error code is set, the return value is undefined. Errors set by this function are: <br>
932*0e209d39SAndroid Build Coastguard Worker      *    U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction<br>
933*0e209d39SAndroid Build Coastguard Worker      *    U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond
934*0e209d39SAndroid Build Coastguard Worker      *    the last reordering group supported by setMaxVariable()
935*0e209d39SAndroid Build Coastguard Worker      * @return variable top primary weight
936*0e209d39SAndroid Build Coastguard Worker      * @deprecated ICU 53 Call setMaxVariable() instead.
937*0e209d39SAndroid Build Coastguard Worker      */
938*0e209d39SAndroid Build Coastguard Worker     virtual uint32_t setVariableTop(const char16_t *varTop, int32_t len, UErrorCode &status) = 0;
939*0e209d39SAndroid Build Coastguard Worker 
940*0e209d39SAndroid Build Coastguard Worker     /**
941*0e209d39SAndroid Build Coastguard Worker      * Sets the variable top to the primary weight of the specified string.
942*0e209d39SAndroid Build Coastguard Worker      *
943*0e209d39SAndroid Build Coastguard Worker      * Beginning with ICU 53, the variable top is pinned to
944*0e209d39SAndroid Build Coastguard Worker      * the top of one of the supported reordering groups,
945*0e209d39SAndroid Build Coastguard Worker      * and it must not be beyond the last of those groups.
946*0e209d39SAndroid Build Coastguard Worker      * See setMaxVariable().
947*0e209d39SAndroid Build Coastguard Worker      * @param varTop a UnicodeString size 1 or more (if contraction) of char16_ts to which the variable top should be set
948*0e209d39SAndroid Build Coastguard Worker      * @param status error code. If error code is set, the return value is undefined. Errors set by this function are: <br>
949*0e209d39SAndroid Build Coastguard Worker      *    U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction<br>
950*0e209d39SAndroid Build Coastguard Worker      *    U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond
951*0e209d39SAndroid Build Coastguard Worker      *    the last reordering group supported by setMaxVariable()
952*0e209d39SAndroid Build Coastguard Worker      * @return variable top primary weight
953*0e209d39SAndroid Build Coastguard Worker      * @deprecated ICU 53 Call setMaxVariable() instead.
954*0e209d39SAndroid Build Coastguard Worker      */
955*0e209d39SAndroid Build Coastguard Worker     virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) = 0;
956*0e209d39SAndroid Build Coastguard Worker 
957*0e209d39SAndroid Build Coastguard Worker     /**
958*0e209d39SAndroid Build Coastguard Worker      * Sets the variable top to the specified primary weight.
959*0e209d39SAndroid Build Coastguard Worker      *
960*0e209d39SAndroid Build Coastguard Worker      * Beginning with ICU 53, the variable top is pinned to
961*0e209d39SAndroid Build Coastguard Worker      * the top of one of the supported reordering groups,
962*0e209d39SAndroid Build Coastguard Worker      * and it must not be beyond the last of those groups.
963*0e209d39SAndroid Build Coastguard Worker      * See setMaxVariable().
964*0e209d39SAndroid Build Coastguard Worker      * @param varTop primary weight, as returned by setVariableTop or ucol_getVariableTop
965*0e209d39SAndroid Build Coastguard Worker      * @param status error code
966*0e209d39SAndroid Build Coastguard Worker      * @deprecated ICU 53 Call setMaxVariable() instead.
967*0e209d39SAndroid Build Coastguard Worker      */
968*0e209d39SAndroid Build Coastguard Worker     virtual void setVariableTop(uint32_t varTop, UErrorCode &status) = 0;
969*0e209d39SAndroid Build Coastguard Worker #endif  // U_FORCE_HIDE_DEPRECATED_API
970*0e209d39SAndroid Build Coastguard Worker 
971*0e209d39SAndroid Build Coastguard Worker     /**
972*0e209d39SAndroid Build Coastguard Worker      * Gets the variable top value of a Collator.
973*0e209d39SAndroid Build Coastguard Worker      * @param status error code (not changed by function). If error code is set, the return value is undefined.
974*0e209d39SAndroid Build Coastguard Worker      * @return the variable top primary weight
975*0e209d39SAndroid Build Coastguard Worker      * @see getMaxVariable
976*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
977*0e209d39SAndroid Build Coastguard Worker      */
978*0e209d39SAndroid Build Coastguard Worker     virtual uint32_t getVariableTop(UErrorCode &status) const = 0;
979*0e209d39SAndroid Build Coastguard Worker 
980*0e209d39SAndroid Build Coastguard Worker     /**
981*0e209d39SAndroid Build Coastguard Worker      * Get a UnicodeSet that contains all the characters and sequences
982*0e209d39SAndroid Build Coastguard Worker      * tailored in this collator.
983*0e209d39SAndroid Build Coastguard Worker      * @param status      error code of the operation
984*0e209d39SAndroid Build Coastguard Worker      * @return a pointer to a UnicodeSet object containing all the
985*0e209d39SAndroid Build Coastguard Worker      *         code points and sequences that may sort differently than
986*0e209d39SAndroid Build Coastguard Worker      *         in the root collator. The object must be disposed of by using delete
987*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
988*0e209d39SAndroid Build Coastguard Worker      */
989*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
990*0e209d39SAndroid Build Coastguard Worker 
991*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
992*0e209d39SAndroid Build Coastguard Worker     /**
993*0e209d39SAndroid Build Coastguard Worker      * Same as clone().
994*0e209d39SAndroid Build Coastguard Worker      * The base class implementation simply calls clone().
995*0e209d39SAndroid Build Coastguard Worker      * @return a copy of this object, owned by the caller
996*0e209d39SAndroid Build Coastguard Worker      * @see clone()
997*0e209d39SAndroid Build Coastguard Worker      * @deprecated ICU 50 no need to have two methods for cloning
998*0e209d39SAndroid Build Coastguard Worker      */
999*0e209d39SAndroid Build Coastguard Worker     virtual Collator* safeClone() const;
1000*0e209d39SAndroid Build Coastguard Worker #endif  // U_FORCE_HIDE_DEPRECATED_API
1001*0e209d39SAndroid Build Coastguard Worker 
1002*0e209d39SAndroid Build Coastguard Worker     /**
1003*0e209d39SAndroid Build Coastguard Worker      * Get the sort key as an array of bytes from a UnicodeString.
1004*0e209d39SAndroid Build Coastguard Worker      * Sort key byte arrays are zero-terminated and can be compared using
1005*0e209d39SAndroid Build Coastguard Worker      * strcmp().
1006*0e209d39SAndroid Build Coastguard Worker      *
1007*0e209d39SAndroid Build Coastguard Worker      * Note that sort keys are often less efficient than simply doing comparison.
1008*0e209d39SAndroid Build Coastguard Worker      * For more details, see the ICU User Guide.
1009*0e209d39SAndroid Build Coastguard Worker      *
1010*0e209d39SAndroid Build Coastguard Worker      * @param source string to be processed.
1011*0e209d39SAndroid Build Coastguard Worker      * @param result buffer to store result in. If nullptr, number of bytes needed
1012*0e209d39SAndroid Build Coastguard Worker      *        will be returned.
1013*0e209d39SAndroid Build Coastguard Worker      * @param resultLength length of the result buffer. If if not enough the
1014*0e209d39SAndroid Build Coastguard Worker      *        buffer will be filled to capacity.
1015*0e209d39SAndroid Build Coastguard Worker      * @return Number of bytes needed for storing the sort key
1016*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.2
1017*0e209d39SAndroid Build Coastguard Worker      */
1018*0e209d39SAndroid Build Coastguard Worker     virtual int32_t getSortKey(const UnicodeString& source,
1019*0e209d39SAndroid Build Coastguard Worker                               uint8_t* result,
1020*0e209d39SAndroid Build Coastguard Worker                               int32_t resultLength) const = 0;
1021*0e209d39SAndroid Build Coastguard Worker 
1022*0e209d39SAndroid Build Coastguard Worker     /**
1023*0e209d39SAndroid Build Coastguard Worker      * Get the sort key as an array of bytes from a char16_t buffer.
1024*0e209d39SAndroid Build Coastguard Worker      * Sort key byte arrays are zero-terminated and can be compared using
1025*0e209d39SAndroid Build Coastguard Worker      * strcmp().
1026*0e209d39SAndroid Build Coastguard Worker      *
1027*0e209d39SAndroid Build Coastguard Worker      * Note that sort keys are often less efficient than simply doing comparison.
1028*0e209d39SAndroid Build Coastguard Worker      * For more details, see the ICU User Guide.
1029*0e209d39SAndroid Build Coastguard Worker      *
1030*0e209d39SAndroid Build Coastguard Worker      * @param source string to be processed.
1031*0e209d39SAndroid Build Coastguard Worker      * @param sourceLength length of string to be processed.
1032*0e209d39SAndroid Build Coastguard Worker      *        If -1, the string is 0 terminated and length will be decided by the
1033*0e209d39SAndroid Build Coastguard Worker      *        function.
1034*0e209d39SAndroid Build Coastguard Worker      * @param result buffer to store result in. If nullptr, number of bytes needed
1035*0e209d39SAndroid Build Coastguard Worker      *        will be returned.
1036*0e209d39SAndroid Build Coastguard Worker      * @param resultLength length of the result buffer. If if not enough the
1037*0e209d39SAndroid Build Coastguard Worker      *        buffer will be filled to capacity.
1038*0e209d39SAndroid Build Coastguard Worker      * @return Number of bytes needed for storing the sort key
1039*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.2
1040*0e209d39SAndroid Build Coastguard Worker      */
1041*0e209d39SAndroid Build Coastguard Worker     virtual int32_t getSortKey(const char16_t*source, int32_t sourceLength,
1042*0e209d39SAndroid Build Coastguard Worker                                uint8_t*result, int32_t resultLength) const = 0;
1043*0e209d39SAndroid Build Coastguard Worker 
1044*0e209d39SAndroid Build Coastguard Worker     /**
1045*0e209d39SAndroid Build Coastguard Worker      * Produce a bound for a given sortkey and a number of levels.
1046*0e209d39SAndroid Build Coastguard Worker      * Return value is always the number of bytes needed, regardless of
1047*0e209d39SAndroid Build Coastguard Worker      * whether the result buffer was big enough or even valid.<br>
1048*0e209d39SAndroid Build Coastguard Worker      * Resulting bounds can be used to produce a range of strings that are
1049*0e209d39SAndroid Build Coastguard Worker      * between upper and lower bounds. For example, if bounds are produced
1050*0e209d39SAndroid Build Coastguard Worker      * for a sortkey of string "smith", strings between upper and lower
1051*0e209d39SAndroid Build Coastguard Worker      * bounds with one level would include "Smith", "SMITH", "sMiTh".<br>
1052*0e209d39SAndroid Build Coastguard Worker      * There are two upper bounds that can be produced. If UCOL_BOUND_UPPER
1053*0e209d39SAndroid Build Coastguard Worker      * is produced, strings matched would be as above. However, if bound
1054*0e209d39SAndroid Build Coastguard Worker      * produced using UCOL_BOUND_UPPER_LONG is used, the above example will
1055*0e209d39SAndroid Build Coastguard Worker      * also match "Smithsonian" and similar.<br>
1056*0e209d39SAndroid Build Coastguard Worker      * For more on usage, see example in cintltst/capitst.c in procedure
1057*0e209d39SAndroid Build Coastguard Worker      * TestBounds.
1058*0e209d39SAndroid Build Coastguard Worker      * Sort keys may be compared using <TT>strcmp</TT>.
1059*0e209d39SAndroid Build Coastguard Worker      * @param source The source sortkey.
1060*0e209d39SAndroid Build Coastguard Worker      * @param sourceLength The length of source, or -1 if null-terminated.
1061*0e209d39SAndroid Build Coastguard Worker      *                     (If an unmodified sortkey is passed, it is always null
1062*0e209d39SAndroid Build Coastguard Worker      *                      terminated).
1063*0e209d39SAndroid Build Coastguard Worker      * @param boundType Type of bound required. It can be UCOL_BOUND_LOWER, which
1064*0e209d39SAndroid Build Coastguard Worker      *                  produces a lower inclusive bound, UCOL_BOUND_UPPER, that
1065*0e209d39SAndroid Build Coastguard Worker      *                  produces upper bound that matches strings of the same length
1066*0e209d39SAndroid Build Coastguard Worker      *                  or UCOL_BOUND_UPPER_LONG that matches strings that have the
1067*0e209d39SAndroid Build Coastguard Worker      *                  same starting substring as the source string.
1068*0e209d39SAndroid Build Coastguard Worker      * @param noOfLevels  Number of levels required in the resulting bound (for most
1069*0e209d39SAndroid Build Coastguard Worker      *                    uses, the recommended value is 1). See users guide for
1070*0e209d39SAndroid Build Coastguard Worker      *                    explanation on number of levels a sortkey can have.
1071*0e209d39SAndroid Build Coastguard Worker      * @param result A pointer to a buffer to receive the resulting sortkey.
1072*0e209d39SAndroid Build Coastguard Worker      * @param resultLength The maximum size of result.
1073*0e209d39SAndroid Build Coastguard Worker      * @param status Used for returning error code if something went wrong. If the
1074*0e209d39SAndroid Build Coastguard Worker      *               number of levels requested is higher than the number of levels
1075*0e209d39SAndroid Build Coastguard Worker      *               in the source key, a warning (U_SORT_KEY_TOO_SHORT_WARNING) is
1076*0e209d39SAndroid Build Coastguard Worker      *               issued.
1077*0e209d39SAndroid Build Coastguard Worker      * @return The size needed to fully store the bound.
1078*0e209d39SAndroid Build Coastguard Worker      * @see ucol_keyHashCode
1079*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.1
1080*0e209d39SAndroid Build Coastguard Worker      */
1081*0e209d39SAndroid Build Coastguard Worker     static int32_t U_EXPORT2 getBound(const uint8_t       *source,
1082*0e209d39SAndroid Build Coastguard Worker             int32_t             sourceLength,
1083*0e209d39SAndroid Build Coastguard Worker             UColBoundMode       boundType,
1084*0e209d39SAndroid Build Coastguard Worker             uint32_t            noOfLevels,
1085*0e209d39SAndroid Build Coastguard Worker             uint8_t             *result,
1086*0e209d39SAndroid Build Coastguard Worker             int32_t             resultLength,
1087*0e209d39SAndroid Build Coastguard Worker             UErrorCode          &status);
1088*0e209d39SAndroid Build Coastguard Worker 
1089*0e209d39SAndroid Build Coastguard Worker 
1090*0e209d39SAndroid Build Coastguard Worker protected:
1091*0e209d39SAndroid Build Coastguard Worker 
1092*0e209d39SAndroid Build Coastguard Worker     // Collator protected constructors -------------------------------------
1093*0e209d39SAndroid Build Coastguard Worker 
1094*0e209d39SAndroid Build Coastguard Worker     /**
1095*0e209d39SAndroid Build Coastguard Worker     * Default constructor.
1096*0e209d39SAndroid Build Coastguard Worker     * Constructor is different from the old default Collator constructor.
1097*0e209d39SAndroid Build Coastguard Worker     * The task for determining the default collation strength and normalization
1098*0e209d39SAndroid Build Coastguard Worker     * mode is left to the child class.
1099*0e209d39SAndroid Build Coastguard Worker     * @stable ICU 2.0
1100*0e209d39SAndroid Build Coastguard Worker     */
1101*0e209d39SAndroid Build Coastguard Worker     Collator();
1102*0e209d39SAndroid Build Coastguard Worker 
1103*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
1104*0e209d39SAndroid Build Coastguard Worker     /**
1105*0e209d39SAndroid Build Coastguard Worker     * Constructor.
1106*0e209d39SAndroid Build Coastguard Worker     * Empty constructor, does not handle the arguments.
1107*0e209d39SAndroid Build Coastguard Worker     * This constructor is done for backward compatibility with 1.7 and 1.8.
1108*0e209d39SAndroid Build Coastguard Worker     * The task for handling the argument collation strength and normalization
1109*0e209d39SAndroid Build Coastguard Worker     * mode is left to the child class.
1110*0e209d39SAndroid Build Coastguard Worker     * @param collationStrength collation strength
1111*0e209d39SAndroid Build Coastguard Worker     * @param decompositionMode
1112*0e209d39SAndroid Build Coastguard Worker     * @deprecated ICU 2.4. Subclasses should use the default constructor
1113*0e209d39SAndroid Build Coastguard Worker     * instead and handle the strength and normalization mode themselves.
1114*0e209d39SAndroid Build Coastguard Worker     */
1115*0e209d39SAndroid Build Coastguard Worker     Collator(UCollationStrength collationStrength,
1116*0e209d39SAndroid Build Coastguard Worker              UNormalizationMode decompositionMode);
1117*0e209d39SAndroid Build Coastguard Worker #endif  /* U_HIDE_DEPRECATED_API */
1118*0e209d39SAndroid Build Coastguard Worker 
1119*0e209d39SAndroid Build Coastguard Worker     /**
1120*0e209d39SAndroid Build Coastguard Worker     * Copy constructor.
1121*0e209d39SAndroid Build Coastguard Worker     * @param other Collator object to be copied from
1122*0e209d39SAndroid Build Coastguard Worker     * @stable ICU 2.0
1123*0e209d39SAndroid Build Coastguard Worker     */
1124*0e209d39SAndroid Build Coastguard Worker     Collator(const Collator& other);
1125*0e209d39SAndroid Build Coastguard Worker 
1126*0e209d39SAndroid Build Coastguard Worker public:
1127*0e209d39SAndroid Build Coastguard Worker    /**
1128*0e209d39SAndroid Build Coastguard Worker     * Used internally by registration to define the requested and valid locales.
1129*0e209d39SAndroid Build Coastguard Worker     * @param requestedLocale the requested locale
1130*0e209d39SAndroid Build Coastguard Worker     * @param validLocale the valid locale
1131*0e209d39SAndroid Build Coastguard Worker     * @param actualLocale the actual locale
1132*0e209d39SAndroid Build Coastguard Worker     * @internal
1133*0e209d39SAndroid Build Coastguard Worker     */
1134*0e209d39SAndroid Build Coastguard Worker     virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
1135*0e209d39SAndroid Build Coastguard Worker 
1136*0e209d39SAndroid Build Coastguard Worker     /** Get the short definition string for a collator. This internal API harvests the collator's
1137*0e209d39SAndroid Build Coastguard Worker      *  locale and the attribute set and produces a string that can be used for opening
1138*0e209d39SAndroid Build Coastguard Worker      *  a collator with the same attributes using the ucol_openFromShortString API.
1139*0e209d39SAndroid Build Coastguard Worker      *  This string will be normalized.
1140*0e209d39SAndroid Build Coastguard Worker      *  The structure and the syntax of the string is defined in the "Naming collators"
1141*0e209d39SAndroid Build Coastguard Worker      *  section of the users guide:
1142*0e209d39SAndroid Build Coastguard Worker      *  https://unicode-org.github.io/icu/userguide/collation/concepts#collator-naming-scheme
1143*0e209d39SAndroid Build Coastguard Worker      *  This function supports preflighting.
1144*0e209d39SAndroid Build Coastguard Worker      *
1145*0e209d39SAndroid Build Coastguard Worker      *  This is internal, and intended to be used with delegate converters.
1146*0e209d39SAndroid Build Coastguard Worker      *
1147*0e209d39SAndroid Build Coastguard Worker      *  @param locale a locale that will appear as a collators locale in the resulting
1148*0e209d39SAndroid Build Coastguard Worker      *                short string definition. If nullptr, the locale will be harvested
1149*0e209d39SAndroid Build Coastguard Worker      *                from the collator.
1150*0e209d39SAndroid Build Coastguard Worker      *  @param buffer space to hold the resulting string
1151*0e209d39SAndroid Build Coastguard Worker      *  @param capacity capacity of the buffer
1152*0e209d39SAndroid Build Coastguard Worker      *  @param status for returning errors. All the preflighting errors are featured
1153*0e209d39SAndroid Build Coastguard Worker      *  @return length of the resulting string
1154*0e209d39SAndroid Build Coastguard Worker      *  @see ucol_openFromShortString
1155*0e209d39SAndroid Build Coastguard Worker      *  @see ucol_normalizeShortDefinitionString
1156*0e209d39SAndroid Build Coastguard Worker      *  @see ucol_getShortDefinitionString
1157*0e209d39SAndroid Build Coastguard Worker      *  @internal
1158*0e209d39SAndroid Build Coastguard Worker      */
1159*0e209d39SAndroid Build Coastguard Worker     virtual int32_t internalGetShortDefinitionString(const char *locale,
1160*0e209d39SAndroid Build Coastguard Worker                                                      char *buffer,
1161*0e209d39SAndroid Build Coastguard Worker                                                      int32_t capacity,
1162*0e209d39SAndroid Build Coastguard Worker                                                      UErrorCode &status) const;
1163*0e209d39SAndroid Build Coastguard Worker 
1164*0e209d39SAndroid Build Coastguard Worker     /**
1165*0e209d39SAndroid Build Coastguard Worker      * Implements ucol_strcollUTF8().
1166*0e209d39SAndroid Build Coastguard Worker      * @internal
1167*0e209d39SAndroid Build Coastguard Worker      */
1168*0e209d39SAndroid Build Coastguard Worker     virtual UCollationResult internalCompareUTF8(
1169*0e209d39SAndroid Build Coastguard Worker             const char *left, int32_t leftLength,
1170*0e209d39SAndroid Build Coastguard Worker             const char *right, int32_t rightLength,
1171*0e209d39SAndroid Build Coastguard Worker             UErrorCode &errorCode) const;
1172*0e209d39SAndroid Build Coastguard Worker 
1173*0e209d39SAndroid Build Coastguard Worker     /**
1174*0e209d39SAndroid Build Coastguard Worker      * Implements ucol_nextSortKeyPart().
1175*0e209d39SAndroid Build Coastguard Worker      * @internal
1176*0e209d39SAndroid Build Coastguard Worker      */
1177*0e209d39SAndroid Build Coastguard Worker     virtual int32_t
1178*0e209d39SAndroid Build Coastguard Worker     internalNextSortKeyPart(
1179*0e209d39SAndroid Build Coastguard Worker             UCharIterator *iter, uint32_t state[2],
1180*0e209d39SAndroid Build Coastguard Worker             uint8_t *dest, int32_t count, UErrorCode &errorCode) const;
1181*0e209d39SAndroid Build Coastguard Worker 
1182*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
1183*0e209d39SAndroid Build Coastguard Worker     /** @internal */
fromUCollator(UCollator * uc)1184*0e209d39SAndroid Build Coastguard Worker     static inline Collator *fromUCollator(UCollator *uc) {
1185*0e209d39SAndroid Build Coastguard Worker         return reinterpret_cast<Collator *>(uc);
1186*0e209d39SAndroid Build Coastguard Worker     }
1187*0e209d39SAndroid Build Coastguard Worker     /** @internal */
fromUCollator(const UCollator * uc)1188*0e209d39SAndroid Build Coastguard Worker     static inline const Collator *fromUCollator(const UCollator *uc) {
1189*0e209d39SAndroid Build Coastguard Worker         return reinterpret_cast<const Collator *>(uc);
1190*0e209d39SAndroid Build Coastguard Worker     }
1191*0e209d39SAndroid Build Coastguard Worker     /** @internal */
toUCollator()1192*0e209d39SAndroid Build Coastguard Worker     inline UCollator *toUCollator() {
1193*0e209d39SAndroid Build Coastguard Worker         return reinterpret_cast<UCollator *>(this);
1194*0e209d39SAndroid Build Coastguard Worker     }
1195*0e209d39SAndroid Build Coastguard Worker     /** @internal */
toUCollator()1196*0e209d39SAndroid Build Coastguard Worker     inline const UCollator *toUCollator() const {
1197*0e209d39SAndroid Build Coastguard Worker         return reinterpret_cast<const UCollator *>(this);
1198*0e209d39SAndroid Build Coastguard Worker     }
1199*0e209d39SAndroid Build Coastguard Worker #endif  // U_HIDE_INTERNAL_API
1200*0e209d39SAndroid Build Coastguard Worker 
1201*0e209d39SAndroid Build Coastguard Worker private:
1202*0e209d39SAndroid Build Coastguard Worker     /**
1203*0e209d39SAndroid Build Coastguard Worker      * Assignment operator. Private for now.
1204*0e209d39SAndroid Build Coastguard Worker      */
1205*0e209d39SAndroid Build Coastguard Worker     Collator& operator=(const Collator& other) = delete;
1206*0e209d39SAndroid Build Coastguard Worker 
1207*0e209d39SAndroid Build Coastguard Worker     friend class CFactory;
1208*0e209d39SAndroid Build Coastguard Worker     friend class SimpleCFactory;
1209*0e209d39SAndroid Build Coastguard Worker     friend class ICUCollatorFactory;
1210*0e209d39SAndroid Build Coastguard Worker     friend class ICUCollatorService;
1211*0e209d39SAndroid Build Coastguard Worker     static Collator* makeInstance(const Locale& desiredLocale,
1212*0e209d39SAndroid Build Coastguard Worker                                   UErrorCode& status);
1213*0e209d39SAndroid Build Coastguard Worker };
1214*0e209d39SAndroid Build Coastguard Worker 
1215*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_SERVICE
1216*0e209d39SAndroid Build Coastguard Worker /**
1217*0e209d39SAndroid Build Coastguard Worker  * A factory, used with registerFactory, the creates multiple collators and provides
1218*0e209d39SAndroid Build Coastguard Worker  * display names for them.  A factory supports some number of locales-- these are the
1219*0e209d39SAndroid Build Coastguard Worker  * locales for which it can create collators.  The factory can be visible, in which
1220*0e209d39SAndroid Build Coastguard Worker  * case the supported locales will be enumerated by getAvailableLocales, or invisible,
1221*0e209d39SAndroid Build Coastguard Worker  * in which they are not.  Invisible locales are still supported, they are just not
1222*0e209d39SAndroid Build Coastguard Worker  * listed by getAvailableLocales.
1223*0e209d39SAndroid Build Coastguard Worker  * <p>
1224*0e209d39SAndroid Build Coastguard Worker  * If standard locale display names are sufficient, Collator instances can
1225*0e209d39SAndroid Build Coastguard Worker  * be registered using registerInstance instead.</p>
1226*0e209d39SAndroid Build Coastguard Worker  * <p>
1227*0e209d39SAndroid Build Coastguard Worker  * Note: if the collators are to be used from C APIs, they must be instances
1228*0e209d39SAndroid Build Coastguard Worker  * of RuleBasedCollator.</p>
1229*0e209d39SAndroid Build Coastguard Worker  *
1230*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.6
1231*0e209d39SAndroid Build Coastguard Worker  */
1232*0e209d39SAndroid Build Coastguard Worker class U_I18N_API CollatorFactory : public UObject {
1233*0e209d39SAndroid Build Coastguard Worker public:
1234*0e209d39SAndroid Build Coastguard Worker 
1235*0e209d39SAndroid Build Coastguard Worker     /**
1236*0e209d39SAndroid Build Coastguard Worker      * Destructor
1237*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 3.0
1238*0e209d39SAndroid Build Coastguard Worker      */
1239*0e209d39SAndroid Build Coastguard Worker     virtual ~CollatorFactory();
1240*0e209d39SAndroid Build Coastguard Worker 
1241*0e209d39SAndroid Build Coastguard Worker     /**
1242*0e209d39SAndroid Build Coastguard Worker      * Return true if this factory is visible.  Default is true.
1243*0e209d39SAndroid Build Coastguard Worker      * If not visible, the locales supported by this factory will not
1244*0e209d39SAndroid Build Coastguard Worker      * be listed by getAvailableLocales.
1245*0e209d39SAndroid Build Coastguard Worker      * @return true if the factory is visible.
1246*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.6
1247*0e209d39SAndroid Build Coastguard Worker      */
1248*0e209d39SAndroid Build Coastguard Worker     virtual UBool visible() const;
1249*0e209d39SAndroid Build Coastguard Worker 
1250*0e209d39SAndroid Build Coastguard Worker     /**
1251*0e209d39SAndroid Build Coastguard Worker      * Return a collator for the provided locale.  If the locale
1252*0e209d39SAndroid Build Coastguard Worker      * is not supported, return nullptr.
1253*0e209d39SAndroid Build Coastguard Worker      * @param loc the locale identifying the collator to be created.
1254*0e209d39SAndroid Build Coastguard Worker      * @return a new collator if the locale is supported, otherwise nullptr.
1255*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.6
1256*0e209d39SAndroid Build Coastguard Worker      */
1257*0e209d39SAndroid Build Coastguard Worker     virtual Collator* createCollator(const Locale& loc) = 0;
1258*0e209d39SAndroid Build Coastguard Worker 
1259*0e209d39SAndroid Build Coastguard Worker     /**
1260*0e209d39SAndroid Build Coastguard Worker      * Return the name of the collator for the objectLocale, localized for the displayLocale.
1261*0e209d39SAndroid Build Coastguard Worker      * If objectLocale is not supported, or the factory is not visible, set the result string
1262*0e209d39SAndroid Build Coastguard Worker      * to bogus.
1263*0e209d39SAndroid Build Coastguard Worker      * @param objectLocale the locale identifying the collator
1264*0e209d39SAndroid Build Coastguard Worker      * @param displayLocale the locale for which the display name of the collator should be localized
1265*0e209d39SAndroid Build Coastguard Worker      * @param result an output parameter for the display name, set to bogus if not supported.
1266*0e209d39SAndroid Build Coastguard Worker      * @return the display name
1267*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.6
1268*0e209d39SAndroid Build Coastguard Worker      */
1269*0e209d39SAndroid Build Coastguard Worker     virtual  UnicodeString& getDisplayName(const Locale& objectLocale,
1270*0e209d39SAndroid Build Coastguard Worker                                            const Locale& displayLocale,
1271*0e209d39SAndroid Build Coastguard Worker                                            UnicodeString& result);
1272*0e209d39SAndroid Build Coastguard Worker 
1273*0e209d39SAndroid Build Coastguard Worker     /**
1274*0e209d39SAndroid Build Coastguard Worker      * Return an array of all the locale names directly supported by this factory.
1275*0e209d39SAndroid Build Coastguard Worker      * The number of names is returned in count.  This array is owned by the factory.
1276*0e209d39SAndroid Build Coastguard Worker      * Its contents must never change.
1277*0e209d39SAndroid Build Coastguard Worker      * @param count output parameter for the number of locales supported by the factory
1278*0e209d39SAndroid Build Coastguard Worker      * @param status the in/out error code
1279*0e209d39SAndroid Build Coastguard Worker      * @return a pointer to an array of count UnicodeStrings.
1280*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.6
1281*0e209d39SAndroid Build Coastguard Worker      */
1282*0e209d39SAndroid Build Coastguard Worker     virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
1283*0e209d39SAndroid Build Coastguard Worker };
1284*0e209d39SAndroid Build Coastguard Worker #endif /* UCONFIG_NO_SERVICE */
1285*0e209d39SAndroid Build Coastguard Worker 
1286*0e209d39SAndroid Build Coastguard Worker // Collator inline methods -----------------------------------------------
1287*0e209d39SAndroid Build Coastguard Worker 
1288*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
1289*0e209d39SAndroid Build Coastguard Worker 
1290*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_COLLATION */
1291*0e209d39SAndroid Build Coastguard Worker 
1292*0e209d39SAndroid Build Coastguard Worker #endif /* U_SHOW_CPLUSPLUS_API */
1293*0e209d39SAndroid Build Coastguard Worker 
1294*0e209d39SAndroid Build Coastguard Worker #endif
1295