2 *******************************************************************************
3 * Copyright (c) 1996-2006, International Business Machines Corporation and others.
5 *******************************************************************************
11 #include "unicode/utypes.h"
13 #if !UCONFIG_NO_COLLATION
15 #include "unicode/unorm.h"
16 #include "unicode/parseerr.h"
17 #include "unicode/uloc.h"
18 #include "unicode/uset.h"
22 * \brief C API: Collator
24 * <h2> Collator C API </h2>
26 * The C API for Collator performs locale-sensitive
27 * string comparison. You use this service to build
28 * searching and sorting routines for natural language text.
29 * <em>Important: </em>The ICU collation service has been reimplemented
30 * in order to achieve better performance and UCA compliance.
31 * For details, see the
32 * <a href="http://dev.icu-project.org/cgi-bin/viewcvs.cgi/~checkout~/icuhtml/design/collation/ICU_collation_design.htm">
33 * collation design document</a>.
35 * For more information about the collation service see
36 * <a href="http://icu.sourceforge.net/userguide/Collate_Intro.html">the users guide</a>.
38 * Collation service provides correct sorting orders for most locales supported in ICU.
39 * If specific data for a locale is not available, the orders eventually falls back
40 * to the <a href="http://www.unicode.org/unicode/reports/tr10/">UCA sort order</a>.
42 * Sort ordering may be customized by providing your own set of rules. For more on
43 * this subject see the
44 * <a href="http://icu.sourceforge.net/userguide/Collate_Customization.html">
45 * Collation customization</a> section of the users guide.
47 * @see UCollationResult
48 * @see UNormalizationMode
49 * @see UCollationStrength
50 * @see UCollationElements
54 * For usage in C programs.
57 /** structure representing a collator object instance
60 typedef struct UCollator UCollator
;
64 * UCOL_LESS is returned if source string is compared to be less than target
65 * string in the u_strcoll() method.
66 * UCOL_EQUAL is returned if source string is compared to be equal to target
67 * string in the u_strcoll() method.
68 * UCOL_GREATER is returned if source string is compared to be greater than
69 * target string in the u_strcoll() method.
72 * Possible values for a comparison result
76 /** string a == string b */
78 /** string a > string b */
80 /** string a < string b */
85 /** Enum containing attribute values for controling collation behavior.
86 * Here are all the allowable values. Not every attribute can take every value. The only
87 * universal value is UCOL_DEFAULT, which resets the attribute value to the predefined
88 * value for that locale
92 /** accepted by most attributes */
95 /** Primary collation strength */
97 /** Secondary collation strength */
99 /** Tertiary collation strength */
101 /** Default collation strength */
102 UCOL_DEFAULT_STRENGTH
= UCOL_TERTIARY
,
103 UCOL_CE_STRENGTH_LIMIT
,
104 /** Quaternary collation strength */
106 /** Identical collation strength */
110 /** Turn the feature off - works for UCOL_FRENCH_COLLATION,
111 UCOL_CASE_LEVEL, UCOL_HIRAGANA_QUATERNARY_MODE
112 & UCOL_DECOMPOSITION_MODE*/
114 /** Turn the feature on - works for UCOL_FRENCH_COLLATION,
115 UCOL_CASE_LEVEL, UCOL_HIRAGANA_QUATERNARY_MODE
116 & UCOL_DECOMPOSITION_MODE*/
119 /** Valid for UCOL_ALTERNATE_HANDLING. Alternate handling will be shifted */
121 /** Valid for UCOL_ALTERNATE_HANDLING. Alternate handling will be non ignorable */
122 UCOL_NON_IGNORABLE
= 21,
124 /** Valid for UCOL_CASE_FIRST -
125 lower case sorts before upper case */
126 UCOL_LOWER_FIRST
= 24,
127 /** upper case sorts before lower case */
128 UCOL_UPPER_FIRST
= 25,
130 UCOL_ATTRIBUTE_VALUE_COUNT
132 } UColAttributeValue
;
135 * Base letter represents a primary difference. Set comparison
136 * level to UCOL_PRIMARY to ignore secondary and tertiary differences.
137 * Use this to set the strength of a Collator object.
138 * Example of primary difference, "abc" < "abd"
140 * Diacritical differences on the same base letter represent a secondary
141 * difference. Set comparison level to UCOL_SECONDARY to ignore tertiary
142 * differences. Use this to set the strength of a Collator object.
143 * Example of secondary difference, "ä" >> "a".
145 * Uppercase and lowercase versions of the same character represents a
146 * tertiary difference. Set comparison level to UCOL_TERTIARY to include
147 * all comparison differences. Use this to set the strength of a Collator
149 * Example of tertiary difference, "abc" <<< "ABC".
151 * Two characters are considered "identical" when they have the same
152 * unicode spellings. UCOL_IDENTICAL.
153 * For example, "ä" == "ä".
155 * UCollationStrength is also used to determine the strength of sort keys
156 * generated from UCollator objects
157 * These values can be now found in the UColAttributeValue enum.
160 typedef UColAttributeValue UCollationStrength
;
162 /** Attributes that collation service understands. All the attributes can take UCOL_DEFAULT
163 * value, as well as the values specific to each one.
167 /** Attribute for direction of secondary weights - used in French.
168 * Acceptable values are UCOL_ON, which results in secondary weights
169 * being considered backwards and UCOL_OFF which treats secondary
170 * weights in the order they appear.*/
171 UCOL_FRENCH_COLLATION
,
172 /** Attribute for handling variable elements.
173 * Acceptable values are UCOL_NON_IGNORABLE (default)
174 * which treats all the codepoints with non-ignorable
175 * primary weights in the same way,
176 * and UCOL_SHIFTED which causes codepoints with primary
177 * weights that are equal or below the variable top value
178 * to be ignored on primary level and moved to the quaternary
180 UCOL_ALTERNATE_HANDLING
,
181 /** Controls the ordering of upper and lower case letters.
182 * Acceptable values are UCOL_OFF (default), which orders
183 * upper and lower case letters in accordance to their tertiary
184 * weights, UCOL_UPPER_FIRST which forces upper case letters to
185 * sort before lower case letters, and UCOL_LOWER_FIRST which does
188 /** Controls whether an extra case level (positioned before the third
189 * level) is generated or not. Acceptable values are UCOL_OFF (default),
190 * when case level is not generated, and UCOL_ON which causes the case
191 * level to be generated. Contents of the case level are affected by
192 * the value of UCOL_CASE_FIRST attribute. A simple way to ignore
193 * accent differences in a string is to set the strength to UCOL_PRIMARY
194 * and enable case level. */
196 /** Controls whether the normalization check and necessary normalizations
197 * are performed. When set to UCOL_OFF (default) no normalization check
198 * is performed. The correctness of the result is guaranteed only if the
199 * input data is in so-called FCD form (see users manual for more info).
200 * When set to UCOL_ON, an incremental check is performed to see whether
201 * the input data is in the FCD form. If the data is not in the FCD form,
202 * incremental NFD normalization is performed. */
203 UCOL_NORMALIZATION_MODE
,
204 /** An alias for UCOL_NORMALIZATION_MODE attribute */
205 UCOL_DECOMPOSITION_MODE
= UCOL_NORMALIZATION_MODE
,
206 /** The strength attribute. Can be either UCOL_PRIMARY, UCOL_SECONDARY,
207 * UCOL_TERTIARY, UCOL_QUATERNARY or UCOL_IDENTICAL. The usual strength
208 * for most locales (except Japanese) is tertiary. Quaternary strength
209 * is useful when combined with shifted setting for alternate handling
210 * attribute and for JIS x 4061 collation, when it is used to distinguish
211 * between Katakana and Hiragana (this is achieved by setting the
212 * UCOL_HIRAGANA_QUATERNARY mode to on. Otherwise, quaternary level
213 * is affected only by the number of non ignorable code points in
214 * the string. Identical strength is rarely useful, as it amounts
215 * to codepoints of the NFD form of the string. */
217 /** When turned on, this attribute positions Hiragana before all
218 * non-ignorables on quaternary level This is a sneaky way to produce JIS
220 UCOL_HIRAGANA_QUATERNARY_MODE
,
221 /** When turned on, this attribute generates a collation key
222 * for the numeric value of substrings of digits.
223 * This is a way to get '100' to sort AFTER '2'. */
224 UCOL_NUMERIC_COLLATION
,
228 /** Options for retrieving the rule string
232 /** Retrieve tailoring only */
234 /** Retrieve UCA rules and tailoring */
239 * Open a UCollator for comparing strings.
240 * The UCollator pointer is used in all the calls to the Collation
241 * service. After finished, collator must be disposed of by calling
242 * {@link #ucol_close }.
243 * @param loc The locale containing the required collation rules.
244 * Special values for locales can be passed in -
245 * if NULL is passed for the locale, the default locale
246 * collation rules will be used. If empty string ("") or
247 * "root" are passed, UCA rules will be used.
248 * @param status A pointer to an UErrorCode to receive any errors
249 * @return A pointer to a UCollator, or 0 if an error occurred.
250 * @see ucol_openRules
251 * @see ucol_safeClone
255 U_STABLE UCollator
* U_EXPORT2
256 ucol_open(const char *loc
, UErrorCode
*status
);
259 * Produce an UCollator instance according to the rules supplied.
260 * The rules are used to change the default ordering, defined in the
261 * UCA in a process called tailoring. The resulting UCollator pointer
262 * can be used in the same way as the one obtained by {@link #ucol_strcoll }.
263 * @param rules A string describing the collation rules. For the syntax
264 * of the rules please see users guide.
265 * @param rulesLength The length of rules, or -1 if null-terminated.
266 * @param normalizationMode The normalization mode: One of
267 * UCOL_OFF (expect the text to not need normalization),
268 * UCOL_ON (normalize), or
269 * UCOL_DEFAULT (set the mode according to the rules)
270 * @param strength The default collation strength; one of UCOL_PRIMARY, UCOL_SECONDARY,
271 * UCOL_TERTIARY, UCOL_IDENTICAL,UCOL_DEFAULT_STRENGTH - can be also set in the rules.
272 * @param parseError A pointer to UParseError to recieve information about errors
273 * occurred during parsing. This argument can currently be set
274 * to NULL, but at users own risk. Please provide a real structure.
275 * @param status A pointer to an UErrorCode to receive any errors
276 * @return A pointer to a UCollator. It is not guaranteed that NULL be returned in case
277 * of error - please use status argument to check for errors.
279 * @see ucol_safeClone
283 U_STABLE UCollator
* U_EXPORT2
284 ucol_openRules( const UChar
*rules
,
286 UColAttributeValue normalizationMode
,
287 UCollationStrength strength
,
288 UParseError
*parseError
,
292 * Open a collator defined by a short form string.
293 * The structure and the syntax of the string is defined in the "Naming collators"
294 * section of the users guide:
295 * http://icu.sourceforge.net/userguide/Collate_Concepts.html#Naming_Collators
296 * Attributes are overriden by the subsequent attributes. So, for "S2_S3", final
297 * strength will be 3. 3066bis locale overrides individual locale parts.
298 * The call to this function is equivalent to a call to ucol_open, followed by a
299 * series of calls to ucol_setAttribute and ucol_setVariableTop.
300 * @param definition A short string containing a locale and a set of attributes.
301 * Attributes not explicitly mentioned are left at the default
302 * state for a locale.
303 * @param parseError if not NULL, structure that will get filled with error's pre
304 * and post context in case of error.
305 * @param forceDefaults if FALSE, the settings that are the same as the collator
306 * default settings will not be applied (for example, setting
307 * French secondary on a French collator would not be executed).
308 * If TRUE, all the settings will be applied regardless of the
309 * collator default value. If the definition
310 * strings are to be cached, should be set to FALSE.
311 * @param status Error code. Apart from regular error conditions connected to
312 * instantiating collators (like out of memory or similar), this
313 * API will return an error if an invalid attribute or attribute/value
314 * combination is specified.
315 * @return A pointer to a UCollator or 0 if an error occured (including an
316 * invalid attribute).
318 * @see ucol_setAttribute
319 * @see ucol_setVariableTop
320 * @see ucol_getShortDefinitionString
321 * @see ucol_normalizeShortDefinitionString
325 U_STABLE UCollator
* U_EXPORT2
326 ucol_openFromShortString( const char *definition
,
328 UParseError
*parseError
,
332 * Get a set containing the contractions defined by the collator. The set includes
333 * both the UCA contractions and the contractions defined by the collator. This set
334 * will contain only strings. If a tailoring explicitly suppresses contractions from
335 * the UCA (like Russian), removed contractions will not be in the resulting set.
336 * @param coll collator
337 * @param conts the set to hold the result. It gets emptied before
338 * contractions are added.
339 * @param status to hold the error code
340 * @return the size of the contraction set
342 * @deprecated ICU 3.4, use ucol_getContractionsAndExpansions instead
344 U_DEPRECATED
int32_t U_EXPORT2
345 ucol_getContractions( const UCollator
*coll
,
350 * Get a set containing the expansions defined by the collator. The set includes
351 * both the UCA expansions and the expansions defined by the tailoring
352 * @param coll collator
353 * @param contractions if not NULL, the set to hold the contractions
354 * @param expansions if not NULL, the set to hold the expansions
355 * @param addPrefixes add the prefix contextual elements to contractions
356 * @param status to hold the error code
360 U_DRAFT
void U_EXPORT2
361 ucol_getContractionsAndExpansions( const UCollator
*coll
,
362 USet
*contractions
, USet
*expansions
,
363 UBool addPrefixes
, UErrorCode
*status
);
367 * Once closed, a UCollator should not be used. Every open collator should
368 * be closed. Otherwise, a memory leak will result.
369 * @param coll The UCollator to close.
371 * @see ucol_openRules
372 * @see ucol_safeClone
375 U_STABLE
void U_EXPORT2
376 ucol_close(UCollator
*coll
);
379 * Compare two strings.
380 * The strings will be compared using the options already specified.
381 * @param coll The UCollator containing the comparison rules.
382 * @param source The source string.
383 * @param sourceLength The length of source, or -1 if null-terminated.
384 * @param target The target string.
385 * @param targetLength The length of target, or -1 if null-terminated.
386 * @return The result of comparing the strings; one of UCOL_EQUAL,
387 * UCOL_GREATER, UCOL_LESS
389 * @see ucol_greaterOrEqual
393 U_STABLE UCollationResult U_EXPORT2
394 ucol_strcoll( const UCollator
*coll
,
396 int32_t sourceLength
,
398 int32_t targetLength
);
401 * Determine if one string is greater than another.
402 * This function is equivalent to {@link #ucol_strcoll } == UCOL_GREATER
403 * @param coll The UCollator containing the comparison rules.
404 * @param source The source string.
405 * @param sourceLength The length of source, or -1 if null-terminated.
406 * @param target The target string.
407 * @param targetLength The length of target, or -1 if null-terminated.
408 * @return TRUE if source is greater than target, FALSE otherwise.
410 * @see ucol_greaterOrEqual
414 U_STABLE UBool U_EXPORT2
415 ucol_greater(const UCollator
*coll
,
416 const UChar
*source
, int32_t sourceLength
,
417 const UChar
*target
, int32_t targetLength
);
420 * Determine if one string is greater than or equal to another.
421 * This function is equivalent to {@link #ucol_strcoll } != UCOL_LESS
422 * @param coll The UCollator containing the comparison rules.
423 * @param source The source string.
424 * @param sourceLength The length of source, or -1 if null-terminated.
425 * @param target The target string.
426 * @param targetLength The length of target, or -1 if null-terminated.
427 * @return TRUE if source is greater than or equal to target, FALSE otherwise.
433 U_STABLE UBool U_EXPORT2
434 ucol_greaterOrEqual(const UCollator
*coll
,
435 const UChar
*source
, int32_t sourceLength
,
436 const UChar
*target
, int32_t targetLength
);
439 * Compare two strings for equality.
440 * This function is equivalent to {@link #ucol_strcoll } == UCOL_EQUAL
441 * @param coll The UCollator containing the comparison rules.
442 * @param source The source string.
443 * @param sourceLength The length of source, or -1 if null-terminated.
444 * @param target The target string.
445 * @param targetLength The length of target, or -1 if null-terminated.
446 * @return TRUE if source is equal to target, FALSE otherwise
449 * @see ucol_greaterOrEqual
452 U_STABLE UBool U_EXPORT2
453 ucol_equal(const UCollator
*coll
,
454 const UChar
*source
, int32_t sourceLength
,
455 const UChar
*target
, int32_t targetLength
);
458 * Compare two UTF-8 encoded trings.
459 * The strings will be compared using the options already specified.
460 * @param coll The UCollator containing the comparison rules.
461 * @param sIter The source string iterator.
462 * @param tIter The target string iterator.
463 * @return The result of comparing the strings; one of UCOL_EQUAL,
464 * UCOL_GREATER, UCOL_LESS
465 * @param status A pointer to an UErrorCode to receive any errors
469 U_STABLE UCollationResult U_EXPORT2
470 ucol_strcollIter( const UCollator
*coll
,
471 UCharIterator
*sIter
,
472 UCharIterator
*tIter
,
476 * Get the collation strength used in a UCollator.
477 * The strength influences how strings are compared.
478 * @param coll The UCollator to query.
479 * @return The collation strength; one of UCOL_PRIMARY, UCOL_SECONDARY,
480 * UCOL_TERTIARY, UCOL_QUATERNARY, UCOL_IDENTICAL
481 * @see ucol_setStrength
484 U_STABLE UCollationStrength U_EXPORT2
485 ucol_getStrength(const UCollator
*coll
);
488 * Set the collation strength used in a UCollator.
489 * The strength influences how strings are compared.
490 * @param coll The UCollator to set.
491 * @param strength The desired collation strength; one of UCOL_PRIMARY,
492 * UCOL_SECONDARY, UCOL_TERTIARY, UCOL_QUATERNARY, UCOL_IDENTICAL, UCOL_DEFAULT
493 * @see ucol_getStrength
496 U_STABLE
void U_EXPORT2
497 ucol_setStrength(UCollator
*coll
,
498 UCollationStrength strength
);
501 * Get the display name for a UCollator.
502 * The display name is suitable for presentation to a user.
503 * @param objLoc The locale of the collator in question.
504 * @param dispLoc The locale for display.
505 * @param result A pointer to a buffer to receive the attribute.
506 * @param resultLength The maximum size of result.
507 * @param status A pointer to an UErrorCode to receive any errors
508 * @return The total buffer size needed; if greater than resultLength,
509 * the output was truncated.
512 U_STABLE
int32_t U_EXPORT2
513 ucol_getDisplayName( const char *objLoc
,
516 int32_t resultLength
,
520 * Get a locale for which collation rules are available.
521 * A UCollator in a locale returned by this function will perform the correct
522 * collation for the locale.
523 * @param index The index of the desired locale.
524 * @return A locale for which collation rules are available, or 0 if none.
525 * @see ucol_countAvailable
528 U_STABLE
const char* U_EXPORT2
529 ucol_getAvailable(int32_t index
);
532 * Determine how many locales have collation rules available.
533 * This function is most useful as determining the loop ending condition for
534 * calls to {@link #ucol_getAvailable }.
535 * @return The number of locales for which collation rules are available.
536 * @see ucol_getAvailable
539 U_STABLE
int32_t U_EXPORT2
540 ucol_countAvailable(void);
542 #if !UCONFIG_NO_SERVICE
544 * Create a string enumerator of all locales for which a valid
545 * collator may be opened.
546 * @param status input-output error code
547 * @return a string enumeration over locale strings. The caller is
548 * responsible for closing the result.
551 U_STABLE UEnumeration
* U_EXPORT2
552 ucol_openAvailableLocales(UErrorCode
*status
);
556 * Create a string enumerator of all possible keywords that are relevant to
557 * collation. At this point, the only recognized keyword for this
558 * service is "collation".
559 * @param status input-output error code
560 * @return a string enumeration over locale strings. The caller is
561 * responsible for closing the result.
564 U_STABLE UEnumeration
* U_EXPORT2
565 ucol_getKeywords(UErrorCode
*status
);
568 * Given a keyword, create a string enumeration of all values
569 * for that keyword that are currently in use.
570 * @param keyword a particular keyword as enumerated by
571 * ucol_getKeywords. If any other keyword is passed in, *status is set
572 * to U_ILLEGAL_ARGUMENT_ERROR.
573 * @param status input-output error code
574 * @return a string enumeration over collation keyword values, or NULL
575 * upon error. The caller is responsible for closing the result.
578 U_STABLE UEnumeration
* U_EXPORT2
579 ucol_getKeywordValues(const char *keyword
, UErrorCode
*status
);
582 * Return the functionally equivalent locale for the given
583 * requested locale, with respect to given keyword, for the
584 * collation service. If two locales return the same result, then
585 * collators instantiated for these locales will behave
586 * equivalently. The converse is not always true; two collators
587 * may in fact be equivalent, but return different results, due to
588 * internal details. The return result has no other meaning than
589 * that stated above, and implies nothing as to the relationship
590 * between the two locales. This is intended for use by
591 * applications who wish to cache collators, or otherwise reuse
592 * collators when possible. The functional equivalent may change
593 * over time. For more information, please see the <a
594 * href="http://icu.sourceforge.net/userguide/locale.html#services">
595 * Locales and Services</a> section of the ICU User Guide.
596 * @param result fillin for the functionally equivalent locale
597 * @param resultCapacity capacity of the fillin buffer
598 * @param keyword a particular keyword as enumerated by
600 * @param locale the requested locale
601 * @param isAvailable if non-NULL, pointer to a fillin parameter that
602 * indicates whether the requested locale was 'available' to the
603 * collation service. A locale is defined as 'available' if it
604 * physically exists within the collation locale data.
605 * @param status pointer to input-output error code
606 * @return the actual buffer size needed for the locale. If greater
607 * than resultCapacity, the returned full name will be truncated and
608 * an error code will be returned.
611 U_STABLE
int32_t U_EXPORT2
612 ucol_getFunctionalEquivalent(char* result
, int32_t resultCapacity
,
613 const char* keyword
, const char* locale
,
614 UBool
* isAvailable
, UErrorCode
* status
);
617 * Get the collation rules from a UCollator.
618 * The rules will follow the rule syntax.
619 * @param coll The UCollator to query.
621 * @return The collation rules.
624 U_STABLE
const UChar
* U_EXPORT2
625 ucol_getRules( const UCollator
*coll
,
628 /** Get the short definition string for a collator. This API harvests the collator's
629 * locale and the attribute set and produces a string that can be used for opening
630 * a collator with the same properties using the ucol_openFromShortString API.
631 * This string will be normalized.
632 * The structure and the syntax of the string is defined in the "Naming collators"
633 * section of the users guide:
634 * http://icu.sourceforge.net/userguide/Collate_Concepts.html#Naming_Collators
635 * This API supports preflighting.
636 * @param coll a collator
637 * @param locale a locale that will appear as a collators locale in the resulting
638 * short string definition. If NULL, the locale will be harvested
640 * @param buffer space to hold the resulting string
641 * @param capacity capacity of the buffer
642 * @param status for returning errors. All the preflighting errors are featured
643 * @return length of the resulting string
644 * @see ucol_openFromShortString
645 * @see ucol_normalizeShortDefinitionString
648 U_STABLE
int32_t U_EXPORT2
649 ucol_getShortDefinitionString(const UCollator
*coll
,
655 /** Verifies and normalizes short definition string.
656 * Normalized short definition string has all the option sorted by the argument name,
657 * so that equivalent definition strings are the same.
658 * This API supports preflighting.
659 * @param source definition string
660 * @param destination space to hold the resulting string
661 * @param capacity capacity of the buffer
662 * @param parseError if not NULL, structure that will get filled with error's pre
663 * and post context in case of error.
664 * @param status Error code. This API will return an error if an invalid attribute
665 * or attribute/value combination is specified. All the preflighting
666 * errors are also featured
667 * @return length of the resulting normalized string.
669 * @see ucol_openFromShortString
670 * @see ucol_getShortDefinitionString
675 U_STABLE
int32_t U_EXPORT2
676 ucol_normalizeShortDefinitionString(const char *source
,
679 UParseError
*parseError
,
684 * Get a sort key for a string from a UCollator.
685 * Sort keys may be compared using <TT>strcmp</TT>.
686 * @param coll The UCollator containing the collation rules.
687 * @param source The string to transform.
688 * @param sourceLength The length of source, or -1 if null-terminated.
689 * @param result A pointer to a buffer to receive the attribute.
690 * @param resultLength The maximum size of result.
691 * @return The size needed to fully store the sort key..
692 * @see ucol_keyHashCode
695 U_STABLE
int32_t U_EXPORT2
696 ucol_getSortKey(const UCollator
*coll
,
698 int32_t sourceLength
,
700 int32_t resultLength
);
703 /** Gets the next count bytes of a sort key. Caller needs
704 * to preserve state array between calls and to provide
705 * the same type of UCharIterator set with the same string.
706 * The destination buffer provided must be big enough to store
707 * the number of requested bytes. Generated sortkey is not
708 * compatible with sortkeys generated using ucol_getSortKey
709 * API, since we don't do any compression. If uncompressed
710 * sortkeys are required, this API can be used.
711 * @param coll The UCollator containing the collation rules.
712 * @param iter UCharIterator containing the string we need
713 * the sort key to be calculated for.
714 * @param state Opaque state of sortkey iteration.
715 * @param dest Buffer to hold the resulting sortkey part
716 * @param count number of sort key bytes required.
717 * @param status error code indicator.
718 * @return the actual number of bytes of a sortkey. It can be
719 * smaller than count if we have reached the end of
723 U_STABLE
int32_t U_EXPORT2
724 ucol_nextSortKeyPart(const UCollator
*coll
,
727 uint8_t *dest
, int32_t count
,
730 /** enum that is taken by ucol_getBound API
731 * See below for explanation
732 * do not change the values assigned to the
733 * members of this enum. Underlying code
734 * depends on them having these numbers
739 UCOL_BOUND_LOWER
= 0,
740 /** upper bound that will match strings of exact size */
741 UCOL_BOUND_UPPER
= 1,
742 /** upper bound that will match all the strings that have the same initial substring as the given string */
743 UCOL_BOUND_UPPER_LONG
= 2,
744 UCOL_BOUND_VALUE_COUNT
748 * Produce a bound for a given sortkey and a number of levels.
749 * Return value is always the number of bytes needed, regardless of
750 * whether the result buffer was big enough or even valid.<br>
751 * Resulting bounds can be used to produce a range of strings that are
752 * between upper and lower bounds. For example, if bounds are produced
753 * for a sortkey of string "smith", strings between upper and lower
754 * bounds with one level would include "Smith", "SMITH", "sMiTh".<br>
755 * There are two upper bounds that can be produced. If UCOL_BOUND_UPPER
756 * is produced, strings matched would be as above. However, if bound
757 * produced using UCOL_BOUND_UPPER_LONG is used, the above example will
758 * also match "Smithsonian" and similar.<br>
759 * For more on usage, see example in cintltst/capitst.c in procedure
761 * Sort keys may be compared using <TT>strcmp</TT>.
762 * @param source The source sortkey.
763 * @param sourceLength The length of source, or -1 if null-terminated.
764 * (If an unmodified sortkey is passed, it is always null
766 * @param boundType Type of bound required. It can be UCOL_BOUND_LOWER, which
767 * produces a lower inclusive bound, UCOL_BOUND_UPPER, that
768 * produces upper bound that matches strings of the same length
769 * or UCOL_BOUND_UPPER_LONG that matches strings that have the
770 * same starting substring as the source string.
771 * @param noOfLevels Number of levels required in the resulting bound (for most
772 * uses, the recommended value is 1). See users guide for
773 * explanation on number of levels a sortkey can have.
774 * @param result A pointer to a buffer to receive the resulting sortkey.
775 * @param resultLength The maximum size of result.
776 * @param status Used for returning error code if something went wrong. If the
777 * number of levels requested is higher than the number of levels
778 * in the source key, a warning (U_SORT_KEY_TOO_SHORT_WARNING) is
780 * @return The size needed to fully store the bound.
781 * @see ucol_keyHashCode
784 U_STABLE
int32_t U_EXPORT2
785 ucol_getBound(const uint8_t *source
,
786 int32_t sourceLength
,
787 UColBoundMode boundType
,
790 int32_t resultLength
,
794 * Gets the version information for a Collator. Version is currently
795 * an opaque 32-bit number which depends, among other things, on major
796 * versions of the collator tailoring and UCA.
797 * @param coll The UCollator to query.
798 * @param info the version # information, the result will be filled in
801 U_STABLE
void U_EXPORT2
802 ucol_getVersion(const UCollator
* coll
, UVersionInfo info
);
805 * Gets the UCA version information for a Collator. Version is the
806 * UCA version number (3.1.1, 4.0).
807 * @param coll The UCollator to query.
808 * @param info the version # information, the result will be filled in
811 U_STABLE
void U_EXPORT2
812 ucol_getUCAVersion(const UCollator
* coll
, UVersionInfo info
);
815 * Merge two sort keys. The levels are merged with their corresponding counterparts
816 * (primaries with primaries, secondaries with secondaries etc.). Between the values
817 * from the same level a separator is inserted.
818 * example (uncompressed):
819 * 191B1D 01 050505 01 910505 00 and 1F2123 01 050505 01 910505 00
821 * 191B1D 02 1F212301 050505 02 050505 01 910505 02 910505 00
822 * This allows for concatenating of first and last names for sorting, among other things.
823 * If the destination buffer is not big enough, the results are undefined.
824 * If any of source lengths are zero or any of source pointers are NULL/undefined,
825 * result is of size zero.
826 * @param src1 pointer to the first sortkey
827 * @param src1Length length of the first sortkey
828 * @param src2 pointer to the second sortkey
829 * @param src2Length length of the second sortkey
830 * @param dest buffer to hold the result
831 * @param destCapacity size of the buffer for the result
832 * @return size of the result. If the buffer is big enough size is always
833 * src1Length+src2Length-1
836 U_STABLE
int32_t U_EXPORT2
837 ucol_mergeSortkeys(const uint8_t *src1
, int32_t src1Length
,
838 const uint8_t *src2
, int32_t src2Length
,
839 uint8_t *dest
, int32_t destCapacity
);
842 * Universal attribute setter
843 * @param coll collator which attributes are to be changed
844 * @param attr attribute type
845 * @param value attribute value
846 * @param status to indicate whether the operation went on smoothly or there were errors
848 * @see UColAttributeValue
849 * @see ucol_getAttribute
852 U_STABLE
void U_EXPORT2
853 ucol_setAttribute(UCollator
*coll
, UColAttribute attr
, UColAttributeValue value
, UErrorCode
*status
);
856 * Universal attribute getter
857 * @param coll collator which attributes are to be changed
858 * @param attr attribute type
859 * @return attribute value
860 * @param status to indicate whether the operation went on smoothly or there were errors
862 * @see UColAttributeValue
863 * @see ucol_setAttribute
866 U_STABLE UColAttributeValue U_EXPORT2
867 ucol_getAttribute(const UCollator
*coll
, UColAttribute attr
, UErrorCode
*status
);
870 * is a two byte primary value which causes all the codepoints with primary values that
871 * are less or equal than the variable top to be shifted when alternate handling is set
873 * Sets the variable top to a collation element value of a string supplied.
874 * @param coll collator which variable top needs to be changed
875 * @param varTop one or more (if contraction) UChars to which the variable top should be set
876 * @param len length of variable top string. If -1 it is considered to be zero terminated.
877 * @param status error code. If error code is set, the return value is undefined.
878 * Errors set by this function are: <br>
879 * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such
881 * U_PRIMARY_TOO_LONG_ERROR if the primary for the variable top has more than two bytes
882 * @return a 32 bit value containing the value of the variable top in upper 16 bits.
883 * Lower 16 bits are undefined
884 * @see ucol_getVariableTop
885 * @see ucol_restoreVariableTop
888 U_STABLE
uint32_t U_EXPORT2
889 ucol_setVariableTop(UCollator
*coll
,
890 const UChar
*varTop
, int32_t len
,
894 * Gets the variable top value of a Collator.
895 * Lower 16 bits are undefined and should be ignored.
896 * @param coll collator which variable top needs to be retrieved
897 * @param status error code (not changed by function). If error code is set,
898 * the return value is undefined.
899 * @return the variable top value of a Collator.
900 * @see ucol_setVariableTop
901 * @see ucol_restoreVariableTop
904 U_STABLE
uint32_t U_EXPORT2
ucol_getVariableTop(const UCollator
*coll
, UErrorCode
*status
);
907 * Sets the variable top to a collation element value supplied. Variable top is
908 * set to the upper 16 bits.
909 * Lower 16 bits are ignored.
910 * @param coll collator which variable top needs to be changed
911 * @param varTop CE value, as returned by ucol_setVariableTop or ucol)getVariableTop
912 * @param status error code (not changed by function)
913 * @see ucol_getVariableTop
914 * @see ucol_setVariableTop
917 U_STABLE
void U_EXPORT2
918 ucol_restoreVariableTop(UCollator
*coll
, const uint32_t varTop
, UErrorCode
*status
);
921 * Thread safe cloning operation. The result is a clone of a given collator.
922 * @param coll collator to be cloned
923 * @param stackBuffer user allocated space for the new clone.
924 * If NULL new memory will be allocated.
925 * If buffer is not large enough, new memory will be allocated.
926 * Clients can use the U_COL_SAFECLONE_BUFFERSIZE.
927 * This will probably be enough to avoid memory allocations.
928 * @param pBufferSize pointer to size of allocated space.
929 * If *pBufferSize == 0, a sufficient size for use in cloning will
930 * be returned ('pre-flighting')
931 * If *pBufferSize is not enough for a stack-based safe clone,
932 * new memory will be allocated.
933 * @param status to indicate whether the operation went on smoothly or there were errors
934 * An informational status value, U_SAFECLONE_ALLOCATED_ERROR, is used if any
935 * allocations were necessary.
936 * @return pointer to the new clone
938 * @see ucol_openRules
942 U_STABLE UCollator
* U_EXPORT2
943 ucol_safeClone(const UCollator
*coll
,
945 int32_t *pBufferSize
,
948 /** default memory size for the new clone. It needs to be this large for os/400 large pointers
951 #define U_COL_SAFECLONE_BUFFERSIZE 512
954 * Returns current rules. Delta defines whether full rules are returned or just the tailoring.
955 * Returns number of UChars needed to store rules. If buffer is NULL or bufferLen is not enough
956 * to store rules, will store up to available space.
957 * @param coll collator to get the rules from
958 * @param delta one of UCOL_TAILORING_ONLY, UCOL_FULL_RULES.
959 * @param buffer buffer to store the result in. If NULL, you'll get no rules.
960 * @param bufferLen lenght of buffer to store rules in. If less then needed you'll get only the part that fits in.
961 * @return current rules
964 U_STABLE
int32_t U_EXPORT2
965 ucol_getRulesEx(const UCollator
*coll
, UColRuleOption delta
, UChar
*buffer
, int32_t bufferLen
);
968 * gets the locale name of the collator. If the collator
969 * is instantiated from the rules, then this function returns
971 * @param coll The UCollator for which the locale is needed
972 * @param type You can choose between requested, valid and actual
973 * locale. For description see the definition of
974 * ULocDataLocaleType in uloc.h
975 * @param status error code of the operation
976 * @return real locale name from which the collation data comes.
977 * If the collator was instantiated from rules, returns
979 * @deprecated ICU 2.8 Use ucol_getLocaleByType instead
981 U_DEPRECATED
const char * U_EXPORT2
982 ucol_getLocale(const UCollator
*coll
, ULocDataLocaleType type
, UErrorCode
*status
);
986 * gets the locale name of the collator. If the collator
987 * is instantiated from the rules, then this function returns
989 * @param coll The UCollator for which the locale is needed
990 * @param type You can choose between requested, valid and actual
991 * locale. For description see the definition of
992 * ULocDataLocaleType in uloc.h
993 * @param status error code of the operation
994 * @return real locale name from which the collation data comes.
995 * If the collator was instantiated from rules, returns
999 U_STABLE
const char * U_EXPORT2
1000 ucol_getLocaleByType(const UCollator
*coll
, ULocDataLocaleType type
, UErrorCode
*status
);
1003 * Get an Unicode set that contains all the characters and sequences tailored in
1004 * this collator. The result must be disposed of by using uset_close.
1005 * @param coll The UCollator for which we want to get tailored chars
1006 * @param status error code of the operation
1007 * @return a pointer to newly created USet. Must be be disposed by using uset_close
1008 * @see ucol_openRules
1012 U_STABLE USet
* U_EXPORT2
1013 ucol_getTailoredSet(const UCollator
*coll
, UErrorCode
*status
);
1015 #ifndef U_HIDE_INTERNAL_API
1017 * Returned by ucol_collatorToIdentifier to signify that collator is
1018 * not encodable as an identifier.
1021 #define UCOL_SIT_COLLATOR_NOT_ENCODABLE 0x80000000
1022 #endif /* U_HIDE_INTERNAL_API */
1025 * Get a 31-bit identifier given a collator.
1026 * @param coll UCollator
1027 * @param locale a locale that will appear as a collators locale in the resulting
1028 * short string definition. If NULL, the locale will be harvested
1029 * from the collator.
1030 * @param status holds error messages
1031 * @return 31-bit identifier. MSB is used if the collator cannot be encoded. In that
1032 * case UCOL_SIT_COLLATOR_NOT_ENCODABLE is returned
1033 * @see ucol_openFromIdentifier
1034 * @see ucol_identifierToShortString
1037 U_INTERNAL
uint32_t U_EXPORT2
1038 ucol_collatorToIdentifier(const UCollator
*coll
,
1040 UErrorCode
*status
);
1043 * Open a collator given a 31-bit identifier
1044 * @param identifier 31-bit identifier, encoded by calling ucol_collatorToIdentifier
1045 * @param forceDefaults if FALSE, the settings that are the same as the collator
1046 * default settings will not be applied (for example, setting
1047 * French secondary on a French collator would not be executed).
1048 * If TRUE, all the settings will be applied regardless of the
1049 * collator default value. If the definition
1050 * strings that can be produced from a collator instantiated by
1051 * calling this API are to be cached, should be set to FALSE.
1052 * @param status for returning errors
1053 * @return UCollator object
1054 * @see ucol_collatorToIdentifier
1055 * @see ucol_identifierToShortString
1058 U_INTERNAL UCollator
* U_EXPORT2
1059 ucol_openFromIdentifier(uint32_t identifier
,
1060 UBool forceDefaults
,
1061 UErrorCode
*status
);
1065 * Calculate the short definition string given an identifier. Supports preflighting.
1066 * @param identifier 31-bit identifier, encoded by calling ucol_collatorToIdentifier
1067 * @param buffer buffer to store the result
1068 * @param capacity buffer capacity
1069 * @param forceDefaults whether the settings that are the same as the default setting
1070 * should be forced anyway. Setting this argument to FALSE reduces
1071 * the number of different configurations, but decreases performace
1072 * as a collator has to be instantiated.
1073 * @param status for returning errors
1074 * @return length of the short definition string
1075 * @see ucol_collatorToIdentifier
1076 * @see ucol_openFromIdentifier
1077 * @see ucol_shortStringToIdentifier
1080 U_INTERNAL
int32_t U_EXPORT2
1081 ucol_identifierToShortString(uint32_t identifier
,
1084 UBool forceDefaults
,
1085 UErrorCode
*status
);
1088 * Calculate the identifier given a short definition string. Supports preflighting.
1089 * @param definition short string definition
1090 * @param forceDefaults whether the settings that are the same as the default setting
1091 * should be forced anyway. Setting this argument to FALSE reduces
1092 * the number of different configurations, but decreases performace
1093 * as a collator has to be instantiated.
1094 * @param status for returning errors
1095 * @return identifier
1096 * @see ucol_collatorToIdentifier
1097 * @see ucol_openFromIdentifier
1098 * @see ucol_identifierToShortString
1101 U_INTERNAL
uint32_t U_EXPORT2
1102 ucol_shortStringToIdentifier(const char *definition
,
1103 UBool forceDefaults
,
1104 UErrorCode
*status
);
1109 * Universal attribute getter that returns UCOL_DEFAULT if the value is default
1110 * @param coll collator which attributes are to be changed
1111 * @param attr attribute type
1112 * @return attribute value or UCOL_DEFAULT if the value is default
1113 * @param status to indicate whether the operation went on smoothly or there were errors
1114 * @see UColAttribute
1115 * @see UColAttributeValue
1116 * @see ucol_setAttribute
1119 U_INTERNAL UColAttributeValue U_EXPORT2
1120 ucol_getAttributeOrDefault(const UCollator
*coll
, UColAttribute attr
, UErrorCode
*status
);
1122 /** Check whether two collators are equal. Collators are considered equal if they
1123 * will sort strings the same. This means that both the current attributes and the
1124 * rules must be equivalent. Currently used for RuleBasedCollator::operator==.
1125 * @param source first collator
1126 * @param target second collator
1127 * @return TRUE or FALSE
1130 U_INTERNAL UBool U_EXPORT2
1131 ucol_equals(const UCollator
*source
, const UCollator
*target
);
1133 /** Calculates the set of unsafe code points, given a collator.
1134 * A character is unsafe if you could append any character and cause the ordering to alter significantly.
1135 * Collation sorts in normalized order, so anything that rearranges in normalization can cause this.
1136 * Thus if you have a character like a_umlaut, and you add a lower_dot to it,
1137 * then it normalizes to a_lower_dot + umlaut, and sorts differently.
1138 * @param coll Collator
1139 * @param unsafe a fill-in set to receive the unsafe points
1140 * @param status for catching errors
1141 * @return number of elements in the set
1144 U_INTERNAL
int32_t U_EXPORT2
1145 ucol_getUnsafeSet( const UCollator
*coll
,
1147 UErrorCode
*status
);
1149 /** Reset UCA's static pointers. You don't want to use this, unless your static memory can go away.
1150 * @internal ICU 3.2.1
1152 U_INTERNAL
void U_EXPORT2
1153 ucol_forgetUCA(void);
1155 /** Touches all resources needed for instantiating a collator from a short string definition,
1156 * thus filling up the cache.
1157 * @param definition A short string containing a locale and a set of attributes.
1158 * Attributes not explicitly mentioned are left at the default
1159 * state for a locale.
1160 * @param parseError if not NULL, structure that will get filled with error's pre
1161 * and post context in case of error.
1162 * @param forceDefaults if FALSE, the settings that are the same as the collator
1163 * default settings will not be applied (for example, setting
1164 * French secondary on a French collator would not be executed).
1165 * If TRUE, all the settings will be applied regardless of the
1166 * collator default value. If the definition
1167 * strings are to be cached, should be set to FALSE.
1168 * @param status Error code. Apart from regular error conditions connected to
1169 * instantiating collators (like out of memory or similar), this
1170 * API will return an error if an invalid attribute or attribute/value
1171 * combination is specified.
1172 * @see ucol_openFromShortString
1173 * @internal ICU 3.2.1
1175 U_INTERNAL
void U_EXPORT2
1176 ucol_prepareShortStringOpen( const char *definition
,
1177 UBool forceDefaults
,
1178 UParseError
*parseError
,
1179 UErrorCode
*status
);
1181 /** Creates a binary image of a collator. This binary image can be stored and
1182 * later used to instantiate a collator using ucol_openBinary.
1183 * This API supports preflighting.
1184 * @param coll Collator
1185 * @param buffer a fill-in buffer to receive the binary image
1186 * @param capacity capacity of the destination buffer
1187 * @param status for catching errors
1188 * @return size of the image
1189 * @see ucol_openBinary
1192 U_STABLE
int32_t U_EXPORT2
1193 ucol_cloneBinary(const UCollator
*coll
,
1194 uint8_t *buffer
, int32_t capacity
,
1195 UErrorCode
*status
);
1197 /** Opens a collator from a collator binary image created using
1198 * ucol_cloneBinary. Binary image used in instantiation of the
1199 * collator remains owned by the user and should stay around for
1200 * the lifetime of the collator. The API also takes a base collator
1201 * which usualy should be UCA.
1202 * @param bin binary image owned by the user and required through the
1203 * lifetime of the collator
1204 * @param length size of the image. If negative, the API will try to
1205 * figure out the length of the image
1206 * @param base fallback collator, usually UCA. Base is required to be
1207 * present through the lifetime of the collator. Currently
1208 * it cannot be NULL.
1209 * @param status for catching errors
1210 * @return newly created collator
1211 * @see ucol_cloneBinary
1214 U_STABLE UCollator
* U_EXPORT2
1215 ucol_openBinary(const uint8_t *bin
, int32_t length
,
1216 const UCollator
*base
,
1217 UErrorCode
*status
);
1220 #endif /* #if !UCONFIG_NO_COLLATION */