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