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