2 ******************************************************************************
3 * Copyright (C) 1996-2006, International Business Machines *
4 * Corporation and others. All Rights Reserved. *
5 ******************************************************************************
11 * Created by: Helena Shih
13 * Modification History:
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
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
39 * 05/15/00 helena Added version information API.
40 * 01/29/01 synwee Modified into a C++ wrapper which calls C apis
47 #include "unicode/utypes.h"
51 * \brief C++ API: Collation Service.
54 #if !UCONFIG_NO_COLLATION
56 #include "unicode/uobject.h"
57 #include "unicode/ucol.h"
58 #include "unicode/normlzr.h"
59 #include "unicode/locid.h"
60 #include "unicode/uniset.h"
61 #include "unicode/umisc.h"
65 class StringEnumeration
;
67 #if !UCONFIG_NO_SERVICE
71 class CollatorFactory
;
80 * The <code>Collator</code> class performs locale-sensitive string
82 * You use this class to build searching and sorting routines for natural
84 * <em>Important: </em>The ICU collation service has been reimplemented
85 * in order to achieve better performance and UCA compliance.
86 * For details, see the
87 * <a href="http://dev.icu-project.org/cgi-bin/viewcvs.cgi/~checkout~/icuhtml/design/collation/ICU_collation_design.htm">
88 * collation design document</a>.
90 * <code>Collator</code> is an abstract base class. Subclasses implement
91 * specific collation strategies. One subclass,
92 * <code>RuleBasedCollator</code>, is currently provided and is applicable
93 * to a wide set of languages. Other subclasses may be created to handle more
96 * Like other locale-sensitive classes, you can use the static factory method,
97 * <code>createInstance</code>, to obtain the appropriate
98 * <code>Collator</code> object for a given locale. You will only need to
99 * look at the subclasses of <code>Collator</code> if you need to
100 * understand the details of a particular collation strategy or if you need to
101 * modify that strategy.
103 * The following example shows how to compare two strings using the
104 * <code>Collator</code> for the default locale.
105 * \htmlonly<blockquote>\endhtmlonly
108 * // Compare two strings in the default locale
109 * UErrorCode success = U_ZERO_ERROR;
110 * Collator* myCollator = Collator::createInstance(success);
111 * if (myCollator->compare("abc", "ABC") < 0)
112 * cout << "abc is less than ABC" << endl;
114 * cout << "abc is greater than or equal to ABC" << endl;
117 * \htmlonly</blockquote>\endhtmlonly
119 * You can set a <code>Collator</code>'s <em>strength</em> property to
120 * determine the level of difference considered significant in comparisons.
121 * Five strengths are provided: <code>PRIMARY</code>, <code>SECONDARY</code>,
122 * <code>TERTIARY</code>, <code>QUATERNARY</code> and <code>IDENTICAL</code>.
123 * The exact assignment of strengths to language features is locale dependant.
124 * For example, in Czech, "e" and "f" are considered primary differences,
125 * while "e" and "\u00EA" are secondary differences, "e" and "E" are tertiary
126 * differences and "e" and "e" are identical. The following shows how both case
127 * and accents could be ignored for US English.
128 * \htmlonly<blockquote>\endhtmlonly
131 * //Get the Collator for US English and set its strength to PRIMARY
132 * UErrorCode success = U_ZERO_ERROR;
133 * Collator* usCollator = Collator::createInstance(Locale::US, success);
134 * usCollator->setStrength(Collator::PRIMARY);
135 * if (usCollator->compare("abc", "ABC") == 0)
136 * cout << "'abc' and 'ABC' strings are equivalent with strength PRIMARY" << endl;
139 * \htmlonly</blockquote>\endhtmlonly
141 * For comparing strings exactly once, the <code>compare</code> method
142 * provides the best performance. When sorting a list of strings however, it
143 * is generally necessary to compare each string multiple times. In this case,
144 * sort keys provide better performance. The <code>getSortKey</code> methods
145 * convert a string to a series of bytes that can be compared bitwise against
146 * other sort keys using <code>strcmp()</code>. Sort keys are written as
147 * zero-terminated byte strings. They consist of several substrings, one for
148 * each collation strength level, that are delimited by 0x01 bytes.
149 * If the string code points are appended for UCOL_IDENTICAL, then they are
150 * processed for correct code point order comparison and may contain 0x01
151 * bytes but not zero bytes.
154 * An older set of APIs returns a <code>CollationKey</code> object that wraps
155 * the sort key bytes instead of returning the bytes themselves.
156 * Its use is deprecated, but it is still available for compatibility with
160 * <strong>Note:</strong> <code>Collator</code>s with different Locale,
161 * and CollationStrength settings will return different sort
162 * orders for the same set of strings. Locales have specific collation rules,
163 * and the way in which secondary and tertiary differences are taken into
164 * account, for example, will result in a different sorting order for same
167 * @see RuleBasedCollator
169 * @see CollationElementIterator
172 * @version 2.0 11/15/01
175 class U_I18N_API Collator
: public UObject
{
178 // Collator public enums -----------------------------------------------
181 * Base letter represents a primary difference. Set comparison level to
182 * PRIMARY to ignore secondary and tertiary differences.<br>
183 * Use this to set the strength of a Collator object.<br>
184 * Example of primary difference, "abc" < "abd"
186 * Diacritical differences on the same base letter represent a secondary
187 * difference. Set comparison level to SECONDARY to ignore tertiary
188 * differences. Use this to set the strength of a Collator object.<br>
189 * Example of secondary difference, "ä" >> "a".
191 * Uppercase and lowercase versions of the same character represents a
192 * tertiary difference. Set comparison level to TERTIARY to include all
193 * comparison differences. Use this to set the strength of a Collator
195 * Example of tertiary difference, "abc" <<< "ABC".
197 * Two characters are considered "identical" when they have the same unicode
199 * For example, "ä" == "ä".
201 * UCollationStrength is also used to determine the strength of sort keys
202 * generated from Collator objects.
205 enum ECollationStrength
215 * LESS is returned if source string is compared to be less than target
216 * string in the compare() method.
217 * EQUAL is returned if source string is compared to be equal to target
218 * string in the compare() method.
219 * GREATER is returned if source string is compared to be greater than
220 * target string in the compare() method.
221 * @see Collator#compare
222 * @deprecated ICU 2.6. Use C enum UCollationResult defined in ucol.h
224 enum EComparisonResult
231 // Collator public destructor -----------------------------------------
239 // Collator public methods --------------------------------------------
242 * Returns true if "other" is the same as "this"
243 * @param other Collator object to be compared
244 * @return true if other is the same as this.
247 virtual UBool
operator==(const Collator
& other
) const;
250 * Returns true if "other" is not the same as "this".
251 * @param other Collator object to be compared
252 * @return true if other is not the same as this.
255 virtual UBool
operator!=(const Collator
& other
) const;
258 * Makes a shallow copy of the current object.
259 * @return a copy of this object
262 virtual Collator
* clone(void) const = 0;
265 * Creates the Collator object for the current default locale.
266 * The default locale is determined by Locale::getDefault.
267 * The UErrorCode& err parameter is used to return status information to the user.
268 * To check whether the construction succeeded or not, you should check the
269 * value of U_SUCCESS(err). If you wish more detailed information, you can
270 * check for informational error results which still indicate success.
271 * U_USING_FALLBACK_ERROR indicates that a fall back locale was used. For
272 * example, 'de_CH' was requested, but nothing was found there, so 'de' was
273 * used. U_USING_DEFAULT_ERROR indicates that the default locale data was
274 * used; neither the requested locale nor any of its fall back locales
276 * The caller owns the returned object and is responsible for deleting it.
278 * @param err the error code status.
279 * @return the collation object of the default locale.(for example, en_US)
280 * @see Locale#getDefault
283 static Collator
* U_EXPORT2
createInstance(UErrorCode
& err
);
286 * Gets the table-based collation object for the desired locale. The
287 * resource of the desired locale will be loaded by ResourceLoader.
288 * Locale::ENGLISH is the base collation table and all other languages are
289 * built on top of it with additional language-specific modifications.
290 * The UErrorCode& err parameter is used to return status information to the user.
291 * To check whether the construction succeeded or not, you should check
292 * the value of U_SUCCESS(err). If you wish more detailed information, you
293 * can check for informational error results which still indicate success.
294 * U_USING_FALLBACK_ERROR indicates that a fall back locale was used. For
295 * example, 'de_CH' was requested, but nothing was found there, so 'de' was
296 * used. U_USING_DEFAULT_ERROR indicates that the default locale data was
297 * used; neither the requested locale nor any of its fall back locales
299 * The caller owns the returned object and is responsible for deleting it.
300 * @param loc The locale ID for which to open a collator.
301 * @param err the error code status.
302 * @return the created table-based collation object based on the desired
305 * @see ResourceLoader
308 static Collator
* U_EXPORT2
createInstance(const Locale
& loc
, UErrorCode
& err
);
310 #ifdef U_USE_COLLATION_OBSOLETE_2_6
312 * Create a Collator with a specific version.
313 * This is the same as createInstance(loc, err) except that getVersion() of
314 * the returned object is guaranteed to be the same as the version
316 * This is designed to be used to open the same collator for a given
317 * locale even when ICU is updated.
318 * The same locale and version guarantees the same sort keys and
319 * comparison results.
321 * Note: this API will be removed in a future release. Use
322 * <tt>createInstance(const Locale&, UErrorCode&) instead.</tt></p>
324 * @param loc The locale ID for which to open a collator.
325 * @param version The requested collator version.
326 * @param err A reference to a UErrorCode,
327 * must not indicate a failure before calling this function.
328 * @return A pointer to a Collator, or 0 if an error occurred
329 * or a collator with the requested version is not available.
334 static Collator
*createInstance(const Locale
&loc
, UVersionInfo version
, UErrorCode
&err
);
338 * The comparison function compares the character data stored in two
339 * different strings. Returns information about whether a string is less
340 * than, greater than or equal to another string.
341 * @param source the source string to be compared with.
342 * @param target the string that is to be compared with the source string.
343 * @return Returns a byte value. GREATER if source is greater
344 * than target; EQUAL if source is equal to target; LESS if source is less
346 * @deprecated ICU 2.6 use the overload with UErrorCode &
348 virtual EComparisonResult
compare(const UnicodeString
& source
,
349 const UnicodeString
& target
) const;
352 * The comparison function compares the character data stored in two
353 * different strings. Returns information about whether a string is less
354 * than, greater than or equal to another string.
355 * @param source the source string to be compared with.
356 * @param target the string that is to be compared with the source string.
357 * @param status possible error code
358 * @return Returns an enum value. UCOL_GREATER if source is greater
359 * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source is less
363 virtual UCollationResult
compare(const UnicodeString
& source
,
364 const UnicodeString
& target
,
365 UErrorCode
&status
) const = 0;
368 * Does the same thing as compare but limits the comparison to a specified
370 * @param source the source string to be compared with.
371 * @param target the string that is to be compared with the source string.
372 * @param length the length the comparison is limited to
373 * @return Returns a byte value. GREATER if source (up to the specified
374 * length) is greater than target; EQUAL if source (up to specified
375 * length) is equal to target; LESS if source (up to the specified
376 * length) is less than target.
377 * @deprecated ICU 2.6 use the overload with UErrorCode &
379 virtual EComparisonResult
compare(const UnicodeString
& source
,
380 const UnicodeString
& target
,
381 int32_t length
) const;
384 * Does the same thing as compare but limits the comparison to a specified
386 * @param source the source string to be compared with.
387 * @param target the string that is to be compared with the source string.
388 * @param length the length the comparison is limited to
389 * @param status possible error code
390 * @return Returns an enum value. UCOL_GREATER if source (up to the specified
391 * length) is greater than target; UCOL_EQUAL if source (up to specified
392 * length) is equal to target; UCOL_LESS if source (up to the specified
393 * length) is less than target.
396 virtual UCollationResult
compare(const UnicodeString
& source
,
397 const UnicodeString
& target
,
399 UErrorCode
&status
) const = 0;
402 * The comparison function compares the character data stored in two
403 * different string arrays. Returns information about whether a string array
404 * is less than, greater than or equal to another string array.
405 * @param source the source string array to be compared with.
406 * @param sourceLength the length of the source string array. If this value
407 * is equal to -1, the string array is null-terminated.
408 * @param target the string that is to be compared with the source string.
409 * @param targetLength the length of the target string array. If this value
410 * is equal to -1, the string array is null-terminated.
411 * @return Returns a byte value. GREATER if source is greater than target;
412 * EQUAL if source is equal to target; LESS if source is less than
414 * @deprecated ICU 2.6 use the overload with UErrorCode &
416 virtual EComparisonResult
compare(const UChar
* source
, int32_t sourceLength
,
417 const UChar
* target
, int32_t targetLength
)
421 * The comparison function compares the character data stored in two
422 * different string arrays. Returns information about whether a string array
423 * is less than, greater than or equal to another string array.
424 * @param source the source string array to be compared with.
425 * @param sourceLength the length of the source string array. If this value
426 * is equal to -1, the string array is null-terminated.
427 * @param target the string that is to be compared with the source string.
428 * @param targetLength the length of the target string array. If this value
429 * is equal to -1, the string array is null-terminated.
430 * @param status possible error code
431 * @return Returns an enum value. UCOL_GREATER if source is greater
432 * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source is less
436 virtual UCollationResult
compare(const UChar
* source
, int32_t sourceLength
,
437 const UChar
* target
, int32_t targetLength
,
438 UErrorCode
&status
) const = 0;
441 * Transforms the string into a series of characters that can be compared
442 * with CollationKey::compareTo. It is not possible to restore the original
443 * string from the chars in the sort key. The generated sort key handles
444 * only a limited number of ignorable characters.
445 * <p>Use CollationKey::equals or CollationKey::compare to compare the
446 * generated sort keys.
447 * If the source string is null, a null collation key will be returned.
448 * @param source the source string to be transformed into a sort key.
449 * @param key the collation key to be filled in
450 * @param status the error code status.
451 * @return the collation key of the string based on the collation rules.
452 * @see CollationKey#compare
453 * @deprecated ICU 2.8 Use getSortKey(...) instead
455 virtual CollationKey
& getCollationKey(const UnicodeString
& source
,
457 UErrorCode
& status
) const = 0;
460 * Transforms the string into a series of characters that can be compared
461 * with CollationKey::compareTo. It is not possible to restore the original
462 * string from the chars in the sort key. The generated sort key handles
463 * only a limited number of ignorable characters.
464 * <p>Use CollationKey::equals or CollationKey::compare to compare the
465 * generated sort keys.
466 * <p>If the source string is null, a null collation key will be returned.
467 * @param source the source string to be transformed into a sort key.
468 * @param sourceLength length of the collation key
469 * @param key the collation key to be filled in
470 * @param status the error code status.
471 * @return the collation key of the string based on the collation rules.
472 * @see CollationKey#compare
473 * @deprecated ICU 2.8 Use getSortKey(...) instead
475 virtual CollationKey
& getCollationKey(const UChar
*source
,
476 int32_t sourceLength
,
478 UErrorCode
& status
) const = 0;
480 * Generates the hash code for the collation object
483 virtual int32_t hashCode(void) const = 0;
486 * Gets the locale of the Collator
488 * @param type can be either requested, valid or actual locale. For more
489 * information see the definition of ULocDataLocaleType in
491 * @param status the error code status.
492 * @return locale where the collation data lives. If the collator
493 * was instantiated from rules, locale is empty.
494 * @deprecated ICU 2.8 This API is under consideration for revision
497 virtual const Locale
getLocale(ULocDataLocaleType type
, UErrorCode
& status
) const = 0;
500 * Convenience method for comparing two strings based on the collation rules.
501 * @param source the source string to be compared with.
502 * @param target the target string to be compared with.
503 * @return true if the first string is greater than the second one,
504 * according to the collation rules. false, otherwise.
505 * @see Collator#compare
508 UBool
greater(const UnicodeString
& source
, const UnicodeString
& target
)
512 * Convenience method for comparing two strings based on the collation rules.
513 * @param source the source string to be compared with.
514 * @param target the target string to be compared with.
515 * @return true if the first string is greater than or equal to the second
516 * one, according to the collation rules. false, otherwise.
517 * @see Collator#compare
520 UBool
greaterOrEqual(const UnicodeString
& source
,
521 const UnicodeString
& target
) const;
524 * Convenience method for comparing two strings based on the collation rules.
525 * @param source the source string to be compared with.
526 * @param target the target string to be compared with.
527 * @return true if the strings are equal according to the collation rules.
529 * @see Collator#compare
532 UBool
equals(const UnicodeString
& source
, const UnicodeString
& target
) const;
535 * Determines the minimum strength that will be use in comparison or
537 * <p>E.g. with strength == SECONDARY, the tertiary difference is ignored
538 * <p>E.g. with strength == PRIMARY, the secondary and tertiary difference
540 * @return the current comparison level.
541 * @see Collator#setStrength
542 * @deprecated ICU 2.6 Use getAttribute(UCOL_STRENGTH...) instead
544 virtual ECollationStrength
getStrength(void) const = 0;
547 * Sets the minimum strength to be used in comparison or transformation.
551 * UErrorCode status = U_ZERO_ERROR;
552 * Collator*myCollation = Collator::createInstance(Locale::US, status);
553 * if (U_FAILURE(status)) return;
554 * myCollation->setStrength(Collator::PRIMARY);
555 * // result will be "abc" == "ABC"
556 * // tertiary differences will be ignored
557 * Collator::ComparisonResult result = myCollation->compare("abc", "ABC");
560 * @see Collator#getStrength
561 * @param newStrength the new comparison level.
562 * @deprecated ICU 2.6 Use setAttribute(UCOL_STRENGTH...) instead
564 virtual void setStrength(ECollationStrength newStrength
) = 0;
567 * Get name of the object for the desired Locale, in the desired langauge
568 * @param objectLocale must be from getAvailableLocales
569 * @param displayLocale specifies the desired locale for output
570 * @param name the fill-in parameter of the return value
571 * @return display-able name of the object for the object locale in the
575 static UnicodeString
& U_EXPORT2
getDisplayName(const Locale
& objectLocale
,
576 const Locale
& displayLocale
,
577 UnicodeString
& name
);
580 * Get name of the object for the desired Locale, in the langauge of the
582 * @param objectLocale must be from getAvailableLocales
583 * @param name the fill-in parameter of the return value
584 * @return name of the object for the desired locale in the default language
587 static UnicodeString
& U_EXPORT2
getDisplayName(const Locale
& objectLocale
,
588 UnicodeString
& name
);
591 * Get the set of Locales for which Collations are installed.
593 * <p>Note this does not include locales supported by registered collators.
594 * If collators might have been registered, use the overload of getAvailableLocales
595 * that returns a StringEnumeration.</p>
597 * @param count the output parameter of number of elements in the locale list
598 * @return the list of available locales for which collations are installed
601 static const Locale
* U_EXPORT2
getAvailableLocales(int32_t& count
);
603 #if !UCONFIG_NO_SERVICE
605 * Return a StringEnumeration over the locales available at the time of the call,
606 * including registered locales. If a severe error occurs (such as out of memory
607 * condition) this will return null. If there is no locale data, an empty enumeration
609 * @return a StringEnumeration over the locales available at the time of the call
612 static StringEnumeration
* U_EXPORT2
getAvailableLocales(void);
616 * Create a string enumerator of all possible keywords that are relevant to
617 * collation. At this point, the only recognized keyword for this
618 * service is "collation".
619 * @param status input-output error code
620 * @return a string enumeration over locale strings. The caller is
621 * responsible for closing the result.
624 static StringEnumeration
* U_EXPORT2
getKeywords(UErrorCode
& status
);
627 * Given a keyword, create a string enumeration of all values
628 * for that keyword that are currently in use.
629 * @param keyword a particular keyword as enumerated by
630 * ucol_getKeywords. If any other keyword is passed in, status is set
631 * to U_ILLEGAL_ARGUMENT_ERROR.
632 * @param status input-output error code
633 * @return a string enumeration over collation keyword values, or NULL
634 * upon error. The caller is responsible for deleting the result.
637 static StringEnumeration
* U_EXPORT2
getKeywordValues(const char *keyword
, UErrorCode
& status
);
640 * Return the functionally equivalent locale for the given
641 * requested locale, with respect to given keyword, for the
642 * collation service. If two locales return the same result, then
643 * collators instantiated for these locales will behave
644 * equivalently. The converse is not always true; two collators
645 * may in fact be equivalent, but return different results, due to
646 * internal details. The return result has no other meaning than
647 * that stated above, and implies nothing as to the relationship
648 * between the two locales. This is intended for use by
649 * applications who wish to cache collators, or otherwise reuse
650 * collators when possible. The functional equivalent may change
651 * over time. For more information, please see the <a
652 * href="http://icu.sourceforge.net/userguide/locale.html#services">
653 * Locales and Services</a> section of the ICU User Guide.
654 * @param keyword a particular keyword as enumerated by
656 * @param locale the requested locale
657 * @param isAvailable reference to a fillin parameter that
658 * indicates whether the requested locale was 'available' to the
659 * collation service. A locale is defined as 'available' if it
660 * physically exists within the collation locale data.
661 * @param status reference to input-output error code
662 * @return the functionally equivalent collation locale, or the root
666 static Locale U_EXPORT2
getFunctionalEquivalent(const char* keyword
, const Locale
& locale
,
667 UBool
& isAvailable
, UErrorCode
& status
);
669 #if !UCONFIG_NO_SERVICE
671 * Register a new Collator. The collator will be adopted.
672 * @param toAdopt the Collator instance to be adopted
673 * @param locale the locale with which the collator will be associated
674 * @param status the in/out status code, no special meanings are assigned
675 * @return a registry key that can be used to unregister this collator
678 static URegistryKey U_EXPORT2
registerInstance(Collator
* toAdopt
, const Locale
& locale
, UErrorCode
& status
);
681 * Register a new CollatorFactory. The factory will be adopted.
682 * @param toAdopt the CollatorFactory instance to be adopted
683 * @param status the in/out status code, no special meanings are assigned
684 * @return a registry key that can be used to unregister this collator
687 static URegistryKey U_EXPORT2
registerFactory(CollatorFactory
* toAdopt
, UErrorCode
& status
);
690 * Unregister a previously-registered Collator or CollatorFactory
691 * using the key returned from the register call. Key becomes
692 * invalid after a successful call and should not be used again.
693 * The object corresponding to the key will be deleted.
694 * @param key the registry key returned by a previous call to registerInstance
695 * @param status the in/out status code, no special meanings are assigned
696 * @return TRUE if the collator for the key was successfully unregistered
699 static UBool U_EXPORT2
unregister(URegistryKey key
, UErrorCode
& status
);
700 #endif /* UCONFIG_NO_SERVICE */
703 * Gets the version information for a Collator.
704 * @param info the version # information, the result will be filled in
707 virtual void getVersion(UVersionInfo info
) const = 0;
710 * Returns a unique class ID POLYMORPHICALLY. Pure virtual method.
711 * This method is to implement a simple version of RTTI, since not all C++
712 * compilers support genuine RTTI. Polymorphic operator==() and clone()
713 * methods call this method.
714 * @return The class ID for this object. All objects of a given class have
715 * the same class ID. Objects of other classes have different class
719 virtual UClassID
getDynamicClassID(void) const = 0;
722 * Universal attribute setter
723 * @param attr attribute type
724 * @param value attribute value
725 * @param status to indicate whether the operation went on smoothly or
729 virtual void setAttribute(UColAttribute attr
, UColAttributeValue value
,
730 UErrorCode
&status
) = 0;
733 * Universal attribute getter
734 * @param attr attribute type
735 * @param status to indicate whether the operation went on smoothly or
737 * @return attribute value
740 virtual UColAttributeValue
getAttribute(UColAttribute attr
,
741 UErrorCode
&status
) = 0;
744 * Sets the variable top to a collation element value of a string supplied.
745 * @param varTop one or more (if contraction) UChars to which the variable top should be set
746 * @param len length of variable top string. If -1 it is considered to be zero terminated.
747 * @param status error code. If error code is set, the return value is undefined. Errors set by this function are: <br>
748 * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such a contraction<br>
749 * U_PRIMARY_TOO_LONG_ERROR if the primary for the variable top has more than two bytes
750 * @return a 32 bit value containing the value of the variable top in upper 16 bits. Lower 16 bits are undefined
753 virtual uint32_t setVariableTop(const UChar
*varTop
, int32_t len
, UErrorCode
&status
) = 0;
756 * Sets the variable top to a collation element value of a string supplied.
757 * @param varTop an UnicodeString size 1 or more (if contraction) of UChars to which the variable top should be set
758 * @param status error code. If error code is set, the return value is undefined. Errors set by this function are: <br>
759 * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such a contraction<br>
760 * U_PRIMARY_TOO_LONG_ERROR if the primary for the variable top has more than two bytes
761 * @return a 32 bit value containing the value of the variable top in upper 16 bits. Lower 16 bits are undefined
764 virtual uint32_t setVariableTop(const UnicodeString varTop
, UErrorCode
&status
) = 0;
767 * Sets the variable top to a collation element value supplied. Variable top is set to the upper 16 bits.
768 * Lower 16 bits are ignored.
769 * @param varTop CE value, as returned by setVariableTop or ucol)getVariableTop
770 * @param status error code (not changed by function)
773 virtual void setVariableTop(const uint32_t varTop
, UErrorCode
&status
) = 0;
776 * Gets the variable top value of a Collator.
777 * Lower 16 bits are undefined and should be ignored.
778 * @param status error code (not changed by function). If error code is set, the return value is undefined.
781 virtual uint32_t getVariableTop(UErrorCode
&status
) const = 0;
784 * Get an UnicodeSet that contains all the characters and sequences
785 * tailored in this collator.
786 * @param status error code of the operation
787 * @return a pointer to a UnicodeSet object containing all the
788 * code points and sequences that may sort differently than
789 * in the UCA. The object must be disposed of by using delete
792 virtual UnicodeSet
*getTailoredSet(UErrorCode
&status
) const;
796 * Thread safe cloning operation
797 * @return pointer to the new clone, user should remove it.
800 virtual Collator
* safeClone(void) = 0;
803 * Get the sort key as an array of bytes from an UnicodeString.
804 * Sort key byte arrays are zero-terminated and can be compared using
806 * @param source string to be processed.
807 * @param result buffer to store result in. If NULL, number of bytes needed
809 * @param resultLength length of the result buffer. If if not enough the
810 * buffer will be filled to capacity.
811 * @return Number of bytes needed for storing the sort key
814 virtual int32_t getSortKey(const UnicodeString
& source
,
816 int32_t resultLength
) const = 0;
819 * Get the sort key as an array of bytes from an UChar buffer.
820 * Sort key byte arrays are zero-terminated and can be compared using
822 * @param source string to be processed.
823 * @param sourceLength length of string to be processed.
824 * If -1, the string is 0 terminated and length will be decided by the
826 * @param result buffer to store result in. If NULL, number of bytes needed
828 * @param resultLength length of the result buffer. If if not enough the
829 * buffer will be filled to capacity.
830 * @return Number of bytes needed for storing the sort key
833 virtual int32_t getSortKey(const UChar
*source
, int32_t sourceLength
,
834 uint8_t*result
, int32_t resultLength
) const = 0;
837 * Produce a bound for a given sortkey and a number of levels.
838 * Return value is always the number of bytes needed, regardless of
839 * whether the result buffer was big enough or even valid.<br>
840 * Resulting bounds can be used to produce a range of strings that are
841 * between upper and lower bounds. For example, if bounds are produced
842 * for a sortkey of string "smith", strings between upper and lower
843 * bounds with one level would include "Smith", "SMITH", "sMiTh".<br>
844 * There are two upper bounds that can be produced. If UCOL_BOUND_UPPER
845 * is produced, strings matched would be as above. However, if bound
846 * produced using UCOL_BOUND_UPPER_LONG is used, the above example will
847 * also match "Smithsonian" and similar.<br>
848 * For more on usage, see example in cintltst/capitst.c in procedure
850 * Sort keys may be compared using <TT>strcmp</TT>.
851 * @param source The source sortkey.
852 * @param sourceLength The length of source, or -1 if null-terminated.
853 * (If an unmodified sortkey is passed, it is always null
855 * @param boundType Type of bound required. It can be UCOL_BOUND_LOWER, which
856 * produces a lower inclusive bound, UCOL_BOUND_UPPER, that
857 * produces upper bound that matches strings of the same length
858 * or UCOL_BOUND_UPPER_LONG that matches strings that have the
859 * same starting substring as the source string.
860 * @param noOfLevels Number of levels required in the resulting bound (for most
861 * uses, the recommended value is 1). See users guide for
862 * explanation on number of levels a sortkey can have.
863 * @param result A pointer to a buffer to receive the resulting sortkey.
864 * @param resultLength The maximum size of result.
865 * @param status Used for returning error code if something went wrong. If the
866 * number of levels requested is higher than the number of levels
867 * in the source key, a warning (U_SORT_KEY_TOO_SHORT_WARNING) is
869 * @return The size needed to fully store the bound.
870 * @see ucol_keyHashCode
873 static int32_t U_EXPORT2
getBound(const uint8_t *source
,
874 int32_t sourceLength
,
875 UColBoundMode boundType
,
878 int32_t resultLength
,
884 // Collator protected constructors -------------------------------------
887 * Default constructor.
888 * Constructor is different from the old default Collator constructor.
889 * The task for determing the default collation strength and normalization
890 * mode is left to the child class.
897 * Empty constructor, does not handle the arguments.
898 * This constructor is done for backward compatibility with 1.7 and 1.8.
899 * The task for handling the argument collation strength and normalization
900 * mode is left to the child class.
901 * @param collationStrength collation strength
902 * @param decompositionMode
903 * @deprecated ICU 2.4. Subclasses should use the default constructor
904 * instead and handle the strength and normalization mode themselves.
906 Collator(UCollationStrength collationStrength
,
907 UNormalizationMode decompositionMode
);
911 * @param other Collator object to be copied from
914 Collator(const Collator
& other
);
916 // Collator protected methods -----------------------------------------
920 * Used internally by registraton to define the requested and valid locales.
921 * @param requestedLocale the requsted locale
922 * @param validLocale the valid locale
925 virtual void setLocales(const Locale
& requestedLocale
, const Locale
& validLocale
);
928 #if !UCONFIG_NO_SERVICE
930 * used only by ucol_open, not for public use
933 static UCollator
* createUCollator(const char* loc
, UErrorCode
* status
);
937 * Assignment operator. Private for now.
940 Collator
& operator=(const Collator
& other
);
942 friend class CFactory
;
943 friend class SimpleCFactory
;
944 friend class ICUCollatorFactory
;
945 friend class ICUCollatorService
;
946 static Collator
* makeInstance(const Locale
& desiredLocale
,
949 // Collator private data members ---------------------------------------
952 synwee : removed as attributes to be handled by child class
953 UCollationStrength strength;
954 Normalizer::EMode decmp;
956 /* This is useless information */
957 /* static const UVersionInfo fVersion;*/
960 #if !UCONFIG_NO_SERVICE
962 * A factory, used with registerFactory, the creates multiple collators and provides
963 * display names for them. A factory supports some number of locales-- these are the
964 * locales for which it can create collators. The factory can be visible, in which
965 * case the supported locales will be enumerated by getAvailableLocales, or invisible,
966 * in which they are not. Invisible locales are still supported, they are just not
967 * listed by getAvailableLocales.
969 * If standard locale display names are sufficient, Collator instances can
970 * be registered using registerInstance instead.</p>
972 * Note: if the collators are to be used from C APIs, they must be instances
973 * of RuleBasedCollator.</p>
977 class U_I18N_API CollatorFactory
: public UObject
{
984 virtual ~CollatorFactory();
987 * Return true if this factory is visible. Default is true.
988 * If not visible, the locales supported by this factory will not
989 * be listed by getAvailableLocales.
990 * @return true if the factory is visible.
993 virtual UBool
visible(void) const;
996 * Return a collator for the provided locale. If the locale
997 * is not supported, return NULL.
998 * @param loc the locale identifying the collator to be created.
999 * @return a new collator if the locale is supported, otherwise NULL.
1002 virtual Collator
* createCollator(const Locale
& loc
) = 0;
1005 * Return the name of the collator for the objectLocale, localized for the displayLocale.
1006 * If objectLocale is not supported, or the factory is not visible, set the result string
1008 * @param objectLocale the locale identifying the collator
1009 * @param displayLocale the locale for which the display name of the collator should be localized
1010 * @param result an output parameter for the display name, set to bogus if not supported.
1011 * @return the display name
1014 virtual UnicodeString
& getDisplayName(const Locale
& objectLocale
,
1015 const Locale
& displayLocale
,
1016 UnicodeString
& result
);
1019 * Return an array of all the locale names directly supported by this factory.
1020 * The number of names is returned in count. This array is owned by the factory.
1021 * Its contents must never change.
1022 * @param count output parameter for the number of locales supported by the factory
1023 * @param status the in/out error code
1024 * @return a pointer to an array of count UnicodeStrings.
1027 virtual const UnicodeString
* getSupportedIDs(int32_t &count
, UErrorCode
& status
) = 0;
1029 #endif /* UCONFIG_NO_SERVICE */
1031 // Collator inline methods -----------------------------------------------
1035 #endif /* #if !UCONFIG_NO_COLLATION */