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