37 * For more information about the collation service see 38 * the User Guide. 39 *
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 CLDR root sort order. 43 *
44 * Sort ordering may be customized by providing your own set of rules. For more on 45 * this subject see the 46 * Collation Customization section of the User Guide. 47 *
48 * @see UCollationResult 49 * @see UNormalizationMode 50 * @see UCollationStrength 51 * @see UCollationElements 52 */ 53 54 /** A collator. 55 * For usage in C programs. 56 */ 57 struct UCollator; 58 /** structure representing a collator object instance 59 * @stable ICU 2.0 60 */ 61 typedef struct UCollator UCollator; 62 63 64 /** 65 * UCOL_LESS is returned if source string is compared to be less than target 66 * string in the ucol_strcoll() method. 67 * UCOL_EQUAL is returned if source string is compared to be equal to target 68 * string in the ucol_strcoll() method. 69 * UCOL_GREATER is returned if source string is compared to be greater than 70 * target string in the ucol_strcoll() method. 71 * @see ucol_strcoll() 72 *
73 * Possible values for a comparison result 74 * @stable ICU 2.0 75 */ 76 typedef enum { 77 /** string a == string b */ 78 UCOL_EQUAL = 0, 79 /** string a > string b */ 80 UCOL_GREATER = 1, 81 /** string a < string b */ 82 UCOL_LESS = -1 83 } UCollationResult ; 84 85 86 /** Enum containing attribute values for controlling collation behavior. 87 * Here are all the allowable values. Not every attribute can take every value. The only 88 * universal value is UCOL_DEFAULT, which resets the attribute value to the predefined 89 * value for that locale 90 * @stable ICU 2.0 91 */ 92 typedef enum { 93 /** accepted by most attributes */ 94 UCOL_DEFAULT = -1, 95 96 /** Primary collation strength */ 97 UCOL_PRIMARY = 0, 98 /** Secondary collation strength */ 99 UCOL_SECONDARY = 1, 100 /** Tertiary collation strength */ 101 UCOL_TERTIARY = 2, 102 /** Default collation strength */ 103 UCOL_DEFAULT_STRENGTH = UCOL_TERTIARY, 104 UCOL_CE_STRENGTH_LIMIT, 105 /** Quaternary collation strength */ 106 UCOL_QUATERNARY=3, 107 /** Identical collation strength */ 108 UCOL_IDENTICAL=15, 109 UCOL_STRENGTH_LIMIT, 110 111 /** Turn the feature off - works for UCOL_FRENCH_COLLATION, 112 UCOL_CASE_LEVEL, UCOL_HIRAGANA_QUATERNARY_MODE 113 & UCOL_DECOMPOSITION_MODE*/ 114 UCOL_OFF = 16, 115 /** Turn the feature on - works for UCOL_FRENCH_COLLATION, 116 UCOL_CASE_LEVEL, UCOL_HIRAGANA_QUATERNARY_MODE 117 & UCOL_DECOMPOSITION_MODE*/ 118 UCOL_ON = 17, 119 120 /** Valid for UCOL_ALTERNATE_HANDLING. Alternate handling will be shifted */ 121 UCOL_SHIFTED = 20, 122 /** Valid for UCOL_ALTERNATE_HANDLING. Alternate handling will be non ignorable */ 123 UCOL_NON_IGNORABLE = 21, 124 125 /** Valid for UCOL_CASE_FIRST - 126 lower case sorts before upper case */ 127 UCOL_LOWER_FIRST = 24, 128 /** upper case sorts before lower case */ 129 UCOL_UPPER_FIRST = 25, 130 131 #ifndef U_HIDE_DEPRECATED_API 132 /** 133 * One more than the highest normal UColAttributeValue value. 134 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 135 */ 136 UCOL_ATTRIBUTE_VALUE_COUNT 137 #endif /* U_HIDE_DEPRECATED_API */ 138 } UColAttributeValue; 139 140 /** 141 * Enum containing the codes for reordering segments of the collation table that are not script 142 * codes. These reordering codes are to be used in conjunction with the script codes. 143 * @see ucol_getReorderCodes 144 * @see ucol_setReorderCodes 145 * @see ucol_getEquivalentReorderCodes 146 * @see UScriptCode 147 * @stable ICU 4.8 148 */ 149 typedef enum { 150 /** 151 * A special reordering code that is used to specify the default 152 * reordering codes for a locale. 153 * @stable ICU 4.8 154 */ 155 UCOL_REORDER_CODE_DEFAULT = -1, 156 /** 157 * A special reordering code that is used to specify no reordering codes. 158 * @stable ICU 4.8 159 */ 160 UCOL_REORDER_CODE_NONE = USCRIPT_UNKNOWN, 161 /** 162 * A special reordering code that is used to specify all other codes used for 163 * reordering except for the codes lised as UColReorderCode values and those 164 * listed explicitly in a reordering. 165 * @stable ICU 4.8 166 */ 167 UCOL_REORDER_CODE_OTHERS = USCRIPT_UNKNOWN, 168 /** 169 * Characters with the space property. 170 * This is equivalent to the rule value "space". 171 * @stable ICU 4.8 172 */ 173 UCOL_REORDER_CODE_SPACE = 0x1000, 174 /** 175 * The first entry in the enumeration of reordering groups. This is intended for use in 176 * range checking and enumeration of the reorder codes. 177 * @stable ICU 4.8 178 */ 179 UCOL_REORDER_CODE_FIRST = UCOL_REORDER_CODE_SPACE, 180 /** 181 * Characters with the punctuation property. 182 * This is equivalent to the rule value "punct". 183 * @stable ICU 4.8 184 */ 185 UCOL_REORDER_CODE_PUNCTUATION = 0x1001, 186 /** 187 * Characters with the symbol property. 188 * This is equivalent to the rule value "symbol". 189 * @stable ICU 4.8 190 */ 191 UCOL_REORDER_CODE_SYMBOL = 0x1002, 192 /** 193 * Characters with the currency property. 194 * This is equivalent to the rule value "currency". 195 * @stable ICU 4.8 196 */ 197 UCOL_REORDER_CODE_CURRENCY = 0x1003, 198 /** 199 * Characters with the digit property. 200 * This is equivalent to the rule value "digit". 201 * @stable ICU 4.8 202 */ 203 UCOL_REORDER_CODE_DIGIT = 0x1004, 204 #ifndef U_HIDE_DEPRECATED_API 205 /** 206 * One more than the highest normal UColReorderCode value. 207 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 208 */ 209 UCOL_REORDER_CODE_LIMIT = 0x1005 210 #endif /* U_HIDE_DEPRECATED_API */ 211 } UColReorderCode; 212 213 /** 214 * Base letter represents a primary difference. Set comparison 215 * level to UCOL_PRIMARY to ignore secondary and tertiary differences. 216 * Use this to set the strength of a Collator object. 217 * Example of primary difference, "abc" < "abd" 218 * 219 * Diacritical differences on the same base letter represent a secondary 220 * difference. Set comparison level to UCOL_SECONDARY to ignore tertiary 221 * differences. Use this to set the strength of a Collator object. 222 * Example of secondary difference, "ä" >> "a". 223 * 224 * Uppercase and lowercase versions of the same character represents a 225 * tertiary difference. Set comparison level to UCOL_TERTIARY to include 226 * all comparison differences. Use this to set the strength of a Collator 227 * object. 228 * Example of tertiary difference, "abc" <<< "ABC". 229 * 230 * Two characters are considered "identical" when they have the same 231 * unicode spellings. UCOL_IDENTICAL. 232 * For example, "ä" == "ä". 233 * 234 * UCollationStrength is also used to determine the strength of sort keys 235 * generated from UCollator objects 236 * These values can be now found in the UColAttributeValue enum. 237 * @stable ICU 2.0 238 **/ 239 typedef UColAttributeValue UCollationStrength; 240 241 /** Attributes that collation service understands. All the attributes can take UCOL_DEFAULT 242 * value, as well as the values specific to each one. 243 * @stable ICU 2.0 244 */ 245 typedef enum { 246 /** Attribute for direction of secondary weights - used in Canadian French. 247 * Acceptable values are UCOL_ON, which results in secondary weights 248 * being considered backwards and UCOL_OFF which treats secondary 249 * weights in the order they appear. 250 * @stable ICU 2.0 251 */ 252 UCOL_FRENCH_COLLATION, 253 /** Attribute for handling variable elements. 254 * Acceptable values are UCOL_NON_IGNORABLE 255 * which treats all the codepoints with non-ignorable 256 * primary weights in the same way, 257 * and UCOL_SHIFTED which causes codepoints with primary 258 * weights that are equal or below the variable top value 259 * to be ignored on primary level and moved to the quaternary 260 * level. The default setting in a Collator object depends on the 261 * locale data loaded from the resources. For most locales, the 262 * default is UCOL_NON_IGNORABLE, but for others, such as "th", 263 * the default could be UCOL_SHIFTED. 264 * @stable ICU 2.0 265 */ 266 UCOL_ALTERNATE_HANDLING, 267 /** Controls the ordering of upper and lower case letters. 268 * Acceptable values are UCOL_OFF, which orders 269 * upper and lower case letters in accordance to their tertiary 270 * weights, UCOL_UPPER_FIRST which forces upper case letters to 271 * sort before lower case letters, and UCOL_LOWER_FIRST which does 272 * the opposite. The default setting in a Collator object depends on the 273 * locale data loaded from the resources. For most locales, the 274 * default is UCOL_OFF, but for others, such as "da" or "mt", 275 * the default could be UCOL_UPPER. 276 * @stable ICU 2.0 277 */ 278 UCOL_CASE_FIRST, 279 /** Controls whether an extra case level (positioned before the third 280 * level) is generated or not. Acceptable values are UCOL_OFF, 281 * when case level is not generated, and UCOL_ON which causes the case 282 * level to be generated. Contents of the case level are affected by 283 * the value of UCOL_CASE_FIRST attribute. A simple way to ignore 284 * accent differences in a string is to set the strength to UCOL_PRIMARY 285 * and enable case level. The default setting in a Collator object depends 286 * on the locale data loaded from the resources. 287 * @stable ICU 2.0 288 */ 289 UCOL_CASE_LEVEL, 290 /** Controls whether the normalization check and necessary normalizations 291 * are performed. When set to UCOL_OFF no normalization check 292 * is performed. The correctness of the result is guaranteed only if the 293 * input data is in so-called FCD form (see users manual for more info). 294 * When set to UCOL_ON, an incremental check is performed to see whether 295 * the input data is in the FCD form. If the data is not in the FCD form, 296 * incremental NFD normalization is performed. The default setting in a 297 * Collator object depends on the locale data loaded from the resources. 298 * For many locales, the default is UCOL_OFF, but for others, such as "hi" 299 * "vi', or "bn", * the default could be UCOL_ON. 300 * @stable ICU 2.0 301 */ 302 UCOL_NORMALIZATION_MODE, 303 /** An alias for UCOL_NORMALIZATION_MODE attribute. 304 * @stable ICU 2.0 305 */ 306 UCOL_DECOMPOSITION_MODE = UCOL_NORMALIZATION_MODE, 307 /** The strength attribute. Can be either UCOL_PRIMARY, UCOL_SECONDARY, 308 * UCOL_TERTIARY, UCOL_QUATERNARY or UCOL_IDENTICAL. The usual strength 309 * for most locales (except Japanese) is tertiary. 310 * 311 * Quaternary strength 312 * is useful when combined with shifted setting for alternate handling 313 * attribute and for JIS X 4061 collation, when it is used to distinguish 314 * between Katakana and Hiragana. 315 * Otherwise, quaternary level 316 * is affected only by the number of non-ignorable code points in 317 * the string. 318 * 319 * Identical strength is rarely useful, as it amounts 320 * to codepoints of the NFD form of the string. 321 * @stable ICU 2.0 322 */ 323 UCOL_STRENGTH, 324 #ifndef U_HIDE_DEPRECATED_API 325 /** When turned on, this attribute positions Hiragana before all 326 * non-ignorables on quaternary level This is a sneaky way to produce JIS 327 * sort order. 328 * 329 * This attribute was an implementation detail of the CLDR Japanese tailoring. 330 * Since ICU 50, this attribute is not settable any more via API functions. 331 * Since CLDR 25/ICU 53, explicit quaternary relations are used 332 * to achieve the same Japanese sort order. 333 * 334 * @deprecated ICU 50 Implementation detail, cannot be set via API, was removed from implementation. 335 */ 336 UCOL_HIRAGANA_QUATERNARY_MODE = UCOL_STRENGTH + 1, 337 #endif /* U_HIDE_DEPRECATED_API */ 338 /** 339 * When turned on, this attribute makes 340 * substrings of digits sort according to their numeric values. 341 * 342 * This is a way to get '100' to sort AFTER '2'. Note that the longest 343 * digit substring that can be treated as a single unit is 344 * 254 digits (not counting leading zeros). If a digit substring is 345 * longer than that, the digits beyond the limit will be treated as a 346 * separate digit substring. 347 * 348 * A "digit" in this sense is a code point with General_Category=Nd, 349 * which does not include circled numbers, roman numerals, etc. 350 * Only a contiguous digit substring is considered, that is, 351 * non-negative integers without separators. 352 * There is no support for plus/minus signs, decimals, exponents, etc. 353 * 354 * @stable ICU 2.8 355 */ 356 UCOL_NUMERIC_COLLATION = UCOL_STRENGTH + 2, 357 358 /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API, 359 * it is needed for layout of RuleBasedCollator object. */ 360 #ifndef U_FORCE_HIDE_DEPRECATED_API 361 /** 362 * One more than the highest normal UColAttribute value. 363 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 364 */ 365 UCOL_ATTRIBUTE_COUNT 366 #endif // U_FORCE_HIDE_DEPRECATED_API 367 } UColAttribute; 368 369 /** Options for retrieving the rule string 370 * @stable ICU 2.0 371 */ 372 typedef enum { 373 /** 374 * Retrieves the tailoring rules only. 375 * Same as calling the version of getRules() without UColRuleOption. 376 * @stable ICU 2.0 377 */ 378 UCOL_TAILORING_ONLY, 379 /** 380 * Retrieves the "UCA rules" concatenated with the tailoring rules. 381 * The "UCA rules" are an approximation of the root collator's sort order. 382 * They are almost never used or useful at runtime and can be removed from the data. 383 * See https://unicode-org.github.io/icu/userguide/collation/customization#building-on-existing-locales 384 * @stable ICU 2.0 385 */ 386 UCOL_FULL_RULES 387 } UColRuleOption ; 388 389 /** 390 * Open a UCollator for comparing strings. 391 * 392 * For some languages, multiple collation types are available; 393 * for example, "de@collation=phonebook". 394 * Starting with ICU 54, collation attributes can be specified via locale keywords as well, 395 * in the old locale extension syntax ("el@colCaseFirst=upper") 396 * or in language tag syntax ("el-u-kf-upper"). 397 * See User Guide: Collation API. 398 * 399 * The UCollator pointer is used in all the calls to the Collation 400 * service. After finished, collator must be disposed of by calling 401 * {@link #ucol_close }. 402 * @param loc The locale containing the required collation rules. 403 * Special values for locales can be passed in - 404 * if NULL is passed for the locale, the default locale 405 * collation rules will be used. If empty string ("") or 406 * "root" are passed, the root collator will be returned. 407 * @param status A pointer to a UErrorCode to receive any errors 408 * @return A pointer to a UCollator, or 0 if an error occurred. 409 * @see ucol_openRules 410 * @see ucol_clone 411 * @see ucol_close 412 * @stable ICU 2.0 413 */ 414 U_CAPI UCollator* U_EXPORT2 415 ucol_open(const char *loc, UErrorCode *status); 416 417 /** 418 * Produce a UCollator instance according to the rules supplied. 419 * The rules are used to change the default ordering, defined in the 420 * UCA in a process called tailoring. The resulting UCollator pointer 421 * can be used in the same way as the one obtained by {@link #ucol_strcoll }. 422 * @param rules A string describing the collation rules. For the syntax 423 * of the rules please see users guide. 424 * @param rulesLength The length of rules, or -1 if null-terminated. 425 * @param normalizationMode The normalization mode: One of 426 * UCOL_OFF (expect the text to not need normalization), 427 * UCOL_ON (normalize), or 428 * UCOL_DEFAULT (set the mode according to the rules) 429 * @param strength The default collation strength; one of UCOL_PRIMARY, UCOL_SECONDARY, 430 * UCOL_TERTIARY, UCOL_IDENTICAL,UCOL_DEFAULT_STRENGTH - can be also set in the rules. 431 * @param parseError A pointer to UParseError to receive information about errors 432 * occurred during parsing. This argument can currently be set 433 * to NULL, but at users own risk. Please provide a real structure. 434 * @param status A pointer to a UErrorCode to receive any errors 435 * @return A pointer to a UCollator. It is not guaranteed that NULL be returned in case 436 * of error - please use status argument to check for errors. 437 * @see ucol_open 438 * @see ucol_clone 439 * @see ucol_close 440 * @stable ICU 2.0 441 */ 442 U_CAPI UCollator* U_EXPORT2 443 ucol_openRules( const UChar *rules, 444 int32_t rulesLength, 445 UColAttributeValue normalizationMode, 446 UCollationStrength strength, 447 UParseError *parseError, 448 UErrorCode *status); 449 450 #ifndef U_HIDE_DEPRECATED_API 451 /** 452 * Open a collator defined by a short form string. 453 * The structure and the syntax of the string is defined in the "Naming collators" 454 * section of the users guide: 455 * https://unicode-org.github.io/icu/userguide/collation/concepts#collator-naming-scheme 456 * Attributes are overridden by the subsequent attributes. So, for "S2_S3", final 457 * strength will be 3. 3066bis locale overrides individual locale parts. 458 * The call to this function is equivalent to a call to ucol_open, followed by a 459 * series of calls to ucol_setAttribute and ucol_setVariableTop. 460 * @param definition A short string containing a locale and a set of attributes. 461 * Attributes not explicitly mentioned are left at the default 462 * state for a locale. 463 * @param parseError if not NULL, structure that will get filled with error's pre 464 * and post context in case of error. 465 * @param forceDefaults if false, the settings that are the same as the collator 466 * default settings will not be applied (for example, setting 467 * French secondary on a French collator would not be executed). 468 * If true, all the settings will be applied regardless of the 469 * collator default value. If the definition 470 * strings are to be cached, should be set to false. 471 * @param status Error code. Apart from regular error conditions connected to 472 * instantiating collators (like out of memory or similar), this 473 * API will return an error if an invalid attribute or attribute/value 474 * combination is specified. 475 * @return A pointer to a UCollator or 0 if an error occurred (including an 476 * invalid attribute). 477 * @see ucol_open 478 * @see ucol_setAttribute 479 * @see ucol_setVariableTop 480 * @see ucol_getShortDefinitionString 481 * @see ucol_normalizeShortDefinitionString 482 * @deprecated ICU 54 Use ucol_open() with language tag collation keywords instead. 483 */ 484 U_DEPRECATED UCollator* U_EXPORT2 485 ucol_openFromShortString( const char *definition, 486 UBool forceDefaults, 487 UParseError *parseError, 488 UErrorCode *status); 489 #endif /* U_HIDE_DEPRECATED_API */ 490 491 #ifndef U_HIDE_DEPRECATED_API 492 /** 493 * Get a set containing the contractions defined by the collator. The set includes 494 * both the root collator's contractions and the contractions defined by the collator. This set 495 * will contain only strings. If a tailoring explicitly suppresses contractions from 496 * the root collator (like Russian), removed contractions will not be in the resulting set. 497 * @param coll collator 498 * @param conts the set to hold the result. It gets emptied before 499 * contractions are added. 500 * @param status to hold the error code 501 * @return the size of the contraction set 502 * 503 * @deprecated ICU 3.4, use ucol_getContractionsAndExpansions instead 504 */ 505 U_DEPRECATED int32_t U_EXPORT2 506 ucol_getContractions( const UCollator *coll, 507 USet *conts, 508 UErrorCode *status); 509 #endif /* U_HIDE_DEPRECATED_API */ 510 511 /** 512 * Get a set containing the expansions defined by the collator. The set includes 513 * both the root collator's expansions and the expansions defined by the tailoring 514 * @param coll collator 515 * @param contractions if not NULL, the set to hold the contractions 516 * @param expansions if not NULL, the set to hold the expansions 517 * @param addPrefixes add the prefix contextual elements to contractions 518 * @param status to hold the error code 519 * 520 * @stable ICU 3.4 521 */ 522 U_CAPI void U_EXPORT2 523 ucol_getContractionsAndExpansions( const UCollator *coll, 524 USet *contractions, USet *expansions, 525 UBool addPrefixes, UErrorCode *status); 526 527 /** 528 * Close a UCollator. 529 * Once closed, a UCollator should not be used. Every open collator should 530 * be closed. Otherwise, a memory leak will result. 531 * @param coll The UCollator to close. 532 * @see ucol_open 533 * @see ucol_openRules 534 * @see ucol_clone 535 * @stable ICU 2.0 536 */ 537 U_CAPI void U_EXPORT2 538 ucol_close(UCollator *coll); 539 540 #if U_SHOW_CPLUSPLUS_API 541 542 U_NAMESPACE_BEGIN 543 544 /** 545 * \class LocalUCollatorPointer 546 * "Smart pointer" class, closes a UCollator via ucol_close(). 547 * For most methods see the LocalPointerBase base class. 548 * 549 * @see LocalPointerBase 550 * @see LocalPointer 551 * @stable ICU 4.4 552 */ 553 U_DEFINE_LOCAL_OPEN_POINTER(LocalUCollatorPointer, UCollator, ucol_close); 554 555 U_NAMESPACE_END 556 557 #endif 558 559 /** 560 * Compare two strings. 561 * The strings will be compared using the options already specified. 562 * @param coll The UCollator containing the comparison rules. 563 * @param source The source string. 564 * @param sourceLength The length of source, or -1 if null-terminated. 565 * @param target The target string. 566 * @param targetLength The length of target, or -1 if null-terminated. 567 * @return The result of comparing the strings; one of UCOL_EQUAL, 568 * UCOL_GREATER, UCOL_LESS 569 * @see ucol_greater 570 * @see ucol_greaterOrEqual 571 * @see ucol_equal 572 * @stable ICU 2.0 573 */ 574 U_CAPI UCollationResult U_EXPORT2 575 ucol_strcoll( const UCollator *coll, 576 const UChar *source, 577 int32_t sourceLength, 578 const UChar *target, 579 int32_t targetLength); 580 581 /** 582 * Compare two strings in UTF-8. 583 * The strings will be compared using the options already specified. 584 * Note: When input string contains malformed a UTF-8 byte sequence, 585 * this function treats these bytes as REPLACEMENT CHARACTER (U+FFFD). 586 * @param coll The UCollator containing the comparison rules. 587 * @param source The source UTF-8 string. 588 * @param sourceLength The length of source, or -1 if null-terminated. 589 * @param target The target UTF-8 string. 590 * @param targetLength The length of target, or -1 if null-terminated. 591 * @param status A pointer to a UErrorCode to receive any errors 592 * @return The result of comparing the strings; one of UCOL_EQUAL, 593 * UCOL_GREATER, UCOL_LESS 594 * @see ucol_greater 595 * @see ucol_greaterOrEqual 596 * @see ucol_equal 597 * @stable ICU 50 598 */ 599 U_CAPI UCollationResult U_EXPORT2 600 ucol_strcollUTF8( 601 const UCollator *coll, 602 const char *source, 603 int32_t sourceLength, 604 const char *target, 605 int32_t targetLength, 606 UErrorCode *status); 607 608 /** 609 * Determine if one string is greater than another. 610 * This function is equivalent to {@link #ucol_strcoll } == UCOL_GREATER 611 * @param coll The UCollator containing the comparison rules. 612 * @param source The source string. 613 * @param sourceLength The length of source, or -1 if null-terminated. 614 * @param target The target string. 615 * @param targetLength The length of target, or -1 if null-terminated. 616 * @return true if source is greater than target, false otherwise. 617 * @see ucol_strcoll 618 * @see ucol_greaterOrEqual 619 * @see ucol_equal 620 * @stable ICU 2.0 621 */ 622 U_CAPI UBool U_EXPORT2 623 ucol_greater(const UCollator *coll, 624 const UChar *source, int32_t sourceLength, 625 const UChar *target, int32_t targetLength); 626 627 /** 628 * Determine if one string is greater than or equal to another. 629 * This function is equivalent to {@link #ucol_strcoll } != UCOL_LESS 630 * @param coll The UCollator containing the comparison rules. 631 * @param source The source string. 632 * @param sourceLength The length of source, or -1 if null-terminated. 633 * @param target The target string. 634 * @param targetLength The length of target, or -1 if null-terminated. 635 * @return true if source is greater than or equal to target, false otherwise. 636 * @see ucol_strcoll 637 * @see ucol_greater 638 * @see ucol_equal 639 * @stable ICU 2.0 640 */ 641 U_CAPI UBool U_EXPORT2 642 ucol_greaterOrEqual(const UCollator *coll, 643 const UChar *source, int32_t sourceLength, 644 const UChar *target, int32_t targetLength); 645 646 /** 647 * Compare two strings for equality. 648 * This function is equivalent to {@link #ucol_strcoll } == UCOL_EQUAL 649 * @param coll The UCollator containing the comparison rules. 650 * @param source The source string. 651 * @param sourceLength The length of source, or -1 if null-terminated. 652 * @param target The target string. 653 * @param targetLength The length of target, or -1 if null-terminated. 654 * @return true if source is equal to target, false otherwise 655 * @see ucol_strcoll 656 * @see ucol_greater 657 * @see ucol_greaterOrEqual 658 * @stable ICU 2.0 659 */ 660 U_CAPI UBool U_EXPORT2 661 ucol_equal(const UCollator *coll, 662 const UChar *source, int32_t sourceLength, 663 const UChar *target, int32_t targetLength); 664 665 /** 666 * Compare two UTF-8 encoded strings. 667 * The strings will be compared using the options already specified. 668 * @param coll The UCollator containing the comparison rules. 669 * @param sIter The source string iterator. 670 * @param tIter The target string iterator. 671 * @return The result of comparing the strings; one of UCOL_EQUAL, 672 * UCOL_GREATER, UCOL_LESS 673 * @param status A pointer to a UErrorCode to receive any errors 674 * @see ucol_strcoll 675 * @stable ICU 2.6 676 */ 677 U_CAPI UCollationResult U_EXPORT2 678 ucol_strcollIter( const UCollator *coll, 679 UCharIterator *sIter, 680 UCharIterator *tIter, 681 UErrorCode *status); 682 683 /** 684 * Get the collation strength used in a UCollator. 685 * The strength influences how strings are compared. 686 * @param coll The UCollator to query. 687 * @return The collation strength; one of UCOL_PRIMARY, UCOL_SECONDARY, 688 * UCOL_TERTIARY, UCOL_QUATERNARY, UCOL_IDENTICAL 689 * @see ucol_setStrength 690 * @stable ICU 2.0 691 */ 692 U_CAPI UCollationStrength U_EXPORT2 693 ucol_getStrength(const UCollator *coll); 694 695 /** 696 * Set the collation strength used in a UCollator. 697 * The strength influences how strings are compared. 698 * @param coll The UCollator to set. 699 * @param strength The desired collation strength; one of UCOL_PRIMARY, 700 * UCOL_SECONDARY, UCOL_TERTIARY, UCOL_QUATERNARY, UCOL_IDENTICAL, UCOL_DEFAULT 701 * @see ucol_getStrength 702 * @stable ICU 2.0 703 */ 704 U_CAPI void U_EXPORT2 705 ucol_setStrength(UCollator *coll, 706 UCollationStrength strength); 707 708 /** 709 * Retrieves the reordering codes for this collator. 710 * These reordering codes are a combination of UScript codes and UColReorderCode entries. 711 * @param coll The UCollator to query. 712 * @param dest The array to fill with the script ordering. 713 * @param destCapacity The length of dest. If it is 0, then dest may be NULL and the function 714 * will only return the length of the result without writing any codes (pre-flighting). 715 * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate a 716 * failure before the function call. 717 * @return The number of reordering codes written to the dest array. 718 * @see ucol_setReorderCodes 719 * @see ucol_getEquivalentReorderCodes 720 * @see UScriptCode 721 * @see UColReorderCode 722 * @stable ICU 4.8 723 */ 724 U_CAPI int32_t U_EXPORT2 725 ucol_getReorderCodes(const UCollator* coll, 726 int32_t* dest, 727 int32_t destCapacity, 728 UErrorCode *pErrorCode); 729 /** 730 * Sets the reordering codes for this collator. 731 * Collation reordering allows scripts and some other groups of characters 732 * to be moved relative to each other. This reordering is done on top of 733 * the DUCET/CLDR standard collation order. Reordering can specify groups to be placed 734 * at the start and/or the end of the collation order. These groups are specified using 735 * UScript codes and UColReorderCode entries. 736 * 737 *
By default, reordering codes specified for the start of the order are placed in the 738 * order given after several special non-script blocks. These special groups of characters 739 * are space, punctuation, symbol, currency, and digit. These special groups are represented with 740 * UColReorderCode entries. Script groups can be intermingled with 741 * these special non-script groups if those special groups are explicitly specified in the reordering. 742 * 743 *
The special code OTHERS stands for any script that is not explicitly 744 * mentioned in the list of reordering codes given. Anything that is after OTHERS 745 * will go at the very end of the reordering in the order given. 746 * 747 *
The special reorder code DEFAULT will reset the reordering for this collator 748 * to the default for this collator. The default reordering may be the DUCET/CLDR order or may be a reordering that 749 * was specified when this collator was created from resource data or from rules. The 750 * DEFAULT code must be the sole code supplied when it is used. 751 * If not, then U_ILLEGAL_ARGUMENT_ERROR will be set. 752 * 753 *
The special reorder code NONE will remove any reordering for this collator. 754 * The result of setting no reordering will be to have the DUCET/CLDR ordering used. The 755 * NONE code must be the sole code supplied when it is used. 756 * 757 * @param coll The UCollator to set. 758 * @param reorderCodes An array of script codes in the new order. This can be NULL if the 759 * length is also set to 0. An empty array will clear any reordering codes on the collator. 760 * @param reorderCodesLength The length of reorderCodes. 761 * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate a 762 * failure before the function call. 763 * @see ucol_getReorderCodes 764 * @see ucol_getEquivalentReorderCodes 765 * @see UScriptCode 766 * @see UColReorderCode 767 * @stable ICU 4.8 768 */ 769 U_CAPI void U_EXPORT2 770 ucol_setReorderCodes(UCollator* coll, 771 const int32_t* reorderCodes, 772 int32_t reorderCodesLength, 773 UErrorCode *pErrorCode); 774 775 /** 776 * Retrieves the reorder codes that are grouped with the given reorder code. Some reorder 777 * codes will be grouped and must reorder together. 778 * Beginning with ICU 55, scripts only reorder together if they are primary-equal, 779 * for example Hiragana and Katakana. 780 * 781 * @param reorderCode The reorder code to determine equivalence for. 782 * @param dest The array to fill with the script ordering. 783 * @param destCapacity The length of dest. If it is 0, then dest may be NULL and the function 784 * will only return the length of the result without writing any codes (pre-flighting). 785 * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate 786 * a failure before the function call. 787 * @return The number of reordering codes written to the dest array. 788 * @see ucol_setReorderCodes 789 * @see ucol_getReorderCodes 790 * @see UScriptCode 791 * @see UColReorderCode 792 * @stable ICU 4.8 793 */ 794 U_CAPI int32_t U_EXPORT2 795 ucol_getEquivalentReorderCodes(int32_t reorderCode, 796 int32_t* dest, 797 int32_t destCapacity, 798 UErrorCode *pErrorCode); 799 800 /** 801 * Get the display name for a UCollator. 802 * The display name is suitable for presentation to a user. 803 * @param objLoc The locale of the collator in question. 804 * @param dispLoc The locale for display. 805 * @param result A pointer to a buffer to receive the attribute. 806 * @param resultLength The maximum size of result. 807 * @param status A pointer to a UErrorCode to receive any errors 808 * @return The total buffer size needed; if greater than resultLength, 809 * the output was truncated. 810 * @stable ICU 2.0 811 */ 812 U_CAPI int32_t U_EXPORT2 813 ucol_getDisplayName( const char *objLoc, 814 const char *dispLoc, 815 UChar *result, 816 int32_t resultLength, 817 UErrorCode *status); 818 819 /** 820 * Get a locale for which collation rules are available. 821 * A UCollator in a locale returned by this function will perform the correct 822 * collation for the locale. 823 * @param localeIndex The index of the desired locale. 824 * @return A locale for which collation rules are available, or 0 if none. 825 * @see ucol_countAvailable 826 * @stable ICU 2.0 827 */ 828 U_CAPI const char* U_EXPORT2 829 ucol_getAvailable(int32_t localeIndex); 830 831 /** 832 * Determine how many locales have collation rules available. 833 * This function is most useful as determining the loop ending condition for 834 * calls to {@link #ucol_getAvailable }. 835 * @return The number of locales for which collation rules are available. 836 * @see ucol_getAvailable 837 * @stable ICU 2.0 838 */ 839 U_CAPI int32_t U_EXPORT2 840 ucol_countAvailable(void); 841 842 #if !UCONFIG_NO_SERVICE 843 /** 844 * Create a string enumerator of all locales for which a valid 845 * collator may be opened. 846 * @param status input-output error code 847 * @return a string enumeration over locale strings. The caller is 848 * responsible for closing the result. 849 * @stable ICU 3.0 850 */ 851 U_CAPI UEnumeration* U_EXPORT2 852 ucol_openAvailableLocales(UErrorCode *status); 853 #endif 854 855 /** 856 * Create a string enumerator of all possible keywords that are relevant to 857 * collation. At this point, the only recognized keyword for this 858 * service is "collation". 859 * @param status input-output error code 860 * @return a string enumeration over locale strings. The caller is 861 * responsible for closing the result. 862 * @stable ICU 3.0 863 */ 864 U_CAPI UEnumeration* U_EXPORT2 865 ucol_getKeywords(UErrorCode *status); 866 867 /** 868 * Given a keyword, create a string enumeration of all values 869 * for that keyword that are currently in use. 870 * @param keyword a particular keyword as enumerated by 871 * ucol_getKeywords. If any other keyword is passed in, *status is set 872 * to U_ILLEGAL_ARGUMENT_ERROR. 873 * @param status input-output error code 874 * @return a string enumeration over collation keyword values, or NULL 875 * upon error. The caller is responsible for closing the result. 876 * @stable ICU 3.0 877 */ 878 U_CAPI UEnumeration* U_EXPORT2 879 ucol_getKeywordValues(const char *keyword, UErrorCode *status); 880 881 /** 882 * Given a key and a locale, returns an array of string values in a preferred 883 * order that would make a difference. These are all and only those values where 884 * the open (creation) of the service with the locale formed from the input locale 885 * plus input keyword and that value has different behavior than creation with the 886 * input locale alone. 887 * @param key one of the keys supported by this service. For now, only 888 * "collation" is supported. 889 * @param locale the locale 890 * @param commonlyUsed if set to true it will return only commonly used values 891 * with the given locale in preferred order. Otherwise, 892 * it will return all the available values for the locale. 893 * @param status error status 894 * @return a string enumeration over keyword values for the given key and the locale. 895 * @stable ICU 4.2 896 */ 897 U_CAPI UEnumeration* U_EXPORT2 898 ucol_getKeywordValuesForLocale(const char* key, 899 const char* locale, 900 UBool commonlyUsed, 901 UErrorCode* status); 902 903 /** 904 * Return the functionally equivalent locale for the specified 905 * input locale, with respect to given keyword, for the 906 * collation service. If two different input locale + keyword 907 * combinations produce the same result locale, then collators 908 * instantiated for these two different input locales will behave 909 * equivalently. The converse is not always true; two collators 910 * may in fact be equivalent, but return different results, due to 911 * internal details. The return result has no other meaning than 912 * that stated above, and implies nothing as to the relationship 913 * between the two locales. This is intended for use by 914 * applications who wish to cache collators, or otherwise reuse 915 * collators when possible. The functional equivalent may change 916 * over time. For more information, please see the 918 * Locales and Services section of the ICU User Guide. 919 * @param result fillin for the functionally equivalent result locale 920 * @param resultCapacity capacity of the fillin buffer 921 * @param keyword a particular keyword as enumerated by 922 * ucol_getKeywords. 923 * @param locale the specified input locale 924 * @param isAvailable if non-NULL, pointer to a fillin parameter that 925 * on return indicates whether the specified input locale was 'available' 926 * to the collation service. A locale is defined as 'available' if it 927 * physically exists within the collation locale data. 928 * @param status pointer to input-output error code 929 * @return the actual buffer size needed for the locale. If greater 930 * than resultCapacity, the returned full name will be truncated and 931 * an error code will be returned. 932 * @stable ICU 3.0 933 */ 934 U_CAPI int32_t U_EXPORT2 935 ucol_getFunctionalEquivalent(char* result, int32_t resultCapacity, 936 const char* keyword, const char* locale, 937 UBool* isAvailable, UErrorCode* status); 938 939 /** 940 * Get the collation tailoring rules from a UCollator. 941 * The rules will follow the rule syntax. 942 * @param coll The UCollator to query. 943 * @param length 944 * @return The collation tailoring rules. 945 * @stable ICU 2.0 946 */ 947 U_CAPI const UChar* U_EXPORT2 948 ucol_getRules( const UCollator *coll, 949 int32_t *length); 950 951 #ifndef U_HIDE_DEPRECATED_API 952 /** Get the short definition string for a collator. This API harvests the collator's 953 * locale and the attribute set and produces a string that can be used for opening 954 * a collator with the same attributes using the ucol_openFromShortString API. 955 * This string will be normalized. 956 * The structure and the syntax of the string is defined in the "Naming collators" 957 * section of the users guide: 958 * https://unicode-org.github.io/icu/userguide/collation/concepts#collator-naming-scheme 959 * This API supports preflighting. 960 * @param coll a collator 961 * @param locale a locale that will appear as a collators locale in the resulting 962 * short string definition. If NULL, the locale will be harvested 963 * from the collator. 964 * @param buffer space to hold the resulting string 965 * @param capacity capacity of the buffer 966 * @param status for returning errors. All the preflighting errors are featured 967 * @return length of the resulting string 968 * @see ucol_openFromShortString 969 * @see ucol_normalizeShortDefinitionString 970 * @deprecated ICU 54 971 */ 972 U_DEPRECATED int32_t U_EXPORT2 973 ucol_getShortDefinitionString(const UCollator *coll, 974 const char *locale, 975 char *buffer, 976 int32_t capacity, 977 UErrorCode *status); 978 979 /** Verifies and normalizes short definition string. 980 * Normalized short definition string has all the option sorted by the argument name, 981 * so that equivalent definition strings are the same. 982 * This API supports preflighting. 983 * @param source definition string 984 * @param destination space to hold the resulting string 985 * @param capacity capacity of the buffer 986 * @param parseError if not NULL, structure that will get filled with error's pre 987 * and post context in case of error. 988 * @param status Error code. This API will return an error if an invalid attribute 989 * or attribute/value combination is specified. All the preflighting 990 * errors are also featured 991 * @return length of the resulting normalized string. 992 * 993 * @see ucol_openFromShortString 994 * @see ucol_getShortDefinitionString 995 * 996 * @deprecated ICU 54 997 */ 998 U_DEPRECATED int32_t U_EXPORT2 999 ucol_normalizeShortDefinitionString(const char *source, 1000 char *destination, 1001 int32_t capacity, 1002 UParseError *parseError, 1003 UErrorCode *status); 1004 #endif /* U_HIDE_DEPRECATED_API */ 1005 1006 1007 /** 1008 * Get a sort key for a string from a UCollator. 1009 * Sort keys may be compared using strcmp. 1010 * 1011 * Note that sort keys are often less efficient than simply doing comparison. 1012 * For more details, see the ICU User Guide. 1013 * 1014 * Like ICU functions that write to an output buffer, the buffer contents 1015 * is undefined if the buffer capacity (resultLength parameter) is too small. 1016 * Unlike ICU functions that write a string to an output buffer, 1017 * the terminating zero byte is counted in the sort key length. 1018 * @param coll The UCollator containing the collation rules. 1019 * @param source The string to transform. 1020 * @param sourceLength The length of source, or -1 if null-terminated. 1021 * @param result A pointer to a buffer to receive the attribute. 1022 * @param resultLength The maximum size of result. 1023 * @return The size needed to fully store the sort key. 1024 * If there was an internal error generating the sort key, 1025 * a zero value is returned. 1026 * @see ucol_keyHashCode 1027 * @stable ICU 2.0 1028 */ 1029 U_CAPI int32_t U_EXPORT2 1030 ucol_getSortKey(const UCollator *coll, 1031 const UChar *source, 1032 int32_t sourceLength, 1033 uint8_t *result, 1034 int32_t resultLength); 1035 1036 1037 /** Gets the next count bytes of a sort key. Caller needs 1038 * to preserve state array between calls and to provide 1039 * the same type of UCharIterator set with the same string. 1040 * The destination buffer provided must be big enough to store 1041 * the number of requested bytes. 1042 * 1043 * The generated sort key may or may not be compatible with 1044 * sort keys generated using ucol_getSortKey(). 1045 * @param coll The UCollator containing the collation rules. 1046 * @param iter UCharIterator containing the string we need 1047 * the sort key to be calculated for. 1048 * @param state Opaque state of sortkey iteration. 1049 * @param dest Buffer to hold the resulting sortkey part 1050 * @param count number of sort key bytes required. 1051 * @param status error code indicator. 1052 * @return the actual number of bytes of a sortkey. It can be 1053 * smaller than count if we have reached the end of 1054 * the sort key. 1055 * @stable ICU 2.6 1056 */ 1057 U_CAPI int32_t U_EXPORT2 1058 ucol_nextSortKeyPart(const UCollator *coll, 1059 UCharIterator *iter, 1060 uint32_t state[2], 1061 uint8_t *dest, int32_t count, 1062 UErrorCode *status); 1063 1064 /** enum that is taken by ucol_getBound API 1065 * See below for explanation 1066 * do not change the values assigned to the 1067 * members of this enum. Underlying code 1068 * depends on them having these numbers 1069 * @stable ICU 2.0 1070 */ 1071 typedef enum { 1072 /** lower bound */ 1073 UCOL_BOUND_LOWER = 0, 1074 /** upper bound that will match strings of exact size */ 1075 UCOL_BOUND_UPPER = 1, 1076 /** upper bound that will match all the strings that have the same initial substring as the given string */ 1077 UCOL_BOUND_UPPER_LONG = 2, 1078 #ifndef U_HIDE_DEPRECATED_API 1079 /** 1080 * One more than the highest normal UColBoundMode value. 1081 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 1082 */ 1083 UCOL_BOUND_VALUE_COUNT 1084 #endif /* U_HIDE_DEPRECATED_API */ 1085 } UColBoundMode; 1086 1087 /** 1088 * Produce a bound for a given sortkey and a number of levels. 1089 * Return value is always the number of bytes needed, regardless of 1090 * whether the result buffer was big enough or even valid. 1091 * Resulting bounds can be used to produce a range of strings that are 1092 * between upper and lower bounds. For example, if bounds are produced 1093 * for a sortkey of string "smith", strings between upper and lower 1094 * bounds with one level would include "Smith", "SMITH", "sMiTh". 1095 * There are two upper bounds that can be produced. If UCOL_BOUND_UPPER 1096 * is produced, strings matched would be as above. However, if bound 1097 * produced using UCOL_BOUND_UPPER_LONG is used, the above example will 1098 * also match "Smithsonian" and similar. 1099 * For more on usage, see example in cintltst/capitst.c in procedure 1100 * TestBounds. 1101 * Sort keys may be compared using strcmp. 1102 * @param source The source sortkey. 1103 * @param sourceLength The length of source, or -1 if null-terminated. 1104 * (If an unmodified sortkey is passed, it is always null 1105 * terminated). 1106 * @param boundType Type of bound required. It can be UCOL_BOUND_LOWER, which 1107 * produces a lower inclusive bound, UCOL_BOUND_UPPER, that 1108 * produces upper bound that matches strings of the same length 1109 * or UCOL_BOUND_UPPER_LONG that matches strings that have the 1110 * same starting substring as the source string. 1111 * @param noOfLevels Number of levels required in the resulting bound (for most 1112 * uses, the recommended value is 1). See users guide for 1113 * explanation on number of levels a sortkey can have. 1114 * @param result A pointer to a buffer to receive the resulting sortkey. 1115 * @param resultLength The maximum size of result. 1116 * @param status Used for returning error code if something went wrong. If the 1117 * number of levels requested is higher than the number of levels 1118 * in the source key, a warning (U_SORT_KEY_TOO_SHORT_WARNING) is 1119 * issued. 1120 * @return The size needed to fully store the bound. 1121 * @see ucol_keyHashCode 1122 * @stable ICU 2.1 1123 */ 1124 U_CAPI int32_t U_EXPORT2 1125 ucol_getBound(const uint8_t *source, 1126 int32_t sourceLength, 1127 UColBoundMode boundType, 1128 uint32_t noOfLevels, 1129 uint8_t *result, 1130 int32_t resultLength, 1131 UErrorCode *status); 1132 1133 /** 1134 * Gets the version information for a Collator. Version is currently 1135 * an opaque 32-bit number which depends, among other things, on major 1136 * versions of the collator tailoring and UCA. 1137 * @param coll The UCollator to query. 1138 * @param info the version # information, the result will be filled in 1139 * @stable ICU 2.0 1140 */ 1141 U_CAPI void U_EXPORT2 1142 ucol_getVersion(const UCollator* coll, UVersionInfo info); 1143 1144 /** 1145 * Gets the UCA version information for a Collator. Version is the 1146 * UCA version number (3.1.1, 4.0). 1147 * @param coll The UCollator to query. 1148 * @param info the version # information, the result will be filled in 1149 * @stable ICU 2.8 1150 */ 1151 U_CAPI void U_EXPORT2 1152 ucol_getUCAVersion(const UCollator* coll, UVersionInfo info); 1153 1154 /** 1155 * Merges two sort keys. The levels are merged with their corresponding counterparts 1156 * (primaries with primaries, secondaries with secondaries etc.). Between the values 1157 * from the same level a separator is inserted. 1158 * 1159 * This is useful, for example, for combining sort keys from first and last names 1160 * to sort such pairs. 1161 * See http://www.unicode.org/reports/tr10/#Merging_Sort_Keys 1162 * 1163 * The recommended way to achieve "merged" sorting is by 1164 * concatenating strings with U+FFFE between them. 1165 * The concatenation has the same sort order as the merged sort keys, 1166 * but merge(getSortKey(str1), getSortKey(str2)) may differ from getSortKey(str1 + '\\uFFFE' + str2). 1167 * Using strings with U+FFFE may yield shorter sort keys. 1168 * 1169 * For details about Sort Key Features see 1170 * https://unicode-org.github.io/icu/userguide/collation/api#sort-key-features 1171 * 1172 * It is possible to merge multiple sort keys by consecutively merging 1173 * another one with the intermediate result. 1174 * 1175 * The length of the merge result is the sum of the lengths of the input sort keys. 1176 * 1177 * Example (uncompressed): 1178 *
191B1D 01 050505 01 910505 00 1179 * 1F2123 01 050505 01 910505 00
191B1D 02 1F2123 01 050505 02 050505 01 910505 02 910505 00