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