2 *******************************************************************************
3 * Copyright (c) 1996-2008, 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://source.icu-project.org/repos/icu/icuhtml/trunk/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-project.org/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-project.org/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-project.org/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_STABLE
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-project.org/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-project.org/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 * If there was an internal error generating the sort key,
693 * a zero value is returned.
694 * @see ucol_keyHashCode
697 U_STABLE
int32_t U_EXPORT2
698 ucol_getSortKey(const UCollator
*coll
,
700 int32_t sourceLength
,
702 int32_t resultLength
);
705 /** Gets the next count bytes of a sort key. Caller needs
706 * to preserve state array between calls and to provide
707 * the same type of UCharIterator set with the same string.
708 * The destination buffer provided must be big enough to store
709 * the number of requested bytes. Generated sortkey is not
710 * compatible with sortkeys generated using ucol_getSortKey
711 * API, since we don't do any compression. If uncompressed
712 * sortkeys are required, this API can be used.
713 * @param coll The UCollator containing the collation rules.
714 * @param iter UCharIterator containing the string we need
715 * the sort key to be calculated for.
716 * @param state Opaque state of sortkey iteration.
717 * @param dest Buffer to hold the resulting sortkey part
718 * @param count number of sort key bytes required.
719 * @param status error code indicator.
720 * @return the actual number of bytes of a sortkey. It can be
721 * smaller than count if we have reached the end of
725 U_STABLE
int32_t U_EXPORT2
726 ucol_nextSortKeyPart(const UCollator
*coll
,
729 uint8_t *dest
, int32_t count
,
732 /** enum that is taken by ucol_getBound API
733 * See below for explanation
734 * do not change the values assigned to the
735 * members of this enum. Underlying code
736 * depends on them having these numbers
741 UCOL_BOUND_LOWER
= 0,
742 /** upper bound that will match strings of exact size */
743 UCOL_BOUND_UPPER
= 1,
744 /** upper bound that will match all the strings that have the same initial substring as the given string */
745 UCOL_BOUND_UPPER_LONG
= 2,
746 UCOL_BOUND_VALUE_COUNT
750 * Produce a bound for a given sortkey and a number of levels.
751 * Return value is always the number of bytes needed, regardless of
752 * whether the result buffer was big enough or even valid.<br>
753 * Resulting bounds can be used to produce a range of strings that are
754 * between upper and lower bounds. For example, if bounds are produced
755 * for a sortkey of string "smith", strings between upper and lower
756 * bounds with one level would include "Smith", "SMITH", "sMiTh".<br>
757 * There are two upper bounds that can be produced. If UCOL_BOUND_UPPER
758 * is produced, strings matched would be as above. However, if bound
759 * produced using UCOL_BOUND_UPPER_LONG is used, the above example will
760 * also match "Smithsonian" and similar.<br>
761 * For more on usage, see example in cintltst/capitst.c in procedure
763 * Sort keys may be compared using <TT>strcmp</TT>.
764 * @param source The source sortkey.
765 * @param sourceLength The length of source, or -1 if null-terminated.
766 * (If an unmodified sortkey is passed, it is always null
768 * @param boundType Type of bound required. It can be UCOL_BOUND_LOWER, which
769 * produces a lower inclusive bound, UCOL_BOUND_UPPER, that
770 * produces upper bound that matches strings of the same length
771 * or UCOL_BOUND_UPPER_LONG that matches strings that have the
772 * same starting substring as the source string.
773 * @param noOfLevels Number of levels required in the resulting bound (for most
774 * uses, the recommended value is 1). See users guide for
775 * explanation on number of levels a sortkey can have.
776 * @param result A pointer to a buffer to receive the resulting sortkey.
777 * @param resultLength The maximum size of result.
778 * @param status Used for returning error code if something went wrong. If the
779 * number of levels requested is higher than the number of levels
780 * in the source key, a warning (U_SORT_KEY_TOO_SHORT_WARNING) is
782 * @return The size needed to fully store the bound.
783 * @see ucol_keyHashCode
786 U_STABLE
int32_t U_EXPORT2
787 ucol_getBound(const uint8_t *source
,
788 int32_t sourceLength
,
789 UColBoundMode boundType
,
792 int32_t resultLength
,
796 * Gets the version information for a Collator. Version is currently
797 * an opaque 32-bit number which depends, among other things, on major
798 * versions of the collator tailoring and UCA.
799 * @param coll The UCollator to query.
800 * @param info the version # information, the result will be filled in
803 U_STABLE
void U_EXPORT2
804 ucol_getVersion(const UCollator
* coll
, UVersionInfo info
);
807 * Gets the UCA version information for a Collator. Version is the
808 * UCA version number (3.1.1, 4.0).
809 * @param coll The UCollator to query.
810 * @param info the version # information, the result will be filled in
813 U_STABLE
void U_EXPORT2
814 ucol_getUCAVersion(const UCollator
* coll
, UVersionInfo info
);
817 * Merge two sort keys. The levels are merged with their corresponding counterparts
818 * (primaries with primaries, secondaries with secondaries etc.). Between the values
819 * from the same level a separator is inserted.
820 * example (uncompressed):
821 * 191B1D 01 050505 01 910505 00 and 1F2123 01 050505 01 910505 00
823 * 191B1D 02 1F212301 050505 02 050505 01 910505 02 910505 00
824 * This allows for concatenating of first and last names for sorting, among other things.
825 * If the destination buffer is not big enough, the results are undefined.
826 * If any of source lengths are zero or any of source pointers are NULL/undefined,
827 * result is of size zero.
828 * @param src1 pointer to the first sortkey
829 * @param src1Length length of the first sortkey
830 * @param src2 pointer to the second sortkey
831 * @param src2Length length of the second sortkey
832 * @param dest buffer to hold the result
833 * @param destCapacity size of the buffer for the result
834 * @return size of the result. If the buffer is big enough size is always
835 * src1Length+src2Length-1
838 U_STABLE
int32_t U_EXPORT2
839 ucol_mergeSortkeys(const uint8_t *src1
, int32_t src1Length
,
840 const uint8_t *src2
, int32_t src2Length
,
841 uint8_t *dest
, int32_t destCapacity
);
844 * Universal attribute setter
845 * @param coll collator which attributes are to be changed
846 * @param attr attribute type
847 * @param value attribute value
848 * @param status to indicate whether the operation went on smoothly or there were errors
850 * @see UColAttributeValue
851 * @see ucol_getAttribute
854 U_STABLE
void U_EXPORT2
855 ucol_setAttribute(UCollator
*coll
, UColAttribute attr
, UColAttributeValue value
, UErrorCode
*status
);
858 * Universal attribute getter
859 * @param coll collator which attributes are to be changed
860 * @param attr attribute type
861 * @return attribute value
862 * @param status to indicate whether the operation went on smoothly or there were errors
864 * @see UColAttributeValue
865 * @see ucol_setAttribute
868 U_STABLE UColAttributeValue U_EXPORT2
869 ucol_getAttribute(const UCollator
*coll
, UColAttribute attr
, UErrorCode
*status
);
872 * is a two byte primary value which causes all the codepoints with primary values that
873 * are less or equal than the variable top to be shifted when alternate handling is set
875 * Sets the variable top to a collation element value of a string supplied.
876 * @param coll collator which variable top needs to be changed
877 * @param varTop one or more (if contraction) UChars to which the variable top should be set
878 * @param len length of variable top string. If -1 it is considered to be zero terminated.
879 * @param status error code. If error code is set, the return value is undefined.
880 * Errors set by this function are: <br>
881 * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such
883 * U_PRIMARY_TOO_LONG_ERROR if the primary for the variable top has more than two bytes
884 * @return a 32 bit value containing the value of the variable top in upper 16 bits.
885 * Lower 16 bits are undefined
886 * @see ucol_getVariableTop
887 * @see ucol_restoreVariableTop
890 U_STABLE
uint32_t U_EXPORT2
891 ucol_setVariableTop(UCollator
*coll
,
892 const UChar
*varTop
, int32_t len
,
896 * Gets the variable top value of a Collator.
897 * Lower 16 bits are undefined and should be ignored.
898 * @param coll collator which variable top needs to be retrieved
899 * @param status error code (not changed by function). If error code is set,
900 * the return value is undefined.
901 * @return the variable top value of a Collator.
902 * @see ucol_setVariableTop
903 * @see ucol_restoreVariableTop
906 U_STABLE
uint32_t U_EXPORT2
ucol_getVariableTop(const UCollator
*coll
, UErrorCode
*status
);
909 * Sets the variable top to a collation element value supplied. Variable top is
910 * set to the upper 16 bits.
911 * Lower 16 bits are ignored.
912 * @param coll collator which variable top needs to be changed
913 * @param varTop CE value, as returned by ucol_setVariableTop or ucol)getVariableTop
914 * @param status error code (not changed by function)
915 * @see ucol_getVariableTop
916 * @see ucol_setVariableTop
919 U_STABLE
void U_EXPORT2
920 ucol_restoreVariableTop(UCollator
*coll
, const uint32_t varTop
, UErrorCode
*status
);
923 * Thread safe cloning operation. The result is a clone of a given collator.
924 * @param coll collator to be cloned
925 * @param stackBuffer user allocated space for the new clone.
926 * If NULL new memory will be allocated.
927 * If buffer is not large enough, new memory will be allocated.
928 * Clients can use the U_COL_SAFECLONE_BUFFERSIZE.
929 * This will probably be enough to avoid memory allocations.
930 * @param pBufferSize pointer to size of allocated space.
931 * If *pBufferSize == 0, a sufficient size for use in cloning will
932 * be returned ('pre-flighting')
933 * If *pBufferSize is not enough for a stack-based safe clone,
934 * new memory will be allocated.
935 * @param status to indicate whether the operation went on smoothly or there were errors
936 * An informational status value, U_SAFECLONE_ALLOCATED_ERROR, is used if any
937 * allocations were necessary.
938 * @return pointer to the new clone
940 * @see ucol_openRules
944 U_STABLE UCollator
* U_EXPORT2
945 ucol_safeClone(const UCollator
*coll
,
947 int32_t *pBufferSize
,
950 /** default memory size for the new clone. It needs to be this large for os/400 large pointers
953 #define U_COL_SAFECLONE_BUFFERSIZE 512
956 * Returns current rules. Delta defines whether full rules are returned or just the tailoring.
957 * Returns number of UChars needed to store rules. If buffer is NULL or bufferLen is not enough
958 * to store rules, will store up to available space.
959 * @param coll collator to get the rules from
960 * @param delta one of UCOL_TAILORING_ONLY, UCOL_FULL_RULES.
961 * @param buffer buffer to store the result in. If NULL, you'll get no rules.
962 * @param bufferLen lenght of buffer to store rules in. If less then needed you'll get only the part that fits in.
963 * @return current rules
966 U_STABLE
int32_t U_EXPORT2
967 ucol_getRulesEx(const UCollator
*coll
, UColRuleOption delta
, UChar
*buffer
, int32_t bufferLen
);
970 * gets the locale name of the collator. If the collator
971 * is instantiated from the rules, then this function returns
973 * @param coll The UCollator for which the locale is needed
974 * @param type You can choose between requested, valid and actual
975 * locale. For description see the definition of
976 * ULocDataLocaleType in uloc.h
977 * @param status error code of the operation
978 * @return real locale name from which the collation data comes.
979 * If the collator was instantiated from rules, returns
981 * @deprecated ICU 2.8 Use ucol_getLocaleByType instead
983 U_DEPRECATED
const char * U_EXPORT2
984 ucol_getLocale(const UCollator
*coll
, ULocDataLocaleType type
, UErrorCode
*status
);
988 * gets the locale name of the collator. If the collator
989 * is instantiated from the rules, then this function returns
991 * @param coll The UCollator for which the locale is needed
992 * @param type You can choose between requested, valid and actual
993 * locale. For description see the definition of
994 * ULocDataLocaleType in uloc.h
995 * @param status error code of the operation
996 * @return real locale name from which the collation data comes.
997 * If the collator was instantiated from rules, returns
1001 U_STABLE
const char * U_EXPORT2
1002 ucol_getLocaleByType(const UCollator
*coll
, ULocDataLocaleType type
, UErrorCode
*status
);
1005 * Get an Unicode set that contains all the characters and sequences tailored in
1006 * this collator. The result must be disposed of by using uset_close.
1007 * @param coll The UCollator for which we want to get tailored chars
1008 * @param status error code of the operation
1009 * @return a pointer to newly created USet. Must be be disposed by using uset_close
1010 * @see ucol_openRules
1014 U_STABLE USet
* U_EXPORT2
1015 ucol_getTailoredSet(const UCollator
*coll
, UErrorCode
*status
);
1018 * Universal attribute getter that returns UCOL_DEFAULT if the value is default
1019 * @param coll collator which attributes are to be changed
1020 * @param attr attribute type
1021 * @return attribute value or UCOL_DEFAULT if the value is default
1022 * @param status to indicate whether the operation went on smoothly or there were errors
1023 * @see UColAttribute
1024 * @see UColAttributeValue
1025 * @see ucol_setAttribute
1028 U_INTERNAL UColAttributeValue U_EXPORT2
1029 ucol_getAttributeOrDefault(const UCollator
*coll
, UColAttribute attr
, UErrorCode
*status
);
1031 /** Check whether two collators are equal. Collators are considered equal if they
1032 * will sort strings the same. This means that both the current attributes and the
1033 * rules must be equivalent. Currently used for RuleBasedCollator::operator==.
1034 * @param source first collator
1035 * @param target second collator
1036 * @return TRUE or FALSE
1039 U_INTERNAL UBool U_EXPORT2
1040 ucol_equals(const UCollator
*source
, const UCollator
*target
);
1042 /** Calculates the set of unsafe code points, given a collator.
1043 * A character is unsafe if you could append any character and cause the ordering to alter significantly.
1044 * Collation sorts in normalized order, so anything that rearranges in normalization can cause this.
1045 * Thus if you have a character like a_umlaut, and you add a lower_dot to it,
1046 * then it normalizes to a_lower_dot + umlaut, and sorts differently.
1047 * @param coll Collator
1048 * @param unsafe a fill-in set to receive the unsafe points
1049 * @param status for catching errors
1050 * @return number of elements in the set
1053 U_INTERNAL
int32_t U_EXPORT2
1054 ucol_getUnsafeSet( const UCollator
*coll
,
1056 UErrorCode
*status
);
1058 /** Reset UCA's static pointers. You don't want to use this, unless your static memory can go away.
1059 * @internal ICU 3.2.1
1061 U_INTERNAL
void U_EXPORT2
1062 ucol_forgetUCA(void);
1064 /** Touches all resources needed for instantiating a collator from a short string definition,
1065 * thus filling up the cache.
1066 * @param definition A short string containing a locale and a set of attributes.
1067 * Attributes not explicitly mentioned are left at the default
1068 * state for a locale.
1069 * @param parseError if not NULL, structure that will get filled with error's pre
1070 * and post context in case of error.
1071 * @param forceDefaults if FALSE, the settings that are the same as the collator
1072 * default settings will not be applied (for example, setting
1073 * French secondary on a French collator would not be executed).
1074 * If TRUE, all the settings will be applied regardless of the
1075 * collator default value. If the definition
1076 * strings are to be cached, should be set to FALSE.
1077 * @param status Error code. Apart from regular error conditions connected to
1078 * instantiating collators (like out of memory or similar), this
1079 * API will return an error if an invalid attribute or attribute/value
1080 * combination is specified.
1081 * @see ucol_openFromShortString
1082 * @internal ICU 3.2.1
1084 U_INTERNAL
void U_EXPORT2
1085 ucol_prepareShortStringOpen( const char *definition
,
1086 UBool forceDefaults
,
1087 UParseError
*parseError
,
1088 UErrorCode
*status
);
1090 /** Creates a binary image of a collator. This binary image can be stored and
1091 * later used to instantiate a collator using ucol_openBinary.
1092 * This API supports preflighting.
1093 * @param coll Collator
1094 * @param buffer a fill-in buffer to receive the binary image
1095 * @param capacity capacity of the destination buffer
1096 * @param status for catching errors
1097 * @return size of the image
1098 * @see ucol_openBinary
1101 U_STABLE
int32_t U_EXPORT2
1102 ucol_cloneBinary(const UCollator
*coll
,
1103 uint8_t *buffer
, int32_t capacity
,
1104 UErrorCode
*status
);
1106 /** Opens a collator from a collator binary image created using
1107 * ucol_cloneBinary. Binary image used in instantiation of the
1108 * collator remains owned by the user and should stay around for
1109 * the lifetime of the collator. The API also takes a base collator
1110 * which usualy should be UCA.
1111 * @param bin binary image owned by the user and required through the
1112 * lifetime of the collator
1113 * @param length size of the image. If negative, the API will try to
1114 * figure out the length of the image
1115 * @param base fallback collator, usually UCA. Base is required to be
1116 * present through the lifetime of the collator. Currently
1117 * it cannot be NULL.
1118 * @param status for catching errors
1119 * @return newly created collator
1120 * @see ucol_cloneBinary
1123 U_STABLE UCollator
* U_EXPORT2
1124 ucol_openBinary(const uint8_t *bin
, int32_t length
,
1125 const UCollator
*base
,
1126 UErrorCode
*status
);
1129 #endif /* #if !UCONFIG_NO_COLLATION */