1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4*******************************************************************************
5* Copyright (c) 1996-2015, International Business Machines Corporation and others.
6* All Rights Reserved.
7*******************************************************************************
8*/
9
10#ifndef UCOL_H
11#define UCOL_H
12
13#include "unicode/utypes.h"
14
15#if !UCONFIG_NO_COLLATION
16
17#include "unicode/unorm.h"
18#include "unicode/parseerr.h"
19#include "unicode/uloc.h"
20#include "unicode/uset.h"
21#include "unicode/uscript.h"
22
23#if U_SHOW_CPLUSPLUS_API
24#include "unicode/localpointer.h"
25#endif // U_SHOW_CPLUSPLUS_API
26
27/**
28 * \file
29 * \brief C API: Collator
30 *
31 * <h2> Collator C API </h2>
32 *
33 * The C API for Collator performs locale-sensitive
34 * string comparison. You use this service to build
35 * searching and sorting routines for natural language text.
36 * <p>
37 * For more information about the collation service see
38 * <a href="https://unicode-org.github.io/icu/userguide/collation">the User Guide</a>.
39 * <p>
40 * Collation service provides correct sorting orders for most locales supported in ICU.
41 * If specific data for a locale is not available, the orders eventually falls back
42 * to the <a href="http://www.unicode.org/reports/tr35/tr35-collation.html#Root_Collation">CLDR root sort order</a>.
43 * <p>
44 * Sort ordering may be customized by providing your own set of rules. For more on
45 * this subject see the <a href="https://unicode-org.github.io/icu/userguide/collation/customization">
46 * Collation Customization</a> section of the User Guide.
47 * <p>
48 * @see UCollationResult
49 * @see UNormalizationMode
50 * @see UCollationStrength
51 * @see UCollationElements
52 */
53
54/** A collator.
55* For usage in C programs.
56*/
57struct UCollator;
58/** structure representing a collator object instance
59 * @stable ICU 2.0
60 */
61typedef struct UCollator UCollator;
62
63
64/**
65 * UCOL_LESS is returned if source string is compared to be less than target
66 * string in the ucol_strcoll() method.
67 * UCOL_EQUAL is returned if source string is compared to be equal to target
68 * string in the ucol_strcoll() method.
69 * UCOL_GREATER is returned if source string is compared to be greater than
70 * target string in the ucol_strcoll() method.
71 * @see ucol_strcoll()
72 * <p>
73 * Possible values for a comparison result
74 * @stable ICU 2.0
75 */
76typedef enum {
77 /** string a == string b */
78 UCOL_EQUAL = 0,
79 /** string a > string b */
80 UCOL_GREATER = 1,
81 /** string a < string b */
82 UCOL_LESS = -1
83} UCollationResult ;
84
85
86/** Enum containing attribute values for controlling collation behavior.
87 * Here are all the allowable values. Not every attribute can take every value. The only
88 * universal value is UCOL_DEFAULT, which resets the attribute value to the predefined
89 * value for that locale
90 * @stable ICU 2.0
91 */
92typedef enum {
93 /** accepted by most attributes */
94 UCOL_DEFAULT = -1,
95
96 /** Primary collation strength */
97 UCOL_PRIMARY = 0,
98 /** Secondary collation strength */
99 UCOL_SECONDARY = 1,
100 /** Tertiary collation strength */
101 UCOL_TERTIARY = 2,
102 /** Default collation strength */
103 UCOL_DEFAULT_STRENGTH = UCOL_TERTIARY,
104 UCOL_CE_STRENGTH_LIMIT,
105 /** Quaternary collation strength */
106 UCOL_QUATERNARY=3,
107 /** Identical collation strength */
108 UCOL_IDENTICAL=15,
109 UCOL_STRENGTH_LIMIT,
110
111 /** Turn the feature off - works for UCOL_FRENCH_COLLATION,
112 UCOL_CASE_LEVEL, UCOL_HIRAGANA_QUATERNARY_MODE
113 & UCOL_DECOMPOSITION_MODE*/
114 UCOL_OFF = 16,
115 /** Turn the feature on - works for UCOL_FRENCH_COLLATION,
116 UCOL_CASE_LEVEL, UCOL_HIRAGANA_QUATERNARY_MODE
117 & UCOL_DECOMPOSITION_MODE*/
118 UCOL_ON = 17,
119
120 /** Valid for UCOL_ALTERNATE_HANDLING. Alternate handling will be shifted */
121 UCOL_SHIFTED = 20,
122 /** Valid for UCOL_ALTERNATE_HANDLING. Alternate handling will be non ignorable */
123 UCOL_NON_IGNORABLE = 21,
124
125 /** Valid for UCOL_CASE_FIRST -
126 lower case sorts before upper case */
127 UCOL_LOWER_FIRST = 24,
128 /** upper case sorts before lower case */
129 UCOL_UPPER_FIRST = 25,
130
131#ifndef U_HIDE_DEPRECATED_API
132 /**
133 * One more than the highest normal UColAttributeValue value.
134 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
135 */
136 UCOL_ATTRIBUTE_VALUE_COUNT
137#endif /* U_HIDE_DEPRECATED_API */
138} UColAttributeValue;
139
140/**
141 * Enum containing the codes for reordering segments of the collation table that are not script
142 * codes. These reordering codes are to be used in conjunction with the script codes.
143 * @see ucol_getReorderCodes
144 * @see ucol_setReorderCodes
145 * @see ucol_getEquivalentReorderCodes
146 * @see UScriptCode
147 * @stable ICU 4.8
148 */
149 typedef enum {
150 /**
151 * A special reordering code that is used to specify the default
152 * reordering codes for a locale.
153 * @stable ICU 4.8
154 */
155 UCOL_REORDER_CODE_DEFAULT = -1,
156 /**
157 * A special reordering code that is used to specify no reordering codes.
158 * @stable ICU 4.8
159 */
160 UCOL_REORDER_CODE_NONE = USCRIPT_UNKNOWN,
161 /**
162 * A special reordering code that is used to specify all other codes used for
163 * reordering except for the codes lised as UColReorderCode values and those
164 * listed explicitly in a reordering.
165 * @stable ICU 4.8
166 */
167 UCOL_REORDER_CODE_OTHERS = USCRIPT_UNKNOWN,
168 /**
169 * Characters with the space property.
170 * This is equivalent to the rule value "space".
171 * @stable ICU 4.8
172 */
173 UCOL_REORDER_CODE_SPACE = 0x1000,
174 /**
175 * The first entry in the enumeration of reordering groups. This is intended for use in
176 * range checking and enumeration of the reorder codes.
177 * @stable ICU 4.8
178 */
179 UCOL_REORDER_CODE_FIRST = UCOL_REORDER_CODE_SPACE,
180 /**
181 * Characters with the punctuation property.
182 * This is equivalent to the rule value "punct".
183 * @stable ICU 4.8
184 */
185 UCOL_REORDER_CODE_PUNCTUATION = 0x1001,
186 /**
187 * Characters with the symbol property.
188 * This is equivalent to the rule value "symbol".
189 * @stable ICU 4.8
190 */
191 UCOL_REORDER_CODE_SYMBOL = 0x1002,
192 /**
193 * Characters with the currency property.
194 * This is equivalent to the rule value "currency".
195 * @stable ICU 4.8
196 */
197 UCOL_REORDER_CODE_CURRENCY = 0x1003,
198 /**
199 * Characters with the digit property.
200 * This is equivalent to the rule value "digit".
201 * @stable ICU 4.8
202 */
203 UCOL_REORDER_CODE_DIGIT = 0x1004,
204#ifndef U_HIDE_DEPRECATED_API
205 /**
206 * One more than the highest normal UColReorderCode value.
207 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
208 */
209 UCOL_REORDER_CODE_LIMIT = 0x1005
210#endif /* U_HIDE_DEPRECATED_API */
211} UColReorderCode;
212
213/**
214 * Base letter represents a primary difference. Set comparison
215 * level to UCOL_PRIMARY to ignore secondary and tertiary differences.
216 * Use this to set the strength of a Collator object.
217 * Example of primary difference, "abc" &lt; "abd"
218 *
219 * Diacritical differences on the same base letter represent a secondary
220 * difference. Set comparison level to UCOL_SECONDARY to ignore tertiary
221 * differences. Use this to set the strength of a Collator object.
222 * Example of secondary difference, "&auml;" >> "a".
223 *
224 * Uppercase and lowercase versions of the same character represents a
225 * tertiary difference. Set comparison level to UCOL_TERTIARY to include
226 * all comparison differences. Use this to set the strength of a Collator
227 * object.
228 * Example of tertiary difference, "abc" &lt;&lt;&lt; "ABC".
229 *
230 * Two characters are considered "identical" when they have the same
231 * unicode spellings. UCOL_IDENTICAL.
232 * For example, "&auml;" == "&auml;".
233 *
234 * UCollationStrength is also used to determine the strength of sort keys
235 * generated from UCollator objects
236 * These values can be now found in the UColAttributeValue enum.
237 * @stable ICU 2.0
238 **/
239typedef UColAttributeValue UCollationStrength;
240
241/** Attributes that collation service understands. All the attributes can take UCOL_DEFAULT
242 * value, as well as the values specific to each one.
243 * @stable ICU 2.0
244 */
245typedef enum {
246 /** Attribute for direction of secondary weights - used in Canadian French.
247 * Acceptable values are UCOL_ON, which results in secondary weights
248 * being considered backwards and UCOL_OFF which treats secondary
249 * weights in the order they appear.
250 * @stable ICU 2.0
251 */
252 UCOL_FRENCH_COLLATION,
253 /** Attribute for handling variable elements.
254 * Acceptable values are UCOL_NON_IGNORABLE
255 * which treats all the codepoints with non-ignorable
256 * primary weights in the same way,
257 * and UCOL_SHIFTED which causes codepoints with primary
258 * weights that are equal or below the variable top value
259 * to be ignored on primary level and moved to the quaternary
260 * level. The default setting in a Collator object depends on the
261 * locale data loaded from the resources. For most locales, the
262 * default is UCOL_NON_IGNORABLE, but for others, such as "th",
263 * the default could be UCOL_SHIFTED.
264 * @stable ICU 2.0
265 */
266 UCOL_ALTERNATE_HANDLING,
267 /** Controls the ordering of upper and lower case letters.
268 * Acceptable values are UCOL_OFF, which orders
269 * upper and lower case letters in accordance to their tertiary
270 * weights, UCOL_UPPER_FIRST which forces upper case letters to
271 * sort before lower case letters, and UCOL_LOWER_FIRST which does
272 * the opposite. The default setting in a Collator object depends on the
273 * locale data loaded from the resources. For most locales, the
274 * default is UCOL_OFF, but for others, such as "da" or "mt",
275 * the default could be UCOL_UPPER.
276 * @stable ICU 2.0
277 */
278 UCOL_CASE_FIRST,
279 /** Controls whether an extra case level (positioned before the third
280 * level) is generated or not. Acceptable values are UCOL_OFF,
281 * when case level is not generated, and UCOL_ON which causes the case
282 * level to be generated. Contents of the case level are affected by
283 * the value of UCOL_CASE_FIRST attribute. A simple way to ignore
284 * accent differences in a string is to set the strength to UCOL_PRIMARY
285 * and enable case level. The default setting in a Collator object depends
286 * on the locale data loaded from the resources.
287 * @stable ICU 2.0
288 */
289 UCOL_CASE_LEVEL,
290 /** Controls whether the normalization check and necessary normalizations
291 * are performed. When set to UCOL_OFF no normalization check
292 * is performed. The correctness of the result is guaranteed only if the
293 * input data is in so-called FCD form (see users manual for more info).
294 * When set to UCOL_ON, an incremental check is performed to see whether
295 * the input data is in the FCD form. If the data is not in the FCD form,
296 * incremental NFD normalization is performed. The default setting in a
297 * Collator object depends on the locale data loaded from the resources.
298 * For many locales, the default is UCOL_OFF, but for others, such as "hi"
299 * "vi', or "bn", * the default could be UCOL_ON.
300 * @stable ICU 2.0
301 */
302 UCOL_NORMALIZATION_MODE,
303 /** An alias for UCOL_NORMALIZATION_MODE attribute.
304 * @stable ICU 2.0
305 */
306 UCOL_DECOMPOSITION_MODE = UCOL_NORMALIZATION_MODE,
307 /** The strength attribute. Can be either UCOL_PRIMARY, UCOL_SECONDARY,
308 * UCOL_TERTIARY, UCOL_QUATERNARY or UCOL_IDENTICAL. The usual strength
309 * for most locales (except Japanese) is tertiary.
310 *
311 * Quaternary strength
312 * is useful when combined with shifted setting for alternate handling
313 * attribute and for JIS X 4061 collation, when it is used to distinguish
314 * between Katakana and Hiragana.
315 * Otherwise, quaternary level
316 * is affected only by the number of non-ignorable code points in
317 * the string.
318 *
319 * Identical strength is rarely useful, as it amounts
320 * to codepoints of the NFD form of the string.
321 * @stable ICU 2.0
322 */
323 UCOL_STRENGTH,
324#ifndef U_HIDE_DEPRECATED_API
325 /** When turned on, this attribute positions Hiragana before all
326 * non-ignorables on quaternary level This is a sneaky way to produce JIS
327 * sort order.
328 *
329 * This attribute was an implementation detail of the CLDR Japanese tailoring.
330 * Since ICU 50, this attribute is not settable any more via API functions.
331 * Since CLDR 25/ICU 53, explicit quaternary relations are used
332 * to achieve the same Japanese sort order.
333 *
334 * @deprecated ICU 50 Implementation detail, cannot be set via API, was removed from implementation.
335 */
336 UCOL_HIRAGANA_QUATERNARY_MODE = UCOL_STRENGTH + 1,
337#endif /* U_HIDE_DEPRECATED_API */
338 /**
339 * When turned on, this attribute makes
340 * substrings of digits sort according to their numeric values.
341 *
342 * This is a way to get '100' to sort AFTER '2'. Note that the longest
343 * digit substring that can be treated as a single unit is
344 * 254 digits (not counting leading zeros). If a digit substring is
345 * longer than that, the digits beyond the limit will be treated as a
346 * separate digit substring.
347 *
348 * A "digit" in this sense is a code point with General_Category=Nd,
349 * which does not include circled numbers, roman numerals, etc.
350 * Only a contiguous digit substring is considered, that is,
351 * non-negative integers without separators.
352 * There is no support for plus/minus signs, decimals, exponents, etc.
353 *
354 * @stable ICU 2.8
355 */
356 UCOL_NUMERIC_COLLATION = UCOL_STRENGTH + 2,
357
358 /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
359 * it is needed for layout of RuleBasedCollator object. */
360#ifndef U_FORCE_HIDE_DEPRECATED_API
361 /**
362 * One more than the highest normal UColAttribute value.
363 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
364 */
365 UCOL_ATTRIBUTE_COUNT
366#endif // U_FORCE_HIDE_DEPRECATED_API
367} UColAttribute;
368
369/** Options for retrieving the rule string
370 * @stable ICU 2.0
371 */
372typedef enum {
373 /**
374 * Retrieves the tailoring rules only.
375 * Same as calling the version of getRules() without UColRuleOption.
376 * @stable ICU 2.0
377 */
378 UCOL_TAILORING_ONLY,
379 /**
380 * Retrieves the "UCA rules" concatenated with the tailoring rules.
381 * The "UCA rules" are an <i>approximation</i> of the root collator's sort order.
382 * They are almost never used or useful at runtime and can be removed from the data.
383 * See https://unicode-org.github.io/icu/userguide/collation/customization#building-on-existing-locales
384 * @stable ICU 2.0
385 */
386 UCOL_FULL_RULES
387} UColRuleOption ;
388
389/**
390 * Open a UCollator for comparing strings.
391 *
392 * For some languages, multiple collation types are available;
393 * for example, "de@collation=phonebook".
394 * Starting with ICU 54, collation attributes can be specified via locale keywords as well,
395 * in the old locale extension syntax ("el@colCaseFirst=upper")
396 * or in language tag syntax ("el-u-kf-upper").
397 * See <a href="https://unicode-org.github.io/icu/userguide/collation/api">User Guide: Collation API</a>.
398 *
399 * The UCollator pointer is used in all the calls to the Collation
400 * service. After finished, collator must be disposed of by calling
401 * {@link #ucol_close }.
402 * @param loc The locale containing the required collation rules.
403 * Special values for locales can be passed in -
404 * if NULL is passed for the locale, the default locale
405 * collation rules will be used. If empty string ("") or
406 * "root" are passed, the root collator will be returned.
407 * @param status A pointer to a UErrorCode to receive any errors
408 * @return A pointer to a UCollator, or 0 if an error occurred.
409 * @see ucol_openRules
410 * @see ucol_clone
411 * @see ucol_close
412 * @stable ICU 2.0
413 */
414U_CAPI UCollator* U_EXPORT2
415ucol_open(const char *loc, UErrorCode *status);
416
417/**
418 * Produce a UCollator instance according to the rules supplied.
419 * The rules are used to change the default ordering, defined in the
420 * UCA in a process called tailoring. The resulting UCollator pointer
421 * can be used in the same way as the one obtained by {@link #ucol_strcoll }.
422 * @param rules A string describing the collation rules. For the syntax
423 * of the rules please see users guide.
424 * @param rulesLength The length of rules, or -1 if null-terminated.
425 * @param normalizationMode The normalization mode: One of
426 * UCOL_OFF (expect the text to not need normalization),
427 * UCOL_ON (normalize), or
428 * UCOL_DEFAULT (set the mode according to the rules)
429 * @param strength The default collation strength; one of UCOL_PRIMARY, UCOL_SECONDARY,
430 * UCOL_TERTIARY, UCOL_IDENTICAL,UCOL_DEFAULT_STRENGTH - can be also set in the rules.
431 * @param parseError A pointer to UParseError to receive information about errors
432 * occurred during parsing. This argument can currently be set
433 * to NULL, but at users own risk. Please provide a real structure.
434 * @param status A pointer to a UErrorCode to receive any errors
435 * @return A pointer to a UCollator. It is not guaranteed that NULL be returned in case
436 * of error - please use status argument to check for errors.
437 * @see ucol_open
438 * @see ucol_clone
439 * @see ucol_close
440 * @stable ICU 2.0
441 */
442U_CAPI UCollator* U_EXPORT2
443ucol_openRules( const UChar *rules,
444 int32_t rulesLength,
445 UColAttributeValue normalizationMode,
446 UCollationStrength strength,
447 UParseError *parseError,
448 UErrorCode *status);
449
450#ifndef U_HIDE_DEPRECATED_API
451/**
452 * Open a collator defined by a short form string.
453 * The structure and the syntax of the string is defined in the "Naming collators"
454 * section of the users guide:
455 * https://unicode-org.github.io/icu/userguide/collation/concepts#collator-naming-scheme
456 * Attributes are overridden by the subsequent attributes. So, for "S2_S3", final
457 * strength will be 3. 3066bis locale overrides individual locale parts.
458 * The call to this function is equivalent to a call to ucol_open, followed by a
459 * series of calls to ucol_setAttribute and ucol_setVariableTop.
460 * @param definition A short string containing a locale and a set of attributes.
461 * Attributes not explicitly mentioned are left at the default
462 * state for a locale.
463 * @param parseError if not NULL, structure that will get filled with error's pre
464 * and post context in case of error.
465 * @param forceDefaults if false, the settings that are the same as the collator
466 * default settings will not be applied (for example, setting
467 * French secondary on a French collator would not be executed).
468 * If true, all the settings will be applied regardless of the
469 * collator default value. If the definition
470 * strings are to be cached, should be set to false.
471 * @param status Error code. Apart from regular error conditions connected to
472 * instantiating collators (like out of memory or similar), this
473 * API will return an error if an invalid attribute or attribute/value
474 * combination is specified.
475 * @return A pointer to a UCollator or 0 if an error occurred (including an
476 * invalid attribute).
477 * @see ucol_open
478 * @see ucol_setAttribute
479 * @see ucol_setVariableTop
480 * @see ucol_getShortDefinitionString
481 * @see ucol_normalizeShortDefinitionString
482 * @deprecated ICU 54 Use ucol_open() with language tag collation keywords instead.
483 */
484U_DEPRECATED UCollator* U_EXPORT2
485ucol_openFromShortString( const char *definition,
486 UBool forceDefaults,
487 UParseError *parseError,
488 UErrorCode *status);
489#endif /* U_HIDE_DEPRECATED_API */
490
491#ifndef U_HIDE_DEPRECATED_API
492/**
493 * Get a set containing the contractions defined by the collator. The set includes
494 * both the root collator's contractions and the contractions defined by the collator. This set
495 * will contain only strings. If a tailoring explicitly suppresses contractions from
496 * the root collator (like Russian), removed contractions will not be in the resulting set.
497 * @param coll collator
498 * @param conts the set to hold the result. It gets emptied before
499 * contractions are added.
500 * @param status to hold the error code
501 * @return the size of the contraction set
502 *
503 * @deprecated ICU 3.4, use ucol_getContractionsAndExpansions instead
504 */
505U_DEPRECATED int32_t U_EXPORT2
506ucol_getContractions( const UCollator *coll,
507 USet *conts,
508 UErrorCode *status);
509#endif /* U_HIDE_DEPRECATED_API */
510
511/**
512 * Get a set containing the expansions defined by the collator. The set includes
513 * both the root collator's expansions and the expansions defined by the tailoring
514 * @param coll collator
515 * @param contractions if not NULL, the set to hold the contractions
516 * @param expansions if not NULL, the set to hold the expansions
517 * @param addPrefixes add the prefix contextual elements to contractions
518 * @param status to hold the error code
519 *
520 * @stable ICU 3.4
521 */
522U_CAPI void U_EXPORT2
523ucol_getContractionsAndExpansions( const UCollator *coll,
524 USet *contractions, USet *expansions,
525 UBool addPrefixes, UErrorCode *status);
526
527/**
528 * Close a UCollator.
529 * Once closed, a UCollator should not be used. Every open collator should
530 * be closed. Otherwise, a memory leak will result.
531 * @param coll The UCollator to close.
532 * @see ucol_open
533 * @see ucol_openRules
534 * @see ucol_clone
535 * @stable ICU 2.0
536 */
537U_CAPI void U_EXPORT2
538ucol_close(UCollator *coll);
539
540#if U_SHOW_CPLUSPLUS_API
541
542U_NAMESPACE_BEGIN
543
544/**
545 * \class LocalUCollatorPointer
546 * "Smart pointer" class, closes a UCollator via ucol_close().
547 * For most methods see the LocalPointerBase base class.
548 *
549 * @see LocalPointerBase
550 * @see LocalPointer
551 * @stable ICU 4.4
552 */
553U_DEFINE_LOCAL_OPEN_POINTER(LocalUCollatorPointer, UCollator, ucol_close);
554
555U_NAMESPACE_END
556
557#endif
558
559/**
560 * Compare two strings.
561 * The strings will be compared using the options already specified.
562 * @param coll The UCollator containing the comparison rules.
563 * @param source The source string.
564 * @param sourceLength The length of source, or -1 if null-terminated.
565 * @param target The target string.
566 * @param targetLength The length of target, or -1 if null-terminated.
567 * @return The result of comparing the strings; one of UCOL_EQUAL,
568 * UCOL_GREATER, UCOL_LESS
569 * @see ucol_greater
570 * @see ucol_greaterOrEqual
571 * @see ucol_equal
572 * @stable ICU 2.0
573 */
574U_CAPI UCollationResult U_EXPORT2
575ucol_strcoll( const UCollator *coll,
576 const UChar *source,
577 int32_t sourceLength,
578 const UChar *target,
579 int32_t targetLength);
580
581/**
582* Compare two strings in UTF-8.
583* The strings will be compared using the options already specified.
584* Note: When input string contains malformed a UTF-8 byte sequence,
585* this function treats these bytes as REPLACEMENT CHARACTER (U+FFFD).
586* @param coll The UCollator containing the comparison rules.
587* @param source The source UTF-8 string.
588* @param sourceLength The length of source, or -1 if null-terminated.
589* @param target The target UTF-8 string.
590* @param targetLength The length of target, or -1 if null-terminated.
591* @param status A pointer to a UErrorCode to receive any errors
592* @return The result of comparing the strings; one of UCOL_EQUAL,
593* UCOL_GREATER, UCOL_LESS
594* @see ucol_greater
595* @see ucol_greaterOrEqual
596* @see ucol_equal
597* @stable ICU 50
598*/
599U_CAPI UCollationResult U_EXPORT2
600ucol_strcollUTF8(
601 const UCollator *coll,
602 const char *source,
603 int32_t sourceLength,
604 const char *target,
605 int32_t targetLength,
606 UErrorCode *status);
607
608/**
609 * Determine if one string is greater than another.
610 * This function is equivalent to {@link #ucol_strcoll } == UCOL_GREATER
611 * @param coll The UCollator containing the comparison rules.
612 * @param source The source string.
613 * @param sourceLength The length of source, or -1 if null-terminated.
614 * @param target The target string.
615 * @param targetLength The length of target, or -1 if null-terminated.
616 * @return true if source is greater than target, false otherwise.
617 * @see ucol_strcoll
618 * @see ucol_greaterOrEqual
619 * @see ucol_equal
620 * @stable ICU 2.0
621 */
622U_CAPI UBool U_EXPORT2
623ucol_greater(const UCollator *coll,
624 const UChar *source, int32_t sourceLength,
625 const UChar *target, int32_t targetLength);
626
627/**
628 * Determine if one string is greater than or equal to another.
629 * This function is equivalent to {@link #ucol_strcoll } != UCOL_LESS
630 * @param coll The UCollator containing the comparison rules.
631 * @param source The source string.
632 * @param sourceLength The length of source, or -1 if null-terminated.
633 * @param target The target string.
634 * @param targetLength The length of target, or -1 if null-terminated.
635 * @return true if source is greater than or equal to target, false otherwise.
636 * @see ucol_strcoll
637 * @see ucol_greater
638 * @see ucol_equal
639 * @stable ICU 2.0
640 */
641U_CAPI UBool U_EXPORT2
642ucol_greaterOrEqual(const UCollator *coll,
643 const UChar *source, int32_t sourceLength,
644 const UChar *target, int32_t targetLength);
645
646/**
647 * Compare two strings for equality.
648 * This function is equivalent to {@link #ucol_strcoll } == UCOL_EQUAL
649 * @param coll The UCollator containing the comparison rules.
650 * @param source The source string.
651 * @param sourceLength The length of source, or -1 if null-terminated.
652 * @param target The target string.
653 * @param targetLength The length of target, or -1 if null-terminated.
654 * @return true if source is equal to target, false otherwise
655 * @see ucol_strcoll
656 * @see ucol_greater
657 * @see ucol_greaterOrEqual
658 * @stable ICU 2.0
659 */
660U_CAPI UBool U_EXPORT2
661ucol_equal(const UCollator *coll,
662 const UChar *source, int32_t sourceLength,
663 const UChar *target, int32_t targetLength);
664
665/**
666 * Compare two UTF-8 encoded strings.
667 * The strings will be compared using the options already specified.
668 * @param coll The UCollator containing the comparison rules.
669 * @param sIter The source string iterator.
670 * @param tIter The target string iterator.
671 * @return The result of comparing the strings; one of UCOL_EQUAL,
672 * UCOL_GREATER, UCOL_LESS
673 * @param status A pointer to a UErrorCode to receive any errors
674 * @see ucol_strcoll
675 * @stable ICU 2.6
676 */
677U_CAPI UCollationResult U_EXPORT2
678ucol_strcollIter( const UCollator *coll,
679 UCharIterator *sIter,
680 UCharIterator *tIter,
681 UErrorCode *status);
682
683/**
684 * Get the collation strength used in a UCollator.
685 * The strength influences how strings are compared.
686 * @param coll The UCollator to query.
687 * @return The collation strength; one of UCOL_PRIMARY, UCOL_SECONDARY,
688 * UCOL_TERTIARY, UCOL_QUATERNARY, UCOL_IDENTICAL
689 * @see ucol_setStrength
690 * @stable ICU 2.0
691 */
692U_CAPI UCollationStrength U_EXPORT2
693ucol_getStrength(const UCollator *coll);
694
695/**
696 * Set the collation strength used in a UCollator.
697 * The strength influences how strings are compared.
698 * @param coll The UCollator to set.
699 * @param strength The desired collation strength; one of UCOL_PRIMARY,
700 * UCOL_SECONDARY, UCOL_TERTIARY, UCOL_QUATERNARY, UCOL_IDENTICAL, UCOL_DEFAULT
701 * @see ucol_getStrength
702 * @stable ICU 2.0
703 */
704U_CAPI void U_EXPORT2
705ucol_setStrength(UCollator *coll,
706 UCollationStrength strength);
707
708/**
709 * Retrieves the reordering codes for this collator.
710 * These reordering codes are a combination of UScript codes and UColReorderCode entries.
711 * @param coll The UCollator to query.
712 * @param dest The array to fill with the script ordering.
713 * @param destCapacity The length of dest. If it is 0, then dest may be NULL and the function
714 * will only return the length of the result without writing any codes (pre-flighting).
715 * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate a
716 * failure before the function call.
717 * @return The number of reordering codes written to the dest array.
718 * @see ucol_setReorderCodes
719 * @see ucol_getEquivalentReorderCodes
720 * @see UScriptCode
721 * @see UColReorderCode
722 * @stable ICU 4.8
723 */
724U_CAPI int32_t U_EXPORT2
725ucol_getReorderCodes(const UCollator* coll,
726 int32_t* dest,
727 int32_t destCapacity,
728 UErrorCode *pErrorCode);
729/**
730 * Sets the reordering codes for this collator.
731 * Collation reordering allows scripts and some other groups of characters
732 * to be moved relative to each other. This reordering is done on top of
733 * the DUCET/CLDR standard collation order. Reordering can specify groups to be placed
734 * at the start and/or the end of the collation order. These groups are specified using
735 * UScript codes and UColReorderCode entries.
736 *
737 * <p>By default, reordering codes specified for the start of the order are placed in the
738 * order given after several special non-script blocks. These special groups of characters
739 * are space, punctuation, symbol, currency, and digit. These special groups are represented with
740 * UColReorderCode entries. Script groups can be intermingled with
741 * these special non-script groups if those special groups are explicitly specified in the reordering.
742 *
743 * <p>The special code OTHERS stands for any script that is not explicitly
744 * mentioned in the list of reordering codes given. Anything that is after OTHERS
745 * will go at the very end of the reordering in the order given.
746 *
747 * <p>The special reorder code DEFAULT will reset the reordering for this collator
748 * to the default for this collator. The default reordering may be the DUCET/CLDR order or may be a reordering that
749 * was specified when this collator was created from resource data or from rules. The
750 * DEFAULT code <b>must</b> be the sole code supplied when it is used.
751 * If not, then U_ILLEGAL_ARGUMENT_ERROR will be set.
752 *
753 * <p>The special reorder code NONE will remove any reordering for this collator.
754 * The result of setting no reordering will be to have the DUCET/CLDR ordering used. The
755 * NONE code <b>must</b> be the sole code supplied when it is used.
756 *
757 * @param coll The UCollator to set.
758 * @param reorderCodes An array of script codes in the new order. This can be NULL if the
759 * length is also set to 0. An empty array will clear any reordering codes on the collator.
760 * @param reorderCodesLength The length of reorderCodes.
761 * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate a
762 * failure before the function call.
763 * @see ucol_getReorderCodes
764 * @see ucol_getEquivalentReorderCodes
765 * @see UScriptCode
766 * @see UColReorderCode
767 * @stable ICU 4.8
768 */
769U_CAPI void U_EXPORT2
770ucol_setReorderCodes(UCollator* coll,
771 const int32_t* reorderCodes,
772 int32_t reorderCodesLength,
773 UErrorCode *pErrorCode);
774
775/**
776 * Retrieves the reorder codes that are grouped with the given reorder code. Some reorder
777 * codes will be grouped and must reorder together.
778 * Beginning with ICU 55, scripts only reorder together if they are primary-equal,
779 * for example Hiragana and Katakana.
780 *
781 * @param reorderCode The reorder code to determine equivalence for.
782 * @param dest The array to fill with the script ordering.
783 * @param destCapacity The length of dest. If it is 0, then dest may be NULL and the function
784 * will only return the length of the result without writing any codes (pre-flighting).
785 * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate
786 * a failure before the function call.
787 * @return The number of reordering codes written to the dest array.
788 * @see ucol_setReorderCodes
789 * @see ucol_getReorderCodes
790 * @see UScriptCode
791 * @see UColReorderCode
792 * @stable ICU 4.8
793 */
794U_CAPI int32_t U_EXPORT2
795ucol_getEquivalentReorderCodes(int32_t reorderCode,
796 int32_t* dest,
797 int32_t destCapacity,
798 UErrorCode *pErrorCode);
799
800/**
801 * Get the display name for a UCollator.
802 * The display name is suitable for presentation to a user.
803 * @param objLoc The locale of the collator in question.
804 * @param dispLoc The locale for display.
805 * @param result A pointer to a buffer to receive the attribute.
806 * @param resultLength The maximum size of result.
807 * @param status A pointer to a UErrorCode to receive any errors
808 * @return The total buffer size needed; if greater than resultLength,
809 * the output was truncated.
810 * @stable ICU 2.0
811 */
812U_CAPI int32_t U_EXPORT2
813ucol_getDisplayName( const char *objLoc,
814 const char *dispLoc,
815 UChar *result,
816 int32_t resultLength,
817 UErrorCode *status);
818
819/**
820 * Get a locale for which collation rules are available.
821 * A UCollator in a locale returned by this function will perform the correct
822 * collation for the locale.
823 * @param localeIndex The index of the desired locale.
824 * @return A locale for which collation rules are available, or 0 if none.
825 * @see ucol_countAvailable
826 * @stable ICU 2.0
827 */
828U_CAPI const char* U_EXPORT2
829ucol_getAvailable(int32_t localeIndex);
830
831/**
832 * Determine how many locales have collation rules available.
833 * This function is most useful as determining the loop ending condition for
834 * calls to {@link #ucol_getAvailable }.
835 * @return The number of locales for which collation rules are available.
836 * @see ucol_getAvailable
837 * @stable ICU 2.0
838 */
839U_CAPI int32_t U_EXPORT2
840ucol_countAvailable(void);
841
842#if !UCONFIG_NO_SERVICE
843/**
844 * Create a string enumerator of all locales for which a valid
845 * collator may be opened.
846 * @param status input-output error code
847 * @return a string enumeration over locale strings. The caller is
848 * responsible for closing the result.
849 * @stable ICU 3.0
850 */
851U_CAPI UEnumeration* U_EXPORT2
852ucol_openAvailableLocales(UErrorCode *status);
853#endif
854
855/**
856 * Create a string enumerator of all possible keywords that are relevant to
857 * collation. At this point, the only recognized keyword for this
858 * service is "collation".
859 * @param status input-output error code
860 * @return a string enumeration over locale strings. The caller is
861 * responsible for closing the result.
862 * @stable ICU 3.0
863 */
864U_CAPI UEnumeration* U_EXPORT2
865ucol_getKeywords(UErrorCode *status);
866
867/**
868 * Given a keyword, create a string enumeration of all values
869 * for that keyword that are currently in use.
870 * @param keyword a particular keyword as enumerated by
871 * ucol_getKeywords. If any other keyword is passed in, *status is set
872 * to U_ILLEGAL_ARGUMENT_ERROR.
873 * @param status input-output error code
874 * @return a string enumeration over collation keyword values, or NULL
875 * upon error. The caller is responsible for closing the result.
876 * @stable ICU 3.0
877 */
878U_CAPI UEnumeration* U_EXPORT2
879ucol_getKeywordValues(const char *keyword, UErrorCode *status);
880
881/**
882 * Given a key and a locale, returns an array of string values in a preferred
883 * order that would make a difference. These are all and only those values where
884 * the open (creation) of the service with the locale formed from the input locale
885 * plus input keyword and that value has different behavior than creation with the
886 * input locale alone.
887 * @param key one of the keys supported by this service. For now, only
888 * "collation" is supported.
889 * @param locale the locale
890 * @param commonlyUsed if set to true it will return only commonly used values
891 * with the given locale in preferred order. Otherwise,
892 * it will return all the available values for the locale.
893 * @param status error status
894 * @return a string enumeration over keyword values for the given key and the locale.
895 * @stable ICU 4.2
896 */
897U_CAPI UEnumeration* U_EXPORT2
898ucol_getKeywordValuesForLocale(const char* key,
899 const char* locale,
900 UBool commonlyUsed,
901 UErrorCode* status);
902
903/**
904 * Return the functionally equivalent locale for the specified
905 * input locale, with respect to given keyword, for the
906 * collation service. If two different input locale + keyword
907 * combinations produce the same result locale, then collators
908 * instantiated for these two different input locales will behave
909 * equivalently. The converse is not always true; two collators
910 * may in fact be equivalent, but return different results, due to
911 * internal details. The return result has no other meaning than
912 * that stated above, and implies nothing as to the relationship
913 * between the two locales. This is intended for use by
914 * applications who wish to cache collators, or otherwise reuse
915 * collators when possible. The functional equivalent may change
916 * over time. For more information, please see the <a
917 * href="https://unicode-org.github.io/icu/userguide/locale#locales-and-services">
918 * Locales and Services</a> section of the ICU User Guide.
919 * @param result fillin for the functionally equivalent result locale
920 * @param resultCapacity capacity of the fillin buffer
921 * @param keyword a particular keyword as enumerated by
922 * ucol_getKeywords.
923 * @param locale the specified input locale
924 * @param isAvailable if non-NULL, pointer to a fillin parameter that
925 * on return indicates whether the specified input locale was 'available'
926 * to the collation service. A locale is defined as 'available' if it
927 * physically exists within the collation locale data.
928 * @param status pointer to input-output error code
929 * @return the actual buffer size needed for the locale. If greater
930 * than resultCapacity, the returned full name will be truncated and
931 * an error code will be returned.
932 * @stable ICU 3.0
933 */
934U_CAPI int32_t U_EXPORT2
935ucol_getFunctionalEquivalent(char* result, int32_t resultCapacity,
936 const char* keyword, const char* locale,
937 UBool* isAvailable, UErrorCode* status);
938
939/**
940 * Get the collation tailoring rules from a UCollator.
941 * The rules will follow the rule syntax.
942 * @param coll The UCollator to query.
943 * @param length
944 * @return The collation tailoring rules.
945 * @stable ICU 2.0
946 */
947U_CAPI const UChar* U_EXPORT2
948ucol_getRules( const UCollator *coll,
949 int32_t *length);
950
951#ifndef U_HIDE_DEPRECATED_API
952/** Get the short definition string for a collator. This API harvests the collator's
953 * locale and the attribute set and produces a string that can be used for opening
954 * a collator with the same attributes using the ucol_openFromShortString API.
955 * This string will be normalized.
956 * The structure and the syntax of the string is defined in the "Naming collators"
957 * section of the users guide:
958 * https://unicode-org.github.io/icu/userguide/collation/concepts#collator-naming-scheme
959 * This API supports preflighting.
960 * @param coll a collator
961 * @param locale a locale that will appear as a collators locale in the resulting
962 * short string definition. If NULL, the locale will be harvested
963 * from the collator.
964 * @param buffer space to hold the resulting string
965 * @param capacity capacity of the buffer
966 * @param status for returning errors. All the preflighting errors are featured
967 * @return length of the resulting string
968 * @see ucol_openFromShortString
969 * @see ucol_normalizeShortDefinitionString
970 * @deprecated ICU 54
971 */
972U_DEPRECATED int32_t U_EXPORT2
973ucol_getShortDefinitionString(const UCollator *coll,
974 const char *locale,
975 char *buffer,
976 int32_t capacity,
977 UErrorCode *status);
978
979/** Verifies and normalizes short definition string.
980 * Normalized short definition string has all the option sorted by the argument name,
981 * so that equivalent definition strings are the same.
982 * This API supports preflighting.
983 * @param source definition string
984 * @param destination space to hold the resulting string
985 * @param capacity capacity of the buffer
986 * @param parseError if not NULL, structure that will get filled with error's pre
987 * and post context in case of error.
988 * @param status Error code. This API will return an error if an invalid attribute
989 * or attribute/value combination is specified. All the preflighting
990 * errors are also featured
991 * @return length of the resulting normalized string.
992 *
993 * @see ucol_openFromShortString
994 * @see ucol_getShortDefinitionString
995 *
996 * @deprecated ICU 54
997 */
998U_DEPRECATED int32_t U_EXPORT2
999ucol_normalizeShortDefinitionString(const char *source,
1000 char *destination,
1001 int32_t capacity,
1002 UParseError *parseError,
1003 UErrorCode *status);
1004#endif /* U_HIDE_DEPRECATED_API */
1005
1006
1007/**
1008 * Get a sort key for a string from a UCollator.
1009 * Sort keys may be compared using <TT>strcmp</TT>.
1010 *
1011 * Note that sort keys are often less efficient than simply doing comparison.
1012 * For more details, see the ICU User Guide.
1013 *
1014 * Like ICU functions that write to an output buffer, the buffer contents
1015 * is undefined if the buffer capacity (resultLength parameter) is too small.
1016 * Unlike ICU functions that write a string to an output buffer,
1017 * the terminating zero byte is counted in the sort key length.
1018 * @param coll The UCollator containing the collation rules.
1019 * @param source The string to transform.
1020 * @param sourceLength The length of source, or -1 if null-terminated.
1021 * @param result A pointer to a buffer to receive the attribute.
1022 * @param resultLength The maximum size of result.
1023 * @return The size needed to fully store the sort key.
1024 * If there was an internal error generating the sort key,
1025 * a zero value is returned.
1026 * @see ucol_keyHashCode
1027 * @stable ICU 2.0
1028 */
1029U_CAPI int32_t U_EXPORT2
1030ucol_getSortKey(const UCollator *coll,
1031 const UChar *source,
1032 int32_t sourceLength,
1033 uint8_t *result,
1034 int32_t resultLength);
1035
1036
1037/** Gets the next count bytes of a sort key. Caller needs
1038 * to preserve state array between calls and to provide
1039 * the same type of UCharIterator set with the same string.
1040 * The destination buffer provided must be big enough to store
1041 * the number of requested bytes.
1042 *
1043 * The generated sort key may or may not be compatible with
1044 * sort keys generated using ucol_getSortKey().
1045 * @param coll The UCollator containing the collation rules.
1046 * @param iter UCharIterator containing the string we need
1047 * the sort key to be calculated for.
1048 * @param state Opaque state of sortkey iteration.
1049 * @param dest Buffer to hold the resulting sortkey part
1050 * @param count number of sort key bytes required.
1051 * @param status error code indicator.
1052 * @return the actual number of bytes of a sortkey. It can be
1053 * smaller than count if we have reached the end of
1054 * the sort key.
1055 * @stable ICU 2.6
1056 */
1057U_CAPI int32_t U_EXPORT2
1058ucol_nextSortKeyPart(const UCollator *coll,
1059 UCharIterator *iter,
1060 uint32_t state[2],
1061 uint8_t *dest, int32_t count,
1062 UErrorCode *status);
1063
1064/** enum that is taken by ucol_getBound API
1065 * See below for explanation
1066 * do not change the values assigned to the
1067 * members of this enum. Underlying code
1068 * depends on them having these numbers
1069 * @stable ICU 2.0
1070 */
1071typedef enum {
1072 /** lower bound */
1073 UCOL_BOUND_LOWER = 0,
1074 /** upper bound that will match strings of exact size */
1075 UCOL_BOUND_UPPER = 1,
1076 /** upper bound that will match all the strings that have the same initial substring as the given string */
1077 UCOL_BOUND_UPPER_LONG = 2,
1078#ifndef U_HIDE_DEPRECATED_API
1079 /**
1080 * One more than the highest normal UColBoundMode value.
1081 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
1082 */
1083 UCOL_BOUND_VALUE_COUNT
1084#endif /* U_HIDE_DEPRECATED_API */
1085} UColBoundMode;
1086
1087/**
1088 * Produce a bound for a given sortkey and a number of levels.
1089 * Return value is always the number of bytes needed, regardless of
1090 * whether the result buffer was big enough or even valid.<br>
1091 * Resulting bounds can be used to produce a range of strings that are
1092 * between upper and lower bounds. For example, if bounds are produced
1093 * for a sortkey of string "smith", strings between upper and lower
1094 * bounds with one level would include "Smith", "SMITH", "sMiTh".<br>
1095 * There are two upper bounds that can be produced. If UCOL_BOUND_UPPER
1096 * is produced, strings matched would be as above. However, if bound
1097 * produced using UCOL_BOUND_UPPER_LONG is used, the above example will
1098 * also match "Smithsonian" and similar.<br>
1099 * For more on usage, see example in cintltst/capitst.c in procedure
1100 * TestBounds.
1101 * Sort keys may be compared using <TT>strcmp</TT>.
1102 * @param source The source sortkey.
1103 * @param sourceLength The length of source, or -1 if null-terminated.
1104 * (If an unmodified sortkey is passed, it is always null
1105 * terminated).
1106 * @param boundType Type of bound required. It can be UCOL_BOUND_LOWER, which
1107 * produces a lower inclusive bound, UCOL_BOUND_UPPER, that
1108 * produces upper bound that matches strings of the same length
1109 * or UCOL_BOUND_UPPER_LONG that matches strings that have the
1110 * same starting substring as the source string.
1111 * @param noOfLevels Number of levels required in the resulting bound (for most
1112 * uses, the recommended value is 1). See users guide for
1113 * explanation on number of levels a sortkey can have.
1114 * @param result A pointer to a buffer to receive the resulting sortkey.
1115 * @param resultLength The maximum size of result.
1116 * @param status Used for returning error code if something went wrong. If the
1117 * number of levels requested is higher than the number of levels
1118 * in the source key, a warning (U_SORT_KEY_TOO_SHORT_WARNING) is
1119 * issued.
1120 * @return The size needed to fully store the bound.
1121 * @see ucol_keyHashCode
1122 * @stable ICU 2.1
1123 */
1124U_CAPI int32_t U_EXPORT2
1125ucol_getBound(const uint8_t *source,
1126 int32_t sourceLength,
1127 UColBoundMode boundType,
1128 uint32_t noOfLevels,
1129 uint8_t *result,
1130 int32_t resultLength,
1131 UErrorCode *status);
1132
1133/**
1134 * Gets the version information for a Collator. Version is currently
1135 * an opaque 32-bit number which depends, among other things, on major
1136 * versions of the collator tailoring and UCA.
1137 * @param coll The UCollator to query.
1138 * @param info the version # information, the result will be filled in
1139 * @stable ICU 2.0
1140 */
1141U_CAPI void U_EXPORT2
1142ucol_getVersion(const UCollator* coll, UVersionInfo info);
1143
1144/**
1145 * Gets the UCA version information for a Collator. Version is the
1146 * UCA version number (3.1.1, 4.0).
1147 * @param coll The UCollator to query.
1148 * @param info the version # information, the result will be filled in
1149 * @stable ICU 2.8
1150 */
1151U_CAPI void U_EXPORT2
1152ucol_getUCAVersion(const UCollator* coll, UVersionInfo info);
1153
1154/**
1155 * Merges two sort keys. The levels are merged with their corresponding counterparts
1156 * (primaries with primaries, secondaries with secondaries etc.). Between the values
1157 * from the same level a separator is inserted.
1158 *
1159 * This is useful, for example, for combining sort keys from first and last names
1160 * to sort such pairs.
1161 * See http://www.unicode.org/reports/tr10/#Merging_Sort_Keys
1162 *
1163 * The recommended way to achieve "merged" sorting is by
1164 * concatenating strings with U+FFFE between them.
1165 * The concatenation has the same sort order as the merged sort keys,
1166 * but merge(getSortKey(str1), getSortKey(str2)) may differ from getSortKey(str1 + '\\uFFFE' + str2).
1167 * Using strings with U+FFFE may yield shorter sort keys.
1168 *
1169 * For details about Sort Key Features see
1170 * https://unicode-org.github.io/icu/userguide/collation/api#sort-key-features
1171 *
1172 * It is possible to merge multiple sort keys by consecutively merging
1173 * another one with the intermediate result.
1174 *
1175 * The length of the merge result is the sum of the lengths of the input sort keys.
1176 *
1177 * Example (uncompressed):
1178 * <pre>191B1D 01 050505 01 910505 00
1179 * 1F2123 01 050505 01 910505 00</pre>
1180 * will be merged as
1181 * <pre>191B1D 02 1F2123 01 050505 02 050505 01 910505 02 910505 00</pre>
1182 *
1183 * If the destination buffer is not big enough, then its contents are undefined.
1184 * If any of source lengths are zero or any of the source pointers are NULL/undefined,
1185 * the result is of size zero.
1186 *
1187 * @param src1 the first sort key
1188 * @param src1Length the length of the first sort key, including the zero byte at the end;
1189 * can be -1 if the function is to find the length
1190 * @param src2 the second sort key
1191 * @param src2Length the length of the second sort key, including the zero byte at the end;
1192 * can be -1 if the function is to find the length
1193 * @param dest the buffer where the merged sort key is written,
1194 * can be NULL if destCapacity==0
1195 * @param destCapacity the number of bytes in the dest buffer
1196 * @return the length of the merged sort key, src1Length+src2Length;
1197 * can be larger than destCapacity, or 0 if an error occurs (only for illegal arguments),
1198 * in which cases the contents of dest is undefined
1199 * @stable ICU 2.0
1200 */
1201U_CAPI int32_t U_EXPORT2
1202ucol_mergeSortkeys(const uint8_t *src1, int32_t src1Length,
1203 const uint8_t *src2, int32_t src2Length,
1204 uint8_t *dest, int32_t destCapacity);
1205
1206/**
1207 * Universal attribute setter
1208 * @param coll collator which attributes are to be changed
1209 * @param attr attribute type
1210 * @param value attribute value
1211 * @param status to indicate whether the operation went on smoothly or there were errors
1212 * @see UColAttribute
1213 * @see UColAttributeValue
1214 * @see ucol_getAttribute
1215 * @stable ICU 2.0
1216 */
1217U_CAPI void U_EXPORT2
1218ucol_setAttribute(UCollator *coll, UColAttribute attr, UColAttributeValue value, UErrorCode *status);
1219
1220/**
1221 * Universal attribute getter
1222 * @param coll collator which attributes are to be changed
1223 * @param attr attribute type
1224 * @return attribute value
1225 * @param status to indicate whether the operation went on smoothly or there were errors
1226 * @see UColAttribute
1227 * @see UColAttributeValue
1228 * @see ucol_setAttribute
1229 * @stable ICU 2.0
1230 */
1231U_CAPI UColAttributeValue U_EXPORT2
1232ucol_getAttribute(const UCollator *coll, UColAttribute attr, UErrorCode *status);
1233
1234/**
1235 * Sets the variable top to the top of the specified reordering group.
1236 * The variable top determines the highest-sorting character
1237 * which is affected by UCOL_ALTERNATE_HANDLING.
1238 * If that attribute is set to UCOL_NON_IGNORABLE, then the variable top has no effect.
1239 * @param coll the collator
1240 * @param group one of UCOL_REORDER_CODE_SPACE, UCOL_REORDER_CODE_PUNCTUATION,
1241 * UCOL_REORDER_CODE_SYMBOL, UCOL_REORDER_CODE_CURRENCY;
1242 * or UCOL_REORDER_CODE_DEFAULT to restore the default max variable group
1243 * @param pErrorCode Standard ICU error code. Its input value must
1244 * pass the U_SUCCESS() test, or else the function returns
1245 * immediately. Check for U_FAILURE() on output or use with
1246 * function chaining. (See User Guide for details.)
1247 * @see ucol_getMaxVariable
1248 * @stable ICU 53
1249 */
1250U_CAPI void U_EXPORT2
1251ucol_setMaxVariable(UCollator *coll, UColReorderCode group, UErrorCode *pErrorCode);
1252
1253/**
1254 * Returns the maximum reordering group whose characters are affected by UCOL_ALTERNATE_HANDLING.
1255 * @param coll the collator
1256 * @return the maximum variable reordering group.
1257 * @see ucol_setMaxVariable
1258 * @stable ICU 53
1259 */
1260U_CAPI UColReorderCode U_EXPORT2
1261ucol_getMaxVariable(const UCollator *coll);
1262
1263#ifndef U_HIDE_DEPRECATED_API
1264/**
1265 * Sets the variable top to the primary weight of the specified string.
1266 *
1267 * Beginning with ICU 53, the variable top is pinned to
1268 * the top of one of the supported reordering groups,
1269 * and it must not be beyond the last of those groups.
1270 * See ucol_setMaxVariable().
1271 * @param coll the collator
1272 * @param varTop one or more (if contraction) UChars to which the variable top should be set
1273 * @param len length of variable top string. If -1 it is considered to be zero terminated.
1274 * @param status error code. If error code is set, the return value is undefined.
1275 * Errors set by this function are:<br>
1276 * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction<br>
1277 * U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond
1278 * the last reordering group supported by ucol_setMaxVariable()
1279 * @return variable top primary weight
1280 * @see ucol_getVariableTop
1281 * @see ucol_restoreVariableTop
1282 * @deprecated ICU 53 Call ucol_setMaxVariable() instead.
1283 */
1284U_DEPRECATED uint32_t U_EXPORT2
1285ucol_setVariableTop(UCollator *coll,
1286 const UChar *varTop, int32_t len,
1287 UErrorCode *status);
1288#endif /* U_HIDE_DEPRECATED_API */
1289
1290/**
1291 * Gets the variable top value of a Collator.
1292 * @param coll collator which variable top needs to be retrieved
1293 * @param status error code (not changed by function). If error code is set,
1294 * the return value is undefined.
1295 * @return the variable top primary weight
1296 * @see ucol_getMaxVariable
1297 * @see ucol_setVariableTop
1298 * @see ucol_restoreVariableTop
1299 * @stable ICU 2.0
1300 */
1301U_CAPI uint32_t U_EXPORT2 ucol_getVariableTop(const UCollator *coll, UErrorCode *status);
1302
1303#ifndef U_HIDE_DEPRECATED_API
1304/**
1305 * Sets the variable top to the specified primary weight.
1306 *
1307 * Beginning with ICU 53, the variable top is pinned to
1308 * the top of one of the supported reordering groups,
1309 * and it must not be beyond the last of those groups.
1310 * See ucol_setMaxVariable().
1311 * @param coll collator to be set
1312 * @param varTop primary weight, as returned by ucol_setVariableTop or ucol_getVariableTop
1313 * @param status error code
1314 * @see ucol_getVariableTop
1315 * @see ucol_setVariableTop
1316 * @deprecated ICU 53 Call ucol_setMaxVariable() instead.
1317 */
1318U_DEPRECATED void U_EXPORT2
1319ucol_restoreVariableTop(UCollator *coll, const uint32_t varTop, UErrorCode *status);
1320#endif /* U_HIDE_DEPRECATED_API */
1321
1322/**
1323 * Thread safe cloning operation. The result is a clone of a given collator.
1324 * @param coll collator to be cloned
1325 * @param status to indicate whether the operation went on smoothly or there were errors
1326 * @return pointer to the new clone
1327 * @see ucol_open
1328 * @see ucol_openRules
1329 * @see ucol_close
1330 * @stable ICU 71
1331 */
1332U_CAPI UCollator* U_EXPORT2 ucol_clone(const UCollator *coll, UErrorCode *status);
1333
1334#ifndef U_HIDE_DEPRECATED_API
1335
1336/**
1337 * Thread safe cloning operation. The result is a clone of a given collator.
1338 * @param coll collator to be cloned
1339 * @param stackBuffer <em>Deprecated functionality as of ICU 52, use NULL.</em><br>
1340 * user allocated space for the new clone.
1341 * If NULL new memory will be allocated.
1342 * If buffer is not large enough, new memory will be allocated.
1343 * Clients can use the U_COL_SAFECLONE_BUFFERSIZE.
1344 * @param pBufferSize <em>Deprecated functionality as of ICU 52, use NULL or 1.</em><br>
1345 * pointer to size of allocated space.
1346 * If *pBufferSize == 0, a sufficient size for use in cloning will
1347 * be returned ('pre-flighting')
1348 * If *pBufferSize is not enough for a stack-based safe clone,
1349 * new memory will be allocated.
1350 * @param status to indicate whether the operation went on smoothly or there were errors
1351 * An informational status value, U_SAFECLONE_ALLOCATED_ERROR, is used
1352 * if pBufferSize != NULL and any allocations were necessary
1353 * @return pointer to the new clone
1354 * @see ucol_open
1355 * @see ucol_openRules
1356 * @see ucol_close
1357 * @deprecated ICU 71 Use ucol_clone() instead.
1358 */
1359U_DEPRECATED UCollator* U_EXPORT2
1360ucol_safeClone(const UCollator *coll,
1361 void *stackBuffer,
1362 int32_t *pBufferSize,
1363 UErrorCode *status);
1364
1365
1366/** default memory size for the new clone.
1367 * @deprecated ICU 52. Do not rely on ucol_safeClone() cloning into any provided buffer.
1368 */
1369#define U_COL_SAFECLONE_BUFFERSIZE 1
1370
1371#endif /* U_HIDE_DEPRECATED_API */
1372
1373/**
1374 * Returns current rules. Delta defines whether full rules are returned or just the tailoring.
1375 * Returns number of UChars needed to store rules. If buffer is NULL or bufferLen is not enough
1376 * to store rules, will store up to available space.
1377 *
1378 * ucol_getRules() should normally be used instead.
1379 * See https://unicode-org.github.io/icu/userguide/collation/customization#building-on-existing-locales
1380 * @param coll collator to get the rules from
1381 * @param delta one of UCOL_TAILORING_ONLY, UCOL_FULL_RULES.
1382 * @param buffer buffer to store the result in. If NULL, you'll get no rules.
1383 * @param bufferLen length of buffer to store rules in. If less than needed you'll get only the part that fits in.
1384 * @return current rules
1385 * @stable ICU 2.0
1386 * @see UCOL_FULL_RULES
1387 */
1388U_CAPI int32_t U_EXPORT2
1389ucol_getRulesEx(const UCollator *coll, UColRuleOption delta, UChar *buffer, int32_t bufferLen);
1390
1391#ifndef U_HIDE_DEPRECATED_API
1392/**
1393 * gets the locale name of the collator. If the collator
1394 * is instantiated from the rules, then this function returns
1395 * NULL.
1396 * @param coll The UCollator for which the locale is needed
1397 * @param type You can choose between requested, valid and actual
1398 * locale. For description see the definition of
1399 * ULocDataLocaleType in uloc.h
1400 * @param status error code of the operation
1401 * @return real locale name from which the collation data comes.
1402 * If the collator was instantiated from rules, returns
1403 * NULL.
1404 * @deprecated ICU 2.8 Use ucol_getLocaleByType instead
1405 */
1406U_DEPRECATED const char * U_EXPORT2
1407ucol_getLocale(const UCollator *coll, ULocDataLocaleType type, UErrorCode *status);
1408#endif /* U_HIDE_DEPRECATED_API */
1409
1410/**
1411 * gets the locale name of the collator. If the collator
1412 * is instantiated from the rules, then this function returns
1413 * NULL.
1414 * @param coll The UCollator for which the locale is needed
1415 * @param type You can choose between requested, valid and actual
1416 * locale. For description see the definition of
1417 * ULocDataLocaleType in uloc.h
1418 * @param status error code of the operation
1419 * @return real locale name from which the collation data comes.
1420 * If the collator was instantiated from rules, returns
1421 * NULL.
1422 * @stable ICU 2.8
1423 */
1424U_CAPI const char * U_EXPORT2
1425ucol_getLocaleByType(const UCollator *coll, ULocDataLocaleType type, UErrorCode *status);
1426
1427/**
1428 * Get a Unicode set that contains all the characters and sequences tailored in
1429 * this collator. The result must be disposed of by using uset_close.
1430 * @param coll The UCollator for which we want to get tailored chars
1431 * @param status error code of the operation
1432 * @return a pointer to newly created USet. Must be be disposed by using uset_close
1433 * @see ucol_openRules
1434 * @see uset_close
1435 * @stable ICU 2.4
1436 */
1437U_CAPI USet * U_EXPORT2
1438ucol_getTailoredSet(const UCollator *coll, UErrorCode *status);
1439
1440#ifndef U_HIDE_INTERNAL_API
1441/** Calculates the set of unsafe code points, given a collator.
1442 * A character is unsafe if you could append any character and cause the ordering to alter significantly.
1443 * Collation sorts in normalized order, so anything that rearranges in normalization can cause this.
1444 * Thus if you have a character like a_umlaut, and you add a lower_dot to it,
1445 * then it normalizes to a_lower_dot + umlaut, and sorts differently.
1446 * @param coll Collator
1447 * @param unsafe a fill-in set to receive the unsafe points
1448 * @param status for catching errors
1449 * @return number of elements in the set
1450 * @internal ICU 3.0
1451 */
1452U_CAPI int32_t U_EXPORT2
1453ucol_getUnsafeSet( const UCollator *coll,
1454 USet *unsafe,
1455 UErrorCode *status);
1456
1457/** Touches all resources needed for instantiating a collator from a short string definition,
1458 * thus filling up the cache.
1459 * @param definition A short string containing a locale and a set of attributes.
1460 * Attributes not explicitly mentioned are left at the default
1461 * state for a locale.
1462 * @param parseError if not NULL, structure that will get filled with error's pre
1463 * and post context in case of error.
1464 * @param forceDefaults if false, the settings that are the same as the collator
1465 * default settings will not be applied (for example, setting
1466 * French secondary on a French collator would not be executed).
1467 * If true, all the settings will be applied regardless of the
1468 * collator default value. If the definition
1469 * strings are to be cached, should be set to false.
1470 * @param status Error code. Apart from regular error conditions connected to
1471 * instantiating collators (like out of memory or similar), this
1472 * API will return an error if an invalid attribute or attribute/value
1473 * combination is specified.
1474 * @see ucol_openFromShortString
1475 * @internal ICU 3.2.1
1476 */
1477U_CAPI void U_EXPORT2
1478ucol_prepareShortStringOpen( const char *definition,
1479 UBool forceDefaults,
1480 UParseError *parseError,
1481 UErrorCode *status);
1482#endif /* U_HIDE_INTERNAL_API */
1483
1484/** Creates a binary image of a collator. This binary image can be stored and
1485 * later used to instantiate a collator using ucol_openBinary.
1486 * This API supports preflighting.
1487 * @param coll Collator
1488 * @param buffer a fill-in buffer to receive the binary image
1489 * @param capacity capacity of the destination buffer
1490 * @param status for catching errors
1491 * @return size of the image
1492 * @see ucol_openBinary
1493 * @stable ICU 3.2
1494 */
1495U_CAPI int32_t U_EXPORT2
1496ucol_cloneBinary(const UCollator *coll,
1497 uint8_t *buffer, int32_t capacity,
1498 UErrorCode *status);
1499
1500/** Opens a collator from a collator binary image created using
1501 * ucol_cloneBinary. Binary image used in instantiation of the
1502 * collator remains owned by the user and should stay around for
1503 * the lifetime of the collator. The API also takes a base collator
1504 * which must be the root collator.
1505 * @param bin binary image owned by the user and required through the
1506 * lifetime of the collator
1507 * @param length size of the image. If negative, the API will try to
1508 * figure out the length of the image
1509 * @param base Base collator, for lookup of untailored characters.
1510 * Must be the root collator, must not be NULL.
1511 * The base is required to be present through the lifetime of the collator.
1512 * @param status for catching errors
1513 * @return newly created collator
1514 * @see ucol_cloneBinary
1515 * @stable ICU 3.2
1516 */
1517U_CAPI UCollator* U_EXPORT2
1518ucol_openBinary(const uint8_t *bin, int32_t length,
1519 const UCollator *base,
1520 UErrorCode *status);
1521
1522
1523#endif /* #if !UCONFIG_NO_COLLATION */
1524
1525#endif
1526

source code of include/unicode/ucol.h