2 ******************************************************************************
3 * Copyright (C) 1996-2004, 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"
49 #if !UCONFIG_NO_COLLATION
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"
59 class StringEnumeration
;
61 #if !UCONFIG_NO_SERVICE
65 typedef const void* URegistryKey
;
70 class CollatorFactory
;
79 * The <code>Collator</code> class performs locale-sensitive string
81 * You use this class to build searching and sorting routines for natural
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>.
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
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.
102 * The following example shows how to compare two strings using the
103 * <code>Collator</code> for the default locale.
104 * \htmlonly<blockquote>\endhtmlonly
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;
113 * cout << "abc is greater than or equal to ABC" << endl;
116 * \htmlonly</blockquote>\endhtmlonly
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
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;
138 * \htmlonly</blockquote>\endhtmlonly
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.
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
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
166 * @see RuleBasedCollator
168 * @see CollationElementIterator
171 * @version 2.0 11/15/01
174 class U_I18N_API Collator
: public UObject
{
177 // Collator public enums -----------------------------------------------
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" < "abd"
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".
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
194 * Example of tertiary difference, "abc" <<< "ABC".
196 * Two characters are considered "identical" when they have the same unicode
198 * For example, "ä" == "ä".
200 * UCollationStrength is also used to determine the strength of sort keys
201 * generated from Collator objects.
204 enum ECollationStrength
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
223 enum EComparisonResult
230 // Collator public destructor -----------------------------------------
238 // Collator public methods --------------------------------------------
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.
246 virtual UBool
operator==(const Collator
& other
) const;
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.
254 virtual UBool
operator!=(const Collator
& other
) const;
257 * Makes a shallow copy of the current object.
258 * @return a copy of this object
261 virtual Collator
* clone(void) const = 0;
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
275 * The caller owns the returned object and is responsible for deleting it.
277 * @param err the error code status.
278 * @return the collation object of the default locale.(for example, en_US)
279 * @see Locale#getDefault
282 static Collator
* U_EXPORT2
createInstance(UErrorCode
& err
);
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
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
304 * @see ResourceLoader
307 static Collator
* U_EXPORT2
createInstance(const Locale
& loc
, UErrorCode
& err
);
309 #ifdef U_USE_COLLATION_OBSOLETE_2_6
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
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.
320 * Note: this API will be removed in a future release. Use
321 * <tt>createInstance(const Locale&, UErrorCode&) instead.</tt></p>
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.
333 static Collator
*createInstance(const Locale
&loc
, UVersionInfo version
, UErrorCode
&err
);
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
345 * @deprecated ICU 2.6 use the overload with UErrorCode &
347 virtual EComparisonResult
compare(const UnicodeString
& source
,
348 const UnicodeString
& target
) const;
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
362 virtual UCollationResult
compare(const UnicodeString
& source
,
363 const UnicodeString
& target
,
364 UErrorCode
&status
) const = 0;
367 * Does the same thing as compare but limits the comparison to a specified
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 &
378 virtual EComparisonResult
compare(const UnicodeString
& source
,
379 const UnicodeString
& target
,
380 int32_t length
) const;
383 * Does the same thing as compare but limits the comparison to a specified
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.
395 virtual UCollationResult
compare(const UnicodeString
& source
,
396 const UnicodeString
& target
,
398 UErrorCode
&status
) const = 0;
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
413 * @deprecated ICU 2.6 use the overload with UErrorCode &
415 virtual EComparisonResult
compare(const UChar
* source
, int32_t sourceLength
,
416 const UChar
* target
, int32_t targetLength
)
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
435 virtual UCollationResult
compare(const UChar
* source
, int32_t sourceLength
,
436 const UChar
* target
, int32_t targetLength
,
437 UErrorCode
&status
) const = 0;
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
454 virtual CollationKey
& getCollationKey(const UnicodeString
& source
,
456 UErrorCode
& status
) const = 0;
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
474 virtual CollationKey
& getCollationKey(const UChar
*source
,
475 int32_t sourceLength
,
477 UErrorCode
& status
) const = 0;
479 * Generates the hash code for the collation object
482 virtual int32_t hashCode(void) const = 0;
485 * Gets the locale of the Collator
487 * @param type can be either requested, valid or actual locale. For more
488 * information see the definition of ULocDataLocaleType in
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
496 virtual const Locale
getLocale(ULocDataLocaleType type
, UErrorCode
& status
) const = 0;
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
507 UBool
greater(const UnicodeString
& source
, const UnicodeString
& target
)
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
519 UBool
greaterOrEqual(const UnicodeString
& source
,
520 const UnicodeString
& target
) const;
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.
528 * @see Collator#compare
531 UBool
equals(const UnicodeString
& source
, const UnicodeString
& target
) const;
534 * Determines the minimum strength that will be use in comparison or
536 * <p>E.g. with strength == SECONDARY, the tertiary difference is ignored
537 * <p>E.g. with strength == PRIMARY, the secondary and tertiary difference
539 * @return the current comparison level.
540 * @see Collator#setStrength
541 * @deprecated ICU 2.6 Use getAttribute(UCOL_STRENGTH...) instead
543 virtual ECollationStrength
getStrength(void) const = 0;
546 * Sets the minimum strength to be used in comparison or transformation.
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");
559 * @see Collator#getStrength
560 * @param newStrength the new comparison level.
561 * @deprecated ICU 2.6 Use setAttribute(UCOL_STRENGTH...) instead
563 virtual void setStrength(ECollationStrength newStrength
) = 0;
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
574 static UnicodeString
& U_EXPORT2
getDisplayName(const Locale
& objectLocale
,
575 const Locale
& displayLocale
,
576 UnicodeString
& name
);
579 * Get name of the object for the desired Locale, in the langauge of the
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
586 static UnicodeString
& U_EXPORT2
getDisplayName(const Locale
& objectLocale
,
587 UnicodeString
& name
);
590 * Get the set of Locales for which Collations are installed.
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>
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
600 static const Locale
* U_EXPORT2
getAvailableLocales(int32_t& count
);
602 #if !UCONFIG_NO_SERVICE
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
608 * @return a StringEnumeration over the locales available at the time of the call
611 static StringEnumeration
* U_EXPORT2
getAvailableLocales(void);
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.
623 static StringEnumeration
* U_EXPORT2
getKeywords(UErrorCode
& status
);
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.
636 static StringEnumeration
* U_EXPORT2
getKeywordValues(const char *keyword
, UErrorCode
& status
);
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
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
665 static Locale U_EXPORT2
getFunctionalEquivalent(const char* keyword
, const Locale
& locale
,
666 UBool
& isAvailable
, UErrorCode
& status
);
668 #if !UCONFIG_NO_SERVICE
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
677 static URegistryKey U_EXPORT2
registerInstance(Collator
* toAdopt
, const Locale
& locale
, UErrorCode
& status
);
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
686 static URegistryKey U_EXPORT2
registerFactory(CollatorFactory
* toAdopt
, UErrorCode
& status
);
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
698 static UBool U_EXPORT2
unregister(URegistryKey key
, UErrorCode
& status
);
699 #endif /* UCONFIG_NO_SERVICE */
702 * Gets the version information for a Collator.
703 * @param info the version # information, the result will be filled in
706 virtual void getVersion(UVersionInfo info
) const = 0;
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
718 virtual UClassID
getDynamicClassID(void) const = 0;
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
728 virtual void setAttribute(UColAttribute attr
, UColAttributeValue value
,
729 UErrorCode
&status
) = 0;
732 * Universal attribute getter
733 * @param attr attribute type
734 * @param status to indicate whether the operation went on smoothly or
736 * @return attribute value
739 virtual UColAttributeValue
getAttribute(UColAttribute attr
,
740 UErrorCode
&status
) = 0;
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
752 virtual uint32_t setVariableTop(const UChar
*varTop
, int32_t len
, UErrorCode
&status
) = 0;
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
763 virtual uint32_t setVariableTop(const UnicodeString varTop
, UErrorCode
&status
) = 0;
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)
772 virtual void setVariableTop(const uint32_t varTop
, UErrorCode
&status
) = 0;
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.
780 virtual uint32_t getVariableTop(UErrorCode
&status
) const = 0;
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
791 virtual UnicodeSet
*getTailoredSet(UErrorCode
&status
) const;
795 * Thread safe cloning operation
796 * @return pointer to the new clone, user should remove it.
799 virtual Collator
* safeClone(void) = 0;
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
805 * @param source string to be processed.
806 * @param result buffer to store result in. If NULL, number of bytes needed
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
813 virtual int32_t getSortKey(const UnicodeString
& source
,
815 int32_t resultLength
) const = 0;
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
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
825 * @param result buffer to store result in. If NULL, number of bytes needed
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
832 virtual int32_t getSortKey(const UChar
*source
, int32_t sourceLength
,
833 uint8_t*result
, int32_t resultLength
) const = 0;
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
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
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
868 * @return The size needed to fully store the bound.
869 * @see ucol_keyHashCode
872 static int32_t U_EXPORT2
getBound(const uint8_t *source
,
873 int32_t sourceLength
,
874 UColBoundMode boundType
,
877 int32_t resultLength
,
883 // Collator protected constructors -------------------------------------
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.
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.
905 Collator(UCollationStrength collationStrength
,
906 UNormalizationMode decompositionMode
);
910 * @param other Collator object to be copied from
913 Collator(const Collator
& other
);
915 // Collator protected methods -----------------------------------------
919 * Used internally by registraton to define the requested and valid locales.
920 * @param requestedLocale the requsted locale
921 * @param validLocale the valid locale
924 virtual void setLocales(const Locale
& requestedLocale
, const Locale
& validLocale
);
927 #if !UCONFIG_NO_SERVICE
929 * used only by ucol_open, not for public use
932 static UCollator
* createUCollator(const char* loc
, UErrorCode
* status
);
936 * Assignment operator. Private for now.
939 Collator
& operator=(const Collator
& other
);
941 friend class CFactory
;
942 friend class SimpleCFactory
;
943 friend class ICUCollatorFactory
;
944 friend class ICUCollatorService
;
945 static Collator
* makeInstance(const Locale
& desiredLocale
,
948 // Collator private data members ---------------------------------------
951 synwee : removed as attributes to be handled by child class
952 UCollationStrength strength;
953 Normalizer::EMode decmp;
955 /* This is useless information */
956 /* static const UVersionInfo fVersion;*/
959 #if !UCONFIG_NO_SERVICE
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.
968 * If standard locale display names are sufficient, Collator instances can
969 * be registered using registerInstance instead.</p>
971 * Note: if the collators are to be used from C APIs, they must be instances
972 * of RuleBasedCollator.</p>
976 class U_I18N_API CollatorFactory
: public UObject
{
983 virtual ~CollatorFactory();
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.
992 virtual UBool
visible(void) const;
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.
1001 virtual Collator
* createCollator(const Locale
& loc
) = 0;
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
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
1013 virtual UnicodeString
& getDisplayName(const Locale
& objectLocale
,
1014 const Locale
& displayLocale
,
1015 UnicodeString
& result
);
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.
1026 virtual const UnicodeString
* getSupportedIDs(int32_t &count
, UErrorCode
& status
) = 0;
1028 #endif /* UCONFIG_NO_SERVICE */
1030 // Collator inline methods -----------------------------------------------
1034 #endif /* #if !UCONFIG_NO_COLLATION */