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