]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/unicode/coll.h
ICU-6.2.4.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / coll.h
1 /*
2 ******************************************************************************
3 * Copyright (C) 1996-2004, International Business Machines *
4 * Corporation and others. All Rights Reserved. *
5 ******************************************************************************
6 */
7
8 /**
9 * File coll.h
10 *
11 * Created by: Helena Shih
12 *
13 * Modification History:
14 *
15 * Date Name Description
16 * 02/5/97 aliu Modified createDefault to load collation data from
17 * binary files when possible. Added related methods
18 * createCollationFromFile, chopLocale, createPathName.
19 * 02/11/97 aliu Added members addToCache, findInCache, and fgCache.
20 * 02/12/97 aliu Modified to create objects from RuleBasedCollator cache.
21 * Moved cache out of Collation class.
22 * 02/13/97 aliu Moved several methods out of this class and into
23 * RuleBasedCollator, with modifications. Modified
24 * createDefault() to call new RuleBasedCollator(Locale&)
25 * constructor. General clean up and documentation.
26 * 02/20/97 helena Added clone, operator==, operator!=, operator=, copy
27 * constructor and getDynamicClassID.
28 * 03/25/97 helena Updated with platform independent data types.
29 * 05/06/97 helena Added memory allocation error detection.
30 * 06/20/97 helena Java class name change.
31 * 09/03/97 helena Added createCollationKeyValues().
32 * 02/10/98 damiba Added compare() with length as parameter.
33 * 04/23/99 stephen Removed EDecompositionMode, merged with
34 * Normalizer::EMode.
35 * 11/02/99 helena Collator performance enhancements. Eliminates the
36 * UnicodeString construction and special case for NO_OP.
37 * 11/23/99 srl More performance enhancements. Inlining of
38 * critical accessors.
39 * 05/15/00 helena Added version information API.
40 * 01/29/01 synwee Modified into a C++ wrapper which calls C apis
41 * (ucoll.h).
42 */
43
44 #ifndef COLL_H
45 #define COLL_H
46
47 #include "unicode/utypes.h"
48
49 #if !UCONFIG_NO_COLLATION
50
51 #include "unicode/uobject.h"
52 #include "unicode/ucol.h"
53 #include "unicode/normlzr.h"
54 #include "unicode/locid.h"
55 #include "unicode/uniset.h"
56
57 U_NAMESPACE_BEGIN
58
59 class StringEnumeration;
60
61 #if !UCONFIG_NO_SERVICE
62 /**
63 * @stable ICU 2.6
64 */
65 typedef const void* URegistryKey;
66
67 /**
68 * @stable ICU 2.6
69 */
70 class CollatorFactory;
71 #endif
72
73 /**
74 * @stable ICU 2.0
75 */
76 class CollationKey;
77
78 /**
79 * The <code>Collator</code> class performs locale-sensitive string
80 * comparison.<br>
81 * You use this class to build searching and sorting routines for natural
82 * language text.<br>
83 * <em>Important: </em>The ICU collation service has been reimplemented
84 * in order to achieve better performance and UCA compliance.
85 * For details, see the
86 * <a href="http://oss.software.ibm.com/cvs/icu/~checkout~/icuhtml/design/collation/ICU_collation_design.htm">
87 * collation design document</a>.
88 * <p>
89 * <code>Collator</code> is an abstract base class. Subclasses implement
90 * specific collation strategies. One subclass,
91 * <code>RuleBasedCollator</code>, is currently provided and is applicable
92 * to a wide set of languages. Other subclasses may be created to handle more
93 * specialized needs.
94 * <p>
95 * Like other locale-sensitive classes, you can use the static factory method,
96 * <code>createInstance</code>, to obtain the appropriate
97 * <code>Collator</code> object for a given locale. You will only need to
98 * look at the subclasses of <code>Collator</code> if you need to
99 * understand the details of a particular collation strategy or if you need to
100 * modify that strategy.
101 * <p>
102 * The following example shows how to compare two strings using the
103 * <code>Collator</code> for the default locale.
104 * \htmlonly<blockquote>\endhtmlonly
105 * <pre>
106 * \code
107 * // Compare two strings in the default locale
108 * UErrorCode success = U_ZERO_ERROR;
109 * Collator* myCollator = Collator::createInstance(success);
110 * if (myCollator->compare("abc", "ABC") < 0)
111 * cout << "abc is less than ABC" << endl;
112 * else
113 * cout << "abc is greater than or equal to ABC" << endl;
114 * \endcode
115 * </pre>
116 * \htmlonly</blockquote>\endhtmlonly
117 * <p>
118 * You can set a <code>Collator</code>'s <em>strength</em> property to
119 * determine the level of difference considered significant in comparisons.
120 * Five strengths are provided: <code>PRIMARY</code>, <code>SECONDARY</code>,
121 * <code>TERTIARY</code>, <code>QUATERNARY</code> and <code>IDENTICAL</code>.
122 * The exact assignment of strengths to language features is locale dependant.
123 * For example, in Czech, "e" and "f" are considered primary differences,
124 * while "e" and "\u00EA" are secondary differences, "e" and "E" are tertiary
125 * differences and "e" and "e" are identical. The following shows how both case
126 * and accents could be ignored for US English.
127 * \htmlonly<blockquote>\endhtmlonly
128 * <pre>
129 * \code
130 * //Get the Collator for US English and set its strength to PRIMARY
131 * UErrorCode success = U_ZERO_ERROR;
132 * Collator* usCollator = Collator::createInstance(Locale::US, success);
133 * usCollator->setStrength(Collator::PRIMARY);
134 * if (usCollator->compare("abc", "ABC") == 0)
135 * cout << "'abc' and 'ABC' strings are equivalent with strength PRIMARY" << endl;
136 * \endcode
137 * </pre>
138 * \htmlonly</blockquote>\endhtmlonly
139 * <p>
140 * For comparing strings exactly once, the <code>compare</code> method
141 * provides the best performance. When sorting a list of strings however, it
142 * is generally necessary to compare each string multiple times. In this case,
143 * sort keys provide better performance. The <code>getSortKey</code> methods
144 * convert a string to a series of bytes that can be compared bitwise against
145 * other sort keys using <code>strcmp()</code>. Sort keys are written as
146 * zero-terminated byte strings. They consist of several substrings, one for
147 * each collation strength level, that are delimited by 0x01 bytes.
148 * If the string code points are appended for UCOL_IDENTICAL, then they are
149 * processed for correct code point order comparison and may contain 0x01
150 * bytes but not zero bytes.
151 * </p>
152 * <p>
153 * An older set of APIs returns a <code>CollationKey</code> object that wraps
154 * the sort key bytes instead of returning the bytes themselves.
155 * Its use is deprecated, but it is still available for compatibility with
156 * Java.
157 * </p>
158 * <p>
159 * <strong>Note:</strong> <code>Collator</code>s with different Locale,
160 * and CollationStrength settings will return different sort
161 * orders for the same set of strings. Locales have specific collation rules,
162 * and the way in which secondary and tertiary differences are taken into
163 * account, for example, will result in a different sorting order for same
164 * strings.
165 * </p>
166 * @see RuleBasedCollator
167 * @see CollationKey
168 * @see CollationElementIterator
169 * @see Locale
170 * @see Normalizer
171 * @version 2.0 11/15/01
172 */
173
174 class U_I18N_API Collator : public UObject {
175 public:
176
177 // Collator public enums -----------------------------------------------
178
179 /**
180 * Base letter represents a primary difference. Set comparison level to
181 * PRIMARY to ignore secondary and tertiary differences.<br>
182 * Use this to set the strength of a Collator object.<br>
183 * Example of primary difference, "abc" &lt; "abd"
184 *
185 * Diacritical differences on the same base letter represent a secondary
186 * difference. Set comparison level to SECONDARY to ignore tertiary
187 * differences. Use this to set the strength of a Collator object.<br>
188 * Example of secondary difference, "ä" >> "a".
189 *
190 * Uppercase and lowercase versions of the same character represents a
191 * tertiary difference. Set comparison level to TERTIARY to include all
192 * comparison differences. Use this to set the strength of a Collator
193 * object.<br>
194 * Example of tertiary difference, "abc" &lt;&lt;&lt; "ABC".
195 *
196 * Two characters are considered "identical" when they have the same unicode
197 * spellings.<br>
198 * For example, "ä" == "ä".
199 *
200 * UCollationStrength is also used to determine the strength of sort keys
201 * generated from Collator objects.
202 * @stable ICU 2.0
203 */
204 enum ECollationStrength
205 {
206 PRIMARY = 0,
207 SECONDARY = 1,
208 TERTIARY = 2,
209 QUATERNARY = 3,
210 IDENTICAL = 15
211 };
212
213 /**
214 * LESS is returned if source string is compared to be less than target
215 * string in the compare() method.
216 * EQUAL is returned if source string is compared to be equal to target
217 * string in the compare() method.
218 * GREATER is returned if source string is compared to be greater than
219 * target string in the compare() method.
220 * @see Collator#compare
221 * @deprecated ICU 2.6. Use C enum UCollationResult defined in ucol.h
222 */
223 enum EComparisonResult
224 {
225 LESS = -1,
226 EQUAL = 0,
227 GREATER = 1
228 };
229
230 // Collator public destructor -----------------------------------------
231
232 /**
233 * Destructor
234 * @stable ICU 2.0
235 */
236 virtual ~Collator();
237
238 // Collator public methods --------------------------------------------
239
240 /**
241 * Returns true if "other" is the same as "this"
242 * @param other Collator object to be compared
243 * @return true if other is the same as this.
244 * @stable ICU 2.0
245 */
246 virtual UBool operator==(const Collator& other) const;
247
248 /**
249 * Returns true if "other" is not the same as "this".
250 * @param other Collator object to be compared
251 * @return true if other is not the same as this.
252 * @stable ICU 2.0
253 */
254 virtual UBool operator!=(const Collator& other) const;
255
256 /**
257 * Makes a shallow copy of the current object.
258 * @return a copy of this object
259 * @stable ICU 2.0
260 */
261 virtual Collator* clone(void) const = 0;
262
263 /**
264 * Creates the Collator object for the current default locale.
265 * The default locale is determined by Locale::getDefault.
266 * The UErrorCode& err parameter is used to return status information to the user.
267 * To check whether the construction succeeded or not, you should check the
268 * value of U_SUCCESS(err). If you wish more detailed information, you can
269 * check for informational error results which still indicate success.
270 * U_USING_FALLBACK_ERROR indicates that a fall back locale was used. For
271 * example, 'de_CH' was requested, but nothing was found there, so 'de' was
272 * used. U_USING_DEFAULT_ERROR indicates that the default locale data was
273 * used; neither the requested locale nor any of its fall back locales
274 * could be found.
275 * The caller owns the returned object and is responsible for deleting it.
276 *
277 * @param err the error code status.
278 * @return the collation object of the default locale.(for example, en_US)
279 * @see Locale#getDefault
280 * @stable ICU 2.0
281 */
282 static Collator* U_EXPORT2 createInstance(UErrorCode& err);
283
284 /**
285 * Gets the table-based collation object for the desired locale. The
286 * resource of the desired locale will be loaded by ResourceLoader.
287 * Locale::ENGLISH is the base collation table and all other languages are
288 * built on top of it with additional language-specific modifications.
289 * The UErrorCode& err parameter is used to return status information to the user.
290 * To check whether the construction succeeded or not, you should check
291 * the value of U_SUCCESS(err). If you wish more detailed information, you
292 * can check for informational error results which still indicate success.
293 * U_USING_FALLBACK_ERROR indicates that a fall back locale was used. For
294 * example, 'de_CH' was requested, but nothing was found there, so 'de' was
295 * used. U_USING_DEFAULT_ERROR indicates that the default locale data was
296 * used; neither the requested locale nor any of its fall back locales
297 * could be found.
298 * The caller owns the returned object and is responsible for deleting it.
299 * @param loc The locale ID for which to open a collator.
300 * @param err the error code status.
301 * @return the created table-based collation object based on the desired
302 * locale.
303 * @see Locale
304 * @see ResourceLoader
305 * @stable ICU 2.2
306 */
307 static Collator* U_EXPORT2 createInstance(const Locale& loc, UErrorCode& err);
308
309 #ifdef U_USE_COLLATION_OBSOLETE_2_6
310 /**
311 * Create a Collator with a specific version.
312 * This is the same as createInstance(loc, err) except that getVersion() of
313 * the returned object is guaranteed to be the same as the version
314 * parameter.
315 * This is designed to be used to open the same collator for a given
316 * locale even when ICU is updated.
317 * The same locale and version guarantees the same sort keys and
318 * comparison results.
319 * <p>
320 * Note: this API will be removed in a future release. Use
321 * <tt>createInstance(const Locale&, UErrorCode&) instead.</tt></p>
322 *
323 * @param loc The locale ID for which to open a collator.
324 * @param version The requested collator version.
325 * @param err A reference to a UErrorCode,
326 * must not indicate a failure before calling this function.
327 * @return A pointer to a Collator, or 0 if an error occurred
328 * or a collator with the requested version is not available.
329 *
330 * @see getVersion
331 * @obsolete ICU 2.6
332 */
333 static Collator *createInstance(const Locale &loc, UVersionInfo version, UErrorCode &err);
334 #endif
335
336 /**
337 * The comparison function compares the character data stored in two
338 * different strings. Returns information about whether a string is less
339 * than, greater than or equal to another string.
340 * @param source the source string to be compared with.
341 * @param target the string that is to be compared with the source string.
342 * @return Returns a byte value. GREATER if source is greater
343 * than target; EQUAL if source is equal to target; LESS if source is less
344 * than target
345 * @deprecated ICU 2.6 use the overload with UErrorCode &
346 */
347 virtual EComparisonResult compare(const UnicodeString& source,
348 const UnicodeString& target) const;
349
350 /**
351 * The comparison function compares the character data stored in two
352 * different strings. Returns information about whether a string is less
353 * than, greater than or equal to another string.
354 * @param source the source string to be compared with.
355 * @param target the string that is to be compared with the source string.
356 * @param status possible error code
357 * @return Returns an enum value. UCOL_GREATER if source is greater
358 * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source is less
359 * than target
360 * @stable ICU 2.6
361 */
362 virtual UCollationResult compare(const UnicodeString& source,
363 const UnicodeString& target,
364 UErrorCode &status) const = 0;
365
366 /**
367 * Does the same thing as compare but limits the comparison to a specified
368 * length
369 * @param source the source string to be compared with.
370 * @param target the string that is to be compared with the source string.
371 * @param length the length the comparison is limited to
372 * @return Returns a byte value. GREATER if source (up to the specified
373 * length) is greater than target; EQUAL if source (up to specified
374 * length) is equal to target; LESS if source (up to the specified
375 * length) is less than target.
376 * @deprecated ICU 2.6 use the overload with UErrorCode &
377 */
378 virtual EComparisonResult compare(const UnicodeString& source,
379 const UnicodeString& target,
380 int32_t length) const;
381
382 /**
383 * Does the same thing as compare but limits the comparison to a specified
384 * length
385 * @param source the source string to be compared with.
386 * @param target the string that is to be compared with the source string.
387 * @param length the length the comparison is limited to
388 * @param status possible error code
389 * @return Returns an enum value. UCOL_GREATER if source (up to the specified
390 * length) is greater than target; UCOL_EQUAL if source (up to specified
391 * length) is equal to target; UCOL_LESS if source (up to the specified
392 * length) is less than target.
393 * @stable ICU 2.6
394 */
395 virtual UCollationResult compare(const UnicodeString& source,
396 const UnicodeString& target,
397 int32_t length,
398 UErrorCode &status) const = 0;
399
400 /**
401 * The comparison function compares the character data stored in two
402 * different string arrays. Returns information about whether a string array
403 * is less than, greater than or equal to another string array.
404 * @param source the source string array to be compared with.
405 * @param sourceLength the length of the source string array. If this value
406 * is equal to -1, the string array is null-terminated.
407 * @param target the string that is to be compared with the source string.
408 * @param targetLength the length of the target string array. If this value
409 * is equal to -1, the string array is null-terminated.
410 * @return Returns a byte value. GREATER if source is greater than target;
411 * EQUAL if source is equal to target; LESS if source is less than
412 * target
413 * @deprecated ICU 2.6 use the overload with UErrorCode &
414 */
415 virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
416 const UChar* target, int32_t targetLength)
417 const;
418
419 /**
420 * The comparison function compares the character data stored in two
421 * different string arrays. Returns information about whether a string array
422 * is less than, greater than or equal to another string array.
423 * @param source the source string array to be compared with.
424 * @param sourceLength the length of the source string array. If this value
425 * is equal to -1, the string array is null-terminated.
426 * @param target the string that is to be compared with the source string.
427 * @param targetLength the length of the target string array. If this value
428 * is equal to -1, the string array is null-terminated.
429 * @param status possible error code
430 * @return Returns an enum value. UCOL_GREATER if source is greater
431 * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source is less
432 * than target
433 * @stable ICU 2.6
434 */
435 virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
436 const UChar* target, int32_t targetLength,
437 UErrorCode &status) const = 0;
438
439 /**
440 * Transforms the string into a series of characters that can be compared
441 * with CollationKey::compareTo. It is not possible to restore the original
442 * string from the chars in the sort key. The generated sort key handles
443 * only a limited number of ignorable characters.
444 * <p>Use CollationKey::equals or CollationKey::compare to compare the
445 * generated sort keys.
446 * If the source string is null, a null collation key will be returned.
447 * @param source the source string to be transformed into a sort key.
448 * @param key the collation key to be filled in
449 * @param status the error code status.
450 * @return the collation key of the string based on the collation rules.
451 * @see CollationKey#compare
452 * @deprecated ICU 2.8 Use getSortKey(...) instead
453 */
454 virtual CollationKey& getCollationKey(const UnicodeString& source,
455 CollationKey& key,
456 UErrorCode& status) const = 0;
457
458 /**
459 * Transforms the string into a series of characters that can be compared
460 * with CollationKey::compareTo. It is not possible to restore the original
461 * string from the chars in the sort key. The generated sort key handles
462 * only a limited number of ignorable characters.
463 * <p>Use CollationKey::equals or CollationKey::compare to compare the
464 * generated sort keys.
465 * <p>If the source string is null, a null collation key will be returned.
466 * @param source the source string to be transformed into a sort key.
467 * @param sourceLength length of the collation key
468 * @param key the collation key to be filled in
469 * @param status the error code status.
470 * @return the collation key of the string based on the collation rules.
471 * @see CollationKey#compare
472 * @deprecated ICU 2.8 Use getSortKey(...) instead
473 */
474 virtual CollationKey& getCollationKey(const UChar*source,
475 int32_t sourceLength,
476 CollationKey& key,
477 UErrorCode& status) const = 0;
478 /**
479 * Generates the hash code for the collation object
480 * @stable ICU 2.0
481 */
482 virtual int32_t hashCode(void) const = 0;
483
484 /**
485 * Gets the locale of the Collator
486 *
487 * @param type can be either requested, valid or actual locale. For more
488 * information see the definition of ULocDataLocaleType in
489 * uloc.h
490 * @param status the error code status.
491 * @return locale where the collation data lives. If the collator
492 * was instantiated from rules, locale is empty.
493 * @deprecated ICU 2.8 This API is under consideration for revision
494 * in ICU 3.0.
495 */
496 virtual const Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0;
497
498 /**
499 * Convenience method for comparing two strings based on the collation rules.
500 * @param source the source string to be compared with.
501 * @param target the target string to be compared with.
502 * @return true if the first string is greater than the second one,
503 * according to the collation rules. false, otherwise.
504 * @see Collator#compare
505 * @stable ICU 2.0
506 */
507 UBool greater(const UnicodeString& source, const UnicodeString& target)
508 const;
509
510 /**
511 * Convenience method for comparing two strings based on the collation rules.
512 * @param source the source string to be compared with.
513 * @param target the target string to be compared with.
514 * @return true if the first string is greater than or equal to the second
515 * one, according to the collation rules. false, otherwise.
516 * @see Collator#compare
517 * @stable ICU 2.0
518 */
519 UBool greaterOrEqual(const UnicodeString& source,
520 const UnicodeString& target) const;
521
522 /**
523 * Convenience method for comparing two strings based on the collation rules.
524 * @param source the source string to be compared with.
525 * @param target the target string to be compared with.
526 * @return true if the strings are equal according to the collation rules.
527 * false, otherwise.
528 * @see Collator#compare
529 * @stable ICU 2.0
530 */
531 UBool equals(const UnicodeString& source, const UnicodeString& target) const;
532
533 /**
534 * Determines the minimum strength that will be use in comparison or
535 * transformation.
536 * <p>E.g. with strength == SECONDARY, the tertiary difference is ignored
537 * <p>E.g. with strength == PRIMARY, the secondary and tertiary difference
538 * are ignored.
539 * @return the current comparison level.
540 * @see Collator#setStrength
541 * @deprecated ICU 2.6 Use getAttribute(UCOL_STRENGTH...) instead
542 */
543 virtual ECollationStrength getStrength(void) const = 0;
544
545 /**
546 * Sets the minimum strength to be used in comparison or transformation.
547 * <p>Example of use:
548 * <pre>
549 * \code
550 * UErrorCode status = U_ZERO_ERROR;
551 * Collator*myCollation = Collator::createInstance(Locale::US, status);
552 * if (U_FAILURE(status)) return;
553 * myCollation->setStrength(Collator::PRIMARY);
554 * // result will be "abc" == "ABC"
555 * // tertiary differences will be ignored
556 * Collator::ComparisonResult result = myCollation->compare("abc", "ABC");
557 * \endcode
558 * </pre>
559 * @see Collator#getStrength
560 * @param newStrength the new comparison level.
561 * @deprecated ICU 2.6 Use setAttribute(UCOL_STRENGTH...) instead
562 */
563 virtual void setStrength(ECollationStrength newStrength) = 0;
564
565 /**
566 * Get name of the object for the desired Locale, in the desired langauge
567 * @param objectLocale must be from getAvailableLocales
568 * @param displayLocale specifies the desired locale for output
569 * @param name the fill-in parameter of the return value
570 * @return display-able name of the object for the object locale in the
571 * desired language
572 * @stable ICU 2.0
573 */
574 static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
575 const Locale& displayLocale,
576 UnicodeString& name);
577
578 /**
579 * Get name of the object for the desired Locale, in the langauge of the
580 * default locale.
581 * @param objectLocale must be from getAvailableLocales
582 * @param name the fill-in parameter of the return value
583 * @return name of the object for the desired locale in the default language
584 * @stable ICU 2.0
585 */
586 static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
587 UnicodeString& name);
588
589 /**
590 * Get the set of Locales for which Collations are installed.
591 *
592 * <p>Note this does not include locales supported by registered collators.
593 * If collators might have been registered, use the overload of getAvailableLocales
594 * that returns a StringEnumeration.</p>
595 *
596 * @param count the output parameter of number of elements in the locale list
597 * @return the list of available locales for which collations are installed
598 * @stable ICU 2.0
599 */
600 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
601
602 #if !UCONFIG_NO_SERVICE
603 /**
604 * Return a StringEnumeration over the locales available at the time of the call,
605 * including registered locales. If a severe error occurs (such as out of memory
606 * condition) this will return null. If there is no locale data, an empty enumeration
607 * will be returned.
608 * @return a StringEnumeration over the locales available at the time of the call
609 * @stable ICU 2.6
610 */
611 static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
612 #endif
613
614 /**
615 * Create a string enumerator of all possible keywords that are relevant to
616 * collation. At this point, the only recognized keyword for this
617 * service is "collation".
618 * @param status input-output error code
619 * @return a string enumeration over locale strings. The caller is
620 * responsible for closing the result.
621 * @draft ICU 3.0
622 */
623 static StringEnumeration* U_EXPORT2 getKeywords(UErrorCode& status);
624
625 /**
626 * Given a keyword, create a string enumeration of all values
627 * for that keyword that are currently in use.
628 * @param keyword a particular keyword as enumerated by
629 * ucol_getKeywords. If any other keyword is passed in, status is set
630 * to U_ILLEGAL_ARGUMENT_ERROR.
631 * @param status input-output error code
632 * @return a string enumeration over collation keyword values, or NULL
633 * upon error. The caller is responsible for deleting the result.
634 * @draft ICU 3.0
635 */
636 static StringEnumeration* U_EXPORT2 getKeywordValues(const char *keyword, UErrorCode& status);
637
638 /**
639 * Return the functionally equivalent locale for the given
640 * requested locale, with respect to given keyword, for the
641 * collation service. If two locales return the same result, then
642 * collators instantiated for these locales will behave
643 * equivalently. The converse is not always true; two collators
644 * may in fact be equivalent, but return different results, due to
645 * internal details. The return result has no other meaning than
646 * that stated above, and implies nothing as to the relationship
647 * between the two locales. This is intended for use by
648 * applications who wish to cache collators, or otherwise reuse
649 * collators when possible. The functional equivalent may change
650 * over time. For more information, please see the <a
651 * href="http://oss.software.ibm.com/icu/userguide/locale.html#services">
652 * Locales and Services</a> section of the ICU User Guide.
653 * @param keyword a particular keyword as enumerated by
654 * ucol_getKeywords.
655 * @param locale the requested locale
656 * @param isAvailable reference to a fillin parameter that
657 * indicates whether the requested locale was 'available' to the
658 * collation service. A locale is defined as 'available' if it
659 * physically exists within the collation locale data.
660 * @param status reference to input-output error code
661 * @return the functionally equivalent collation locale, or the root
662 * locale upon error.
663 * @draft ICU 3.0
664 */
665 static Locale U_EXPORT2 getFunctionalEquivalent(const char* keyword, const Locale& locale,
666 UBool& isAvailable, UErrorCode& status);
667
668 #if !UCONFIG_NO_SERVICE
669 /**
670 * Register a new Collator. The collator will be adopted.
671 * @param toAdopt the Collator instance to be adopted
672 * @param locale the locale with which the collator will be associated
673 * @param status the in/out status code, no special meanings are assigned
674 * @return a registry key that can be used to unregister this collator
675 * @stable ICU 2.6
676 */
677 static URegistryKey U_EXPORT2 registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status);
678
679 /**
680 * Register a new CollatorFactory. The factory will be adopted.
681 * @param toAdopt the CollatorFactory instance to be adopted
682 * @param status the in/out status code, no special meanings are assigned
683 * @return a registry key that can be used to unregister this collator
684 * @stable ICU 2.6
685 */
686 static URegistryKey U_EXPORT2 registerFactory(CollatorFactory* toAdopt, UErrorCode& status);
687
688 /**
689 * Unregister a previously-registered Collator or CollatorFactory
690 * using the key returned from the register call. Key becomes
691 * invalid after a successful call and should not be used again.
692 * The object corresponding to the key will be deleted.
693 * @param key the registry key returned by a previous call to registerInstance
694 * @param status the in/out status code, no special meanings are assigned
695 * @return TRUE if the collator for the key was successfully unregistered
696 * @stable ICU 2.6
697 */
698 static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
699 #endif /* UCONFIG_NO_SERVICE */
700
701 /**
702 * Gets the version information for a Collator.
703 * @param info the version # information, the result will be filled in
704 * @stable ICU 2.0
705 */
706 virtual void getVersion(UVersionInfo info) const = 0;
707
708 /**
709 * Returns a unique class ID POLYMORPHICALLY. Pure virtual method.
710 * This method is to implement a simple version of RTTI, since not all C++
711 * compilers support genuine RTTI. Polymorphic operator==() and clone()
712 * methods call this method.
713 * @return The class ID for this object. All objects of a given class have
714 * the same class ID. Objects of other classes have different class
715 * IDs.
716 * @stable ICU 2.0
717 */
718 virtual UClassID getDynamicClassID(void) const = 0;
719
720 /**
721 * Universal attribute setter
722 * @param attr attribute type
723 * @param value attribute value
724 * @param status to indicate whether the operation went on smoothly or
725 * there were errors
726 * @stable ICU 2.2
727 */
728 virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
729 UErrorCode &status) = 0;
730
731 /**
732 * Universal attribute getter
733 * @param attr attribute type
734 * @param status to indicate whether the operation went on smoothly or
735 * there were errors
736 * @return attribute value
737 * @stable ICU 2.2
738 */
739 virtual UColAttributeValue getAttribute(UColAttribute attr,
740 UErrorCode &status) = 0;
741
742 /**
743 * Sets the variable top to a collation element value of a string supplied.
744 * @param varTop one or more (if contraction) UChars to which the variable top should be set
745 * @param len length of variable top string. If -1 it is considered to be zero terminated.
746 * @param status error code. If error code is set, the return value is undefined. Errors set by this function are: <br>
747 * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such a contraction<br>
748 * U_PRIMARY_TOO_LONG_ERROR if the primary for the variable top has more than two bytes
749 * @return a 32 bit value containing the value of the variable top in upper 16 bits. Lower 16 bits are undefined
750 * @stable ICU 2.0
751 */
752 virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status) = 0;
753
754 /**
755 * Sets the variable top to a collation element value of a string supplied.
756 * @param varTop an UnicodeString size 1 or more (if contraction) of UChars to which the variable top should be set
757 * @param status error code. If error code is set, the return value is undefined. Errors set by this function are: <br>
758 * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such a contraction<br>
759 * U_PRIMARY_TOO_LONG_ERROR if the primary for the variable top has more than two bytes
760 * @return a 32 bit value containing the value of the variable top in upper 16 bits. Lower 16 bits are undefined
761 * @stable ICU 2.0
762 */
763 virtual uint32_t setVariableTop(const UnicodeString varTop, UErrorCode &status) = 0;
764
765 /**
766 * Sets the variable top to a collation element value supplied. Variable top is set to the upper 16 bits.
767 * Lower 16 bits are ignored.
768 * @param varTop CE value, as returned by setVariableTop or ucol)getVariableTop
769 * @param status error code (not changed by function)
770 * @stable ICU 2.0
771 */
772 virtual void setVariableTop(const uint32_t varTop, UErrorCode &status) = 0;
773
774 /**
775 * Gets the variable top value of a Collator.
776 * Lower 16 bits are undefined and should be ignored.
777 * @param status error code (not changed by function). If error code is set, the return value is undefined.
778 * @stable ICU 2.0
779 */
780 virtual uint32_t getVariableTop(UErrorCode &status) const = 0;
781
782 /**
783 * Get an UnicodeSet that contains all the characters and sequences
784 * tailored in this collator.
785 * @param status error code of the operation
786 * @return a pointer to a UnicodeSet object containing all the
787 * code points and sequences that may sort differently than
788 * in the UCA. The object must be disposed of by using delete
789 * @stable ICU 2.4
790 */
791 virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
792
793
794 /**
795 * Thread safe cloning operation
796 * @return pointer to the new clone, user should remove it.
797 * @stable ICU 2.2
798 */
799 virtual Collator* safeClone(void) = 0;
800
801 /**
802 * Get the sort key as an array of bytes from an UnicodeString.
803 * Sort key byte arrays are zero-terminated and can be compared using
804 * strcmp().
805 * @param source string to be processed.
806 * @param result buffer to store result in. If NULL, number of bytes needed
807 * will be returned.
808 * @param resultLength length of the result buffer. If if not enough the
809 * buffer will be filled to capacity.
810 * @return Number of bytes needed for storing the sort key
811 * @stable ICU 2.2
812 */
813 virtual int32_t getSortKey(const UnicodeString& source,
814 uint8_t* result,
815 int32_t resultLength) const = 0;
816
817 /**
818 * Get the sort key as an array of bytes from an UChar buffer.
819 * Sort key byte arrays are zero-terminated and can be compared using
820 * strcmp().
821 * @param source string to be processed.
822 * @param sourceLength length of string to be processed.
823 * If -1, the string is 0 terminated and length will be decided by the
824 * function.
825 * @param result buffer to store result in. If NULL, number of bytes needed
826 * will be returned.
827 * @param resultLength length of the result buffer. If if not enough the
828 * buffer will be filled to capacity.
829 * @return Number of bytes needed for storing the sort key
830 * @stable ICU 2.2
831 */
832 virtual int32_t getSortKey(const UChar*source, int32_t sourceLength,
833 uint8_t*result, int32_t resultLength) const = 0;
834
835 /**
836 * Produce a bound for a given sortkey and a number of levels.
837 * Return value is always the number of bytes needed, regardless of
838 * whether the result buffer was big enough or even valid.<br>
839 * Resulting bounds can be used to produce a range of strings that are
840 * between upper and lower bounds. For example, if bounds are produced
841 * for a sortkey of string "smith", strings between upper and lower
842 * bounds with one level would include "Smith", "SMITH", "sMiTh".<br>
843 * There are two upper bounds that can be produced. If UCOL_BOUND_UPPER
844 * is produced, strings matched would be as above. However, if bound
845 * produced using UCOL_BOUND_UPPER_LONG is used, the above example will
846 * also match "Smithsonian" and similar.<br>
847 * For more on usage, see example in cintltst/capitst.c in procedure
848 * TestBounds.
849 * Sort keys may be compared using <TT>strcmp</TT>.
850 * @param source The source sortkey.
851 * @param sourceLength The length of source, or -1 if null-terminated.
852 * (If an unmodified sortkey is passed, it is always null
853 * terminated).
854 * @param boundType Type of bound required. It can be UCOL_BOUND_LOWER, which
855 * produces a lower inclusive bound, UCOL_BOUND_UPPER, that
856 * produces upper bound that matches strings of the same length
857 * or UCOL_BOUND_UPPER_LONG that matches strings that have the
858 * same starting substring as the source string.
859 * @param noOfLevels Number of levels required in the resulting bound (for most
860 * uses, the recommended value is 1). See users guide for
861 * explanation on number of levels a sortkey can have.
862 * @param result A pointer to a buffer to receive the resulting sortkey.
863 * @param resultLength The maximum size of result.
864 * @param status Used for returning error code if something went wrong. If the
865 * number of levels requested is higher than the number of levels
866 * in the source key, a warning (U_SORT_KEY_TOO_SHORT_WARNING) is
867 * issued.
868 * @return The size needed to fully store the bound.
869 * @see ucol_keyHashCode
870 * @stable ICU 2.1
871 */
872 static int32_t U_EXPORT2 getBound(const uint8_t *source,
873 int32_t sourceLength,
874 UColBoundMode boundType,
875 uint32_t noOfLevels,
876 uint8_t *result,
877 int32_t resultLength,
878 UErrorCode &status);
879
880
881 protected:
882
883 // Collator protected constructors -------------------------------------
884
885 /**
886 * Default constructor.
887 * Constructor is different from the old default Collator constructor.
888 * The task for determing the default collation strength and normalization
889 * mode is left to the child class.
890 * @stable ICU 2.0
891 */
892 Collator();
893
894 /**
895 * Constructor.
896 * Empty constructor, does not handle the arguments.
897 * This constructor is done for backward compatibility with 1.7 and 1.8.
898 * The task for handling the argument collation strength and normalization
899 * mode is left to the child class.
900 * @param collationStrength collation strength
901 * @param decompositionMode
902 * @deprecated ICU 2.4. Subclasses should use the default constructor
903 * instead and handle the strength and normalization mode themselves.
904 */
905 Collator(UCollationStrength collationStrength,
906 UNormalizationMode decompositionMode);
907
908 /**
909 * Copy constructor.
910 * @param other Collator object to be copied from
911 * @stable ICU 2.0
912 */
913 Collator(const Collator& other);
914
915 // Collator protected methods -----------------------------------------
916
917
918 /**
919 * Used internally by registraton to define the requested and valid locales.
920 * @param requestedLocale the requsted locale
921 * @param validLocale the valid locale
922 * @internal
923 */
924 virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale);
925
926 public:
927 #if !UCONFIG_NO_SERVICE
928 /**
929 * used only by ucol_open, not for public use
930 * @internal
931 */
932 static UCollator* createUCollator(const char* loc, UErrorCode* status);
933 #endif
934 private:
935 /**
936 * Assignment operator. Private for now.
937 * @internal
938 */
939 Collator& operator=(const Collator& other);
940
941 friend class CFactory;
942 friend class SimpleCFactory;
943 friend class ICUCollatorFactory;
944 friend class ICUCollatorService;
945 static Collator* makeInstance(const Locale& desiredLocale,
946 UErrorCode& status);
947
948 // Collator private data members ---------------------------------------
949
950 /*
951 synwee : removed as attributes to be handled by child class
952 UCollationStrength strength;
953 Normalizer::EMode decmp;
954 */
955 /* This is useless information */
956 /* static const UVersionInfo fVersion;*/
957 };
958
959 #if !UCONFIG_NO_SERVICE
960 /**
961 * A factory, used with registerFactory, the creates multiple collators and provides
962 * display names for them. A factory supports some number of locales-- these are the
963 * locales for which it can create collators. The factory can be visible, in which
964 * case the supported locales will be enumerated by getAvailableLocales, or invisible,
965 * in which they are not. Invisible locales are still supported, they are just not
966 * listed by getAvailableLocales.
967 * <p>
968 * If standard locale display names are sufficient, Collator instances can
969 * be registered using registerInstance instead.</p>
970 * <p>
971 * Note: if the collators are to be used from C APIs, they must be instances
972 * of RuleBasedCollator.</p>
973 *
974 * @stable ICU 2.6
975 */
976 class U_I18N_API CollatorFactory : public UObject {
977 public:
978
979 /**
980 * Destructor
981 * @draft ICU 3.0
982 */
983 virtual ~CollatorFactory();
984
985 /**
986 * Return true if this factory is visible. Default is true.
987 * If not visible, the locales supported by this factory will not
988 * be listed by getAvailableLocales.
989 * @return true if the factory is visible.
990 * @stable ICU 2.6
991 */
992 virtual UBool visible(void) const;
993
994 /**
995 * Return a collator for the provided locale. If the locale
996 * is not supported, return NULL.
997 * @param loc the locale identifying the collator to be created.
998 * @return a new collator if the locale is supported, otherwise NULL.
999 * @stable ICU 2.6
1000 */
1001 virtual Collator* createCollator(const Locale& loc) = 0;
1002
1003 /**
1004 * Return the name of the collator for the objectLocale, localized for the displayLocale.
1005 * If objectLocale is not supported, or the factory is not visible, set the result string
1006 * to bogus.
1007 * @param objectLocale the locale identifying the collator
1008 * @param displayLocale the locale for which the display name of the collator should be localized
1009 * @param result an output parameter for the display name, set to bogus if not supported.
1010 * @return the display name
1011 * @stable ICU 2.6
1012 */
1013 virtual UnicodeString& getDisplayName(const Locale& objectLocale,
1014 const Locale& displayLocale,
1015 UnicodeString& result);
1016
1017 /**
1018 * Return an array of all the locale names directly supported by this factory.
1019 * The number of names is returned in count. This array is owned by the factory.
1020 * Its contents must never change.
1021 * @param count output parameter for the number of locales supported by the factory
1022 * @param status the in/out error code
1023 * @return a pointer to an array of count UnicodeStrings.
1024 * @stable ICU 2.6
1025 */
1026 virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
1027 };
1028 #endif /* UCONFIG_NO_SERVICE */
1029
1030 // Collator inline methods -----------------------------------------------
1031
1032 U_NAMESPACE_END
1033
1034 #endif /* #if !UCONFIG_NO_COLLATION */
1035
1036 #endif