ucol.h File Reference

C API: Collator. More...

`#include "unicode/utypes.h"`
`#include "unicode/unorm.h"`
`#include "unicode/parseerr.h"`
`#include "unicode/uloc.h"`
`#include "unicode/uset.h"`
`#include "unicode/uscript.h"`
`#include "unicode/localpointer.h"`
`#include <functional>`
`#include <string_view>`
`#include <type_traits>`
`#include "unicode/char16ptr.h"`
`#include "unicode/stringpiece.h"`
`#include "unicode/unistr.h"`

Go to the source code of this file.

## Data Structures

class | U_HEADER_ONLY_NAMESPACE::collator::internal::Predicate< Compare, result >
| Function object for performing comparisons using a UCollator. More...

## Namespaces

namespace | icu
| File coll.h.

## Macros

#define | U_COL_SAFECLONE_BUFFERSIZE 1
| default memory size for the new clone.

## Typedefs

typedef struct UCollator | UCollator
| structure representing a collator object instance
typedef UColAttributeValue | UCollationStrength
| Base letter represents a primary difference.
using | U_HEADER_ONLY_NAMESPACE::collator::equal_to = internal::Predicate< std::equal_to, UCOL_EQUAL >
| Function object for performing comparisons using this collator.
using | U_HEADER_ONLY_NAMESPACE::collator::greater = internal::Predicate< std::equal_to, UCOL_GREATER >
| Function object for performing comparisons using this collator.
using | U_HEADER_ONLY_NAMESPACE::collator::less = internal::Predicate< std::equal_to, UCOL_LESS >
| Function object for performing comparisons using this collator.
using | U_HEADER_ONLY_NAMESPACE::collator::not_equal_to = internal::Predicate< std::not_equal_to, UCOL_EQUAL >
| Function object for performing comparisons using this collator.
using | U_HEADER_ONLY_NAMESPACE::collator::greater_equal = internal::Predicate< std::not_equal_to, UCOL_LESS >
| Function object for performing comparisons using this collator.
using | U_HEADER_ONLY_NAMESPACE::collator::less_equal = internal::Predicate< std::not_equal_to, UCOL_GREATER >
| Function object for performing comparisons using this collator.

## Enumerations

enum | UCollationResult { UCOL_EQUAL = 0 , UCOL_GREATER = 1 , UCOL_LESS = -1 }
| UCOL_LESS is returned if source string is compared to be less than target string in the ucol_strcoll() method. More...
enum | UColAttributeValue { UCOL_DEFAULT = -1 , UCOL_PRIMARY = 0 , UCOL_SECONDARY = 1 , UCOL_TERTIARY = 2 , UCOL_DEFAULT_STRENGTH = UCOL_TERTIARY , UCOL_CE_STRENGTH_LIMIT , UCOL_QUATERNARY =3 , UCOL_IDENTICAL =15 , UCOL_STRENGTH_LIMIT , UCOL_OFF = 16 , UCOL_ON = 17 , UCOL_SHIFTED = 20 , UCOL_NON_IGNORABLE = 21 , UCOL_LOWER_FIRST = 24 , UCOL_UPPER_FIRST = 25 , UCOL_ATTRIBUTE_VALUE_COUNT }
| Enum containing attribute values for controlling collation behavior. More...

enum

UColReorderCode {
UCOL_REORDER_CODE_DEFAULT = -1 , UCOL_REORDER_CODE_NONE = USCRIPT_UNKNOWN , UCOL_REORDER_CODE_OTHERS = USCRIPT_UNKNOWN , UCOL_REORDER_CODE_SPACE = 0x1000 ,
UCOL_REORDER_CODE_FIRST = UCOL_REORDER_CODE_SPACE , UCOL_REORDER_CODE_PUNCTUATION = 0x1001 , UCOL_REORDER_CODE_SYMBOL = 0x1002 , UCOL_REORDER_CODE_CURRENCY = 0x1003 ,
UCOL_REORDER_CODE_DIGIT = 0x1004 , UCOL_REORDER_CODE_LIMIT = 0x1005
}

| Enum containing the codes for reordering segments of the collation table that are not script codes. More...
enum | UColAttribute { UCOL_FRENCH_COLLATION , UCOL_ALTERNATE_HANDLING , UCOL_CASE_FIRST , UCOL_CASE_LEVEL , UCOL_NORMALIZATION_MODE , UCOL_DECOMPOSITION_MODE = UCOL_NORMALIZATION_MODE , UCOL_STRENGTH , UCOL_HIRAGANA_QUATERNARY_MODE = UCOL_STRENGTH + 1 , UCOL_NUMERIC_COLLATION = UCOL_STRENGTH + 2 , UCOL_ATTRIBUTE_COUNT }
| Attributes that collation service understands. More...
enum | UColRuleOption { UCOL_TAILORING_ONLY , UCOL_FULL_RULES }
| Options for retrieving the rule string. More...
enum | UColBoundMode { UCOL_BOUND_LOWER = 0 , UCOL_BOUND_UPPER = 1 , UCOL_BOUND_UPPER_LONG = 2 , UCOL_BOUND_VALUE_COUNT }
| enum that is taken by ucol_getBound API See below for explanation do not change the values assigned to the members of this enum. More...

## Functions

U_CAPI UCollator * | ucol_open (const char *loc, UErrorCode *status)
| Open a UCollator for comparing strings.
U_CAPI UCollator * | ucol_openRules (const UChar *rules, int32_t rulesLength, UColAttributeValue normalizationMode, UCollationStrength strength, UParseError *parseError, UErrorCode *status)
| Produce a UCollator instance according to the rules supplied.
UCollator * | ucol_openFromShortString (const char *definition, UBool forceDefaults, UParseError *parseError, UErrorCode *status)
| Open a collator defined by a short form string.
int32_t | ucol_getContractions (const UCollator *coll, USet *conts, UErrorCode *status)
| Get a set containing the contractions defined by the collator.
U_CAPI void | ucol_getContractionsAndExpansions (const UCollator *coll, USet *contractions, USet *expansions, UBool addPrefixes, UErrorCode *status)
| Get a set containing the expansions defined by the collator.
U_CAPI void | ucol_close (UCollator *coll)
| Close a UCollator.
U_CAPI UCollationResult | ucol_strcoll (const UCollator *coll, const UChar *source, int32_t sourceLength, const UChar *target, int32_t targetLength)
| Compare two strings.
U_CAPI UCollationResult | ucol_strcollUTF8 (const UCollator *coll, const char *source, int32_t sourceLength, const char *target, int32_t targetLength, UErrorCode *status)
| Compare two strings in UTF-8.
U_CAPI UBool | ucol_greater (const UCollator *coll, const UChar *source, int32_t sourceLength, const UChar *target, int32_t targetLength)
| Determine if one string is greater than another.
U_CAPI UBool | ucol_greaterOrEqual (const UCollator *coll, const UChar *source, int32_t sourceLength, const UChar *target, int32_t targetLength)
| Determine if one string is greater than or equal to another.
U_CAPI UBool | ucol_equal (const UCollator *coll, const UChar *source, int32_t sourceLength, const UChar *target, int32_t targetLength)
| Compare two strings for equality.
U_CAPI UCollationResult | ucol_strcollIter (const UCollator *coll, UCharIterator *sIter, UCharIterator *tIter, UErrorCode *status)
| Compare two UTF-8 encoded strings.
U_CAPI UCollationStrength | ucol_getStrength (const UCollator *coll)
| Get the collation strength used in a UCollator.
U_CAPI void | ucol_setStrength (UCollator *coll, UCollationStrength strength)
| Set the collation strength used in a UCollator.
U_CAPI int32_t | ucol_getReorderCodes (const UCollator *coll, int32_t *dest, int32_t destCapacity, UErrorCode *pErrorCode)
| Retrieves the reordering codes for this collator.
U_CAPI void | ucol_setReorderCodes (UCollator *coll, const int32_t *reorderCodes, int32_t reorderCodesLength, UErrorCode *pErrorCode)
| Sets the reordering codes for this collator.
U_CAPI int32_t | ucol_getEquivalentReorderCodes (int32_t reorderCode, int32_t *dest, int32_t destCapacity, UErrorCode *pErrorCode)
| Retrieves the reorder codes that are grouped with the given reorder code.
U_CAPI int32_t | ucol_getDisplayName (const char *objLoc, const char *dispLoc, UChar *result, int32_t resultLength, UErrorCode *status)
| Get the display name for a UCollator.
U_CAPI const char * | ucol_getAvailable (int32_t localeIndex)
| Get a locale for which collation rules are available.
U_CAPI int32_t | ucol_countAvailable (void)
| Determine how many locales have collation rules available.
U_CAPI UEnumeration * | ucol_openAvailableLocales (UErrorCode *status)
| Create a string enumerator of all locales for which a valid collator may be opened.
U_CAPI UEnumeration * | ucol_getKeywords (UErrorCode *status)
| Create a string enumerator of all possible keywords that are relevant to collation.
U_CAPI UEnumeration * | ucol_getKeywordValues (const char *keyword, UErrorCode *status)
| Given a keyword, create a string enumeration of all values for that keyword that are currently in use.
U_CAPI UEnumeration * | ucol_getKeywordValuesForLocale (const char *key, const char *locale, UBool commonlyUsed, UErrorCode *status)
| Given a key and a locale, returns an array of string values in a preferred order that would make a difference.
U_CAPI int32_t | ucol_getFunctionalEquivalent (char *result, int32_t resultCapacity, const char *keyword, const char *locale, UBool *isAvailable, UErrorCode *status)
| Return the functionally equivalent locale for the specified input locale, with respect to given keyword, for the collation service.
U_CAPI const UChar * | ucol_getRules (const UCollator *coll, int32_t *length)
| Get the collation tailoring rules from a UCollator.
int32_t | ucol_getShortDefinitionString (const UCollator *coll, const char *locale, char *buffer, int32_t capacity, UErrorCode *status)
| Get the short definition string for a collator.
int32_t | ucol_normalizeShortDefinitionString (const char *source, char *destination, int32_t capacity, UParseError *parseError, UErrorCode *status)
| Verifies and normalizes short definition string.
U_CAPI int32_t | ucol_getSortKey (const UCollator *coll, const UChar *source, int32_t sourceLength, uint8_t *result, int32_t resultLength)
| Get a sort key for a string from a UCollator.
U_CAPI int32_t | ucol_nextSortKeyPart (const UCollator *coll, UCharIterator *iter, uint32_t state[2], uint8_t *dest, int32_t count, UErrorCode *status)
| Gets the next count bytes of a sort key.
U_CAPI int32_t | ucol_getBound (const uint8_t *source, int32_t sourceLength, UColBoundMode boundType, uint32_t noOfLevels, uint8_t *result, int32_t resultLength, UErrorCode *status)
| Produce a bound for a given sortkey and a number of levels.
U_CAPI void | ucol_getVersion (const UCollator *coll, UVersionInfo info)
| Gets the version information for a Collator.
U_CAPI void | ucol_getUCAVersion (const UCollator *coll, UVersionInfo info)
| Gets the UCA version information for a Collator.
U_CAPI int32_t | ucol_mergeSortkeys (const uint8_t *src1, int32_t src1Length, const uint8_t *src2, int32_t src2Length, uint8_t *dest, int32_t destCapacity)
| Merges two sort keys.
U_CAPI void | ucol_setAttribute (UCollator *coll, UColAttribute attr, UColAttributeValue value, UErrorCode *status)
| Universal attribute setter.
U_CAPI UColAttributeValue | ucol_getAttribute (const UCollator *coll, UColAttribute attr, UErrorCode *status)
| Universal attribute getter.
U_CAPI void | ucol_setMaxVariable (UCollator *coll, UColReorderCode group, UErrorCode *pErrorCode)
| Sets the variable top to the top of the specified reordering group.
U_CAPI UColReorderCode | ucol_getMaxVariable (const UCollator *coll)
| Returns the maximum reordering group whose characters are affected by UCOL_ALTERNATE_HANDLING.
uint32_t | ucol_setVariableTop (UCollator *coll, const UChar *varTop, int32_t len, UErrorCode *status)
| Sets the variable top to the primary weight of the specified string.
U_CAPI uint32_t | ucol_getVariableTop (const UCollator *coll, UErrorCode *status)
| Gets the variable top value of a Collator.
void | ucol_restoreVariableTop (UCollator *coll, const uint32_t varTop, UErrorCode *status)
| Sets the variable top to the specified primary weight.
U_CAPI UCollator * | ucol_clone (const UCollator *coll, UErrorCode *status)
| Thread safe cloning operation.
UCollator * | ucol_safeClone (const UCollator *coll, void *stackBuffer, int32_t *pBufferSize, UErrorCode *status)
| Thread safe cloning operation.
U_CAPI int32_t | ucol_getRulesEx (const UCollator *coll, UColRuleOption delta, UChar *buffer, int32_t bufferLen)
| Returns current rules.
const char * | ucol_getLocale (const UCollator *coll, ULocDataLocaleType type, UErrorCode *status)
| gets the locale name of the collator.
U_CAPI const char * | ucol_getLocaleByType (const UCollator *coll, ULocDataLocaleType type, UErrorCode *status)
| gets the locale name of the collator.
U_CAPI USet * | ucol_getTailoredSet (const UCollator *coll, UErrorCode *status)
| Get a Unicode set that contains all the characters and sequences tailored in this collator.
U_CAPI int32_t | ucol_getUnsafeSet (const UCollator *coll, USet *unsafe, UErrorCode *status)
| Calculates the set of unsafe code points, given a collator.
U_CAPI void | ucol_prepareShortStringOpen (const char *definition, UBool forceDefaults, UParseError *parseError, UErrorCode *status)
| Touches all resources needed for instantiating a collator from a short string definition, thus filling up the cache.
U_CAPI int32_t | ucol_cloneBinary (const UCollator *coll, uint8_t *buffer, int32_t capacity, UErrorCode *status)
| Creates a binary image of a collator.
U_CAPI UCollator * | ucol_openBinary (const uint8_t *bin, int32_t length, const UCollator *base, UErrorCode *status)
| Opens a collator from a collator binary image created using ucol_cloneBinary.

## Detailed Description

C API: Collator.

## Collator C API

The C API for Collator performs locale-sensitive string comparison. You use this service to build searching and sorting routines for natural language text.

For more information about the collation service see the User Guide.

Collation service provides correct sorting orders for most locales supported in ICU. If specific data for a locale is not available, the orders eventually falls back to the CLDR root sort order.

Sort ordering may be customized by providing your own set of rules. For more on this subject see the Collation Customization section of the User Guide.

See also
  UCollationResult
  UNormalizationMode
  UCollationStrength
  UCollationElements

Definition in file ucol.h.

## Macro Definition Documentation

## U_COL_SAFECLONE_BUFFERSIZE

#define U_COL_SAFECLONE_BUFFERSIZE 1

default memory size for the new clone.

Deprecated:
  ICU 52. Do not rely on ucol_safeClone() cloning into any provided buffer.

Definition at line 1369 of file ucol.h.

## Typedef Documentation

## equal_to

using U_HEADER_ONLY_NAMESPACE::collator::equal_to = typedef internal::Predicate<std::equal_to, UCOL_EQUAL>

Function object for performing comparisons using this collator.

Like `std::equal_to` but uses the collator instead of `operator==`.

Draft:
  This API may be changed in the future versions and was introduced in ICU 76

Definition at line 1602 of file ucol.h.

## greater

using U_HEADER_ONLY_NAMESPACE::collator::greater = typedef internal::Predicate<std::equal_to, UCOL_GREATER>

Function object for performing comparisons using this collator.

Like `std::greater` but uses the collator instead of `operator>`.

Draft:
  This API may be changed in the future versions and was introduced in ICU 76

Definition at line 1609 of file ucol.h.

## greater_equal

using U_HEADER_ONLY_NAMESPACE::collator::greater_equal = typedef internal::Predicate<std::not_equal_to, UCOL_LESS>

Function object for performing comparisons using this collator.

Like `std::greater_equal` but uses the collator instead of `operator>=`.

Draft:
  This API may be changed in the future versions and was introduced in ICU 76

Definition at line 1630 of file ucol.h.

## less

using U_HEADER_ONLY_NAMESPACE::collator::less = typedef internal::Predicate<std::equal_to, UCOL_LESS>

Function object for performing comparisons using this collator.

Like `std::less` but uses the collator instead of `operator<`.

Draft:
  This API may be changed in the future versions and was introduced in ICU 76

Definition at line 1616 of file ucol.h.

## less_equal

using U_HEADER_ONLY_NAMESPACE::collator::less_equal = typedef internal::Predicate<std::not_equal_to, UCOL_GREATER>

Function object for performing comparisons using this collator.

Like `std::less_equal` but uses the collator instead of `operator<=`.

Draft:
  This API may be changed in the future versions and was introduced in ICU 76

Definition at line 1637 of file ucol.h.

## not_equal_to

using U_HEADER_ONLY_NAMESPACE::collator::not_equal_to = typedef internal::Predicate<std::not_equal_to, UCOL_EQUAL>

Function object for performing comparisons using this collator.

Like `std::not_equal_to` but uses the collator instead of `operator!=`.

Draft:
  This API may be changed in the future versions and was introduced in ICU 76

Definition at line 1623 of file ucol.h.

## UCollationStrength

typedef UColAttributeValue UCollationStrength

Base letter represents a primary difference.

Set comparison level to UCOL_PRIMARY to ignore secondary and tertiary differences. Use this to set the strength of a Collator object. Example of primary difference, "abc" < "abd"

Diacritical differences on the same base letter represent a secondary difference. Set comparison level to UCOL_SECONDARY to ignore tertiary differences. Use this to set the strength of a Collator object. Example of secondary difference, "&auml;" >> "a".

Uppercase and lowercase versions of the same character represents a tertiary difference. Set comparison level to UCOL_TERTIARY to include all comparison differences. Use this to set the strength of a Collator object. Example of tertiary difference, "abc" <<< "ABC".

Two characters are considered "identical" when they have the same unicode spellings. UCOL_IDENTICAL. For example, "&auml;" == "&auml;".

UCollationStrength is also used to determine the strength of sort keys generated from UCollator objects These values can be now found in the UColAttributeValue enum.

Stable:
  ICU 2.0

Definition at line 239 of file ucol.h.

## UCollator

typedef struct UCollator UCollator

structure representing a collator object instance

Stable:
  ICU 2.0

Definition at line 61 of file ucol.h.

## Enumeration Type Documentation

## UColAttribute

enum UColAttribute

Attributes that collation service understands.

All the attributes can take UCOL_DEFAULT value, as well as the values specific to each one.

Stable:
  ICU 2.0

Enumerator

UCOL_FRENCH_COLLATION

Attribute for direction of secondary weights - used in Canadian French.

Acceptable values are UCOL_ON, which results in secondary weights being considered backwards and UCOL_OFF which treats secondary weights in the order they appear.

Stable:
  ICU 2.0

UCOL_ALTERNATE_HANDLING

Attribute for handling variable elements.

Acceptable values are UCOL_NON_IGNORABLE which treats all the codepoints with non-ignorable primary weights in the same way, and UCOL_SHIFTED which causes codepoints with primary weights that are equal or below the variable top value to be ignored on primary level and moved to the quaternary level. The default setting in a Collator object depends on the locale data loaded from the resources. For most locales, the default is UCOL_NON_IGNORABLE, but for others, such as "th", the default could be UCOL_SHIFTED.

Stable:
  ICU 2.0

UCOL_CASE_FIRST

Controls the ordering of upper and lower case letters.

Acceptable values are UCOL_OFF, which orders upper and lower case letters in accordance to their tertiary weights, UCOL_UPPER_FIRST which forces upper case letters to sort before lower case letters, and UCOL_LOWER_FIRST which does the opposite. The default setting in a Collator object depends on the locale data loaded from the resources. For most locales, the default is UCOL_OFF, but for others, such as "da" or "mt", the default could be UCOL_UPPER.

Stable:
  ICU 2.0

UCOL_CASE_LEVEL

Controls whether an extra case level (positioned before the third level) is generated or not.

Acceptable values are UCOL_OFF, when case level is not generated, and UCOL_ON which causes the case level to be generated. Contents of the case level are affected by the value of UCOL_CASE_FIRST attribute. A simple way to ignore accent differences in a string is to set the strength to UCOL_PRIMARY and enable case level. The default setting in a Collator object depends on the locale data loaded from the resources.

Stable:
  ICU 2.0

UCOL_NORMALIZATION_MODE

Controls whether the normalization check and necessary normalizations are performed.

When set to UCOL_OFF no normalization check is performed. The correctness of the result is guaranteed only if the input data is in so-called FCD form (see users manual for more info). When set to UCOL_ON, an incremental check is performed to see whether the input data is in the FCD form. If the data is not in the FCD form, incremental NFD normalization is performed. The default setting in a Collator object depends on the locale data loaded from the resources. For many locales, the default is UCOL_OFF, but for others, such as "hi" "vi', or "bn", * the default could be UCOL_ON.

Stable:
  ICU 2.0

UCOL_DECOMPOSITION_MODE

An alias for UCOL_NORMALIZATION_MODE attribute.

Stable:
  ICU 2.0

UCOL_STRENGTH

The strength attribute.

Can be either UCOL_PRIMARY, UCOL_SECONDARY, UCOL_TERTIARY, UCOL_QUATERNARY or UCOL_IDENTICAL. The usual strength for most locales (except Japanese) is tertiary.

Quaternary strength is useful when combined with shifted setting for alternate handling attribute and for JIS X 4061 collation, when it is used to distinguish between Katakana and Hiragana. Otherwise, quaternary level is affected only by the number of non-ignorable code points in the string.

Identical strength is rarely useful, as it amounts to codepoints of the NFD form of the string.

Stable:
  ICU 2.0

UCOL_HIRAGANA_QUATERNARY_MODE

When turned on, this attribute positions Hiragana before all
non-ignorables on quaternary level This is a sneaky way to produce JIS sort order.

This attribute was an implementation detail of the CLDR Japanese tailoring. Since ICU 50, this attribute is not settable any more via API functions. Since CLDR 25/ICU 53, explicit quaternary relations are used to achieve the same Japanese sort order.

Deprecated:
  ICU 50 Implementation detail, cannot be set via API, was removed from implementation.

UCOL_NUMERIC_COLLATION

When turned on, this attribute makes substrings of digits sort according to their numeric values.

This is a way to get '100' to sort AFTER '2'. Note that the longest digit substring that can be treated as a single unit is 254 digits (not counting leading zeros). If a digit substring is longer than that, the digits beyond the limit will be treated as a separate digit substring.

A "digit" in this sense is a code point with General_Category=Nd, which does not include circled numbers, roman numerals, etc. Only a contiguous digit substring is considered, that is, non-negative integers without separators. There is no support for plus/minus signs, decimals, exponents, etc.

Stable:
  ICU 2.8

UCOL_ATTRIBUTE_COUNT

One more than the highest normal UColAttribute value.

Deprecated:
  ICU 58 The numeric value may change over time, see ICU ticket #12420.

Definition at line 245 of file ucol.h.

## UColAttributeValue

enum UColAttributeValue

Enum containing attribute values for controlling collation behavior.

Here are all the allowable values. Not every attribute can take every value. The only universal value is UCOL_DEFAULT, which resets the attribute value to the predefined
value for that locale

Stable:
  ICU 2.0

Enumerator
UCOL_DEFAULT | accepted by most attributes
UCOL_PRIMARY | Primary collation strength.
UCOL_SECONDARY | Secondary collation strength.
UCOL_TERTIARY | Tertiary collation strength.
UCOL_DEFAULT_STRENGTH | Default collation strength.
UCOL_QUATERNARY | Quaternary collation strength.
UCOL_IDENTICAL | Identical collation strength.
UCOL_OFF | Turn the feature off - works for UCOL_FRENCH_COLLATION, UCOL_CASE_LEVEL, UCOL_HIRAGANA_QUATERNARY_MODE & UCOL_DECOMPOSITION_MODE.
UCOL_ON | Turn the feature on - works for UCOL_FRENCH_COLLATION, UCOL_CASE_LEVEL, UCOL_HIRAGANA_QUATERNARY_MODE & UCOL_DECOMPOSITION_MODE.
UCOL_SHIFTED | Valid for UCOL_ALTERNATE_HANDLING. Alternate handling will be shifted
UCOL_NON_IGNORABLE | Valid for UCOL_ALTERNATE_HANDLING. Alternate handling will be non ignorable
UCOL_LOWER_FIRST | Valid for UCOL_CASE_FIRST - lower case sorts before upper case.
UCOL_UPPER_FIRST | upper case sorts before lower case

UCOL_ATTRIBUTE_VALUE_COUNT

One more than the highest normal UColAttributeValue value.

Deprecated:
  ICU 58 The numeric value may change over time, see ICU ticket #12420.

Definition at line 92 of file ucol.h.

## UColBoundMode

enum UColBoundMode

enum that is taken by ucol_getBound API See below for explanation
do not change the values assigned to the members of this enum.

Underlying code
depends on them having these numbers

Stable:
  ICU 2.0

Enumerator
UCOL_BOUND_LOWER | lower bound
UCOL_BOUND_UPPER | upper bound that will match strings of exact size
UCOL_BOUND_UPPER_LONG | upper bound that will match all the strings that have the same initial substring as the given string

UCOL_BOUND_VALUE_COUNT

One more than the highest normal UColBoundMode value.

Deprecated:
  ICU 58 The numeric value may change over time, see ICU ticket #12420.

Definition at line 1071 of file ucol.h.

## UCollationResult

enum UCollationResult

UCOL_LESS is returned if source string is compared to be less than target string in the ucol_strcoll() method.

UCOL_EQUAL is returned if source string is compared to be equal to target string in the ucol_strcoll() method. UCOL_GREATER is returned if source string is compared to be greater than target string in the ucol_strcoll() method.

See also
  ucol_strcoll()

Possible values for a comparison result

Stable:
  ICU 2.0

Enumerator
UCOL_EQUAL | string a == string b
UCOL_GREATER | string a > string b
UCOL_LESS | string a < string b

Definition at line 76 of file ucol.h.

## UColReorderCode

enum UColReorderCode

Enum containing the codes for reordering segments of the collation table that are not script codes.

These reordering codes are to be used in conjunction with the script codes.

See also
  ucol_getReorderCodes
  ucol_setReorderCodes
  ucol_getEquivalentReorderCodes
  UScriptCode

Stable:
  ICU 4.8

Enumerator

UCOL_REORDER_CODE_DEFAULT

A special reordering code that is used to specify the default reordering codes for a locale.

Stable:
  ICU 4.8

UCOL_REORDER_CODE_NONE

A special reordering code that is used to specify no reordering codes.

Stable:
  ICU 4.8

UCOL_REORDER_CODE_OTHERS

A special reordering code that is used to specify all other codes used for reordering except for the codes lised as UColReorderCode values and those listed explicitly in a reordering.

Stable:
  ICU 4.8

UCOL_REORDER_CODE_SPACE

Characters with the space property.

This is equivalent to the rule value "space".

Stable:
  ICU 4.8

UCOL_REORDER_CODE_FIRST

The first entry in the enumeration of reordering groups.

This is intended for use in range checking and enumeration of the reorder codes.

Stable:
  ICU 4.8

UCOL_REORDER_CODE_PUNCTUATION

Characters with the punctuation property.

This is equivalent to the rule value "punct".

Stable:
  ICU 4.8

UCOL_REORDER_CODE_SYMBOL

Characters with the symbol property.

This is equivalent to the rule value "symbol".

Stable:
  ICU 4.8

UCOL_REORDER_CODE_CURRENCY

Characters with the currency property.

This is equivalent to the rule value "currency".

Stable:
  ICU 4.8

UCOL_REORDER_CODE_DIGIT

Characters with the digit property.

This is equivalent to the rule value "digit".

Stable:
  ICU 4.8

UCOL_REORDER_CODE_LIMIT

One more than the highest normal UColReorderCode value.

Deprecated:
  ICU 58 The numeric value may change over time, see ICU ticket #12420.

Definition at line 149 of file ucol.h.

## UColRuleOption

enum UColRuleOption

Options for retrieving the rule string.

Stable:
  ICU 2.0

Enumerator

UCOL_TAILORING_ONLY

Retrieves the tailoring rules only.

Same as calling the version of getRules() without UColRuleOption.

Stable:
  ICU 2.0

UCOL_FULL_RULES

Retrieves the "UCA rules" concatenated with the tailoring rules.

The "UCA rules" are an approximation of the root collator's sort order. They are almost never used or useful at runtime and can be removed from the data. See https://unicode-org.github.io/icu/userguide/collation/customization#building-on-existing-locales

Stable:
  ICU 2.0

Definition at line 372 of file ucol.h.

## Function Documentation

## ucol_clone()

U_CAPI UCollator * ucol_clone | ( | const UCollator * | coll,
|  | UErrorCode * | status
| ) |  |

Thread safe cloning operation.

The result is a clone of a given collator.

Parameters

  coll | collator to be cloned
  status | to indicate whether the operation went on smoothly or there were errors

Returns
  pointer to the new clone

See also
  ucol_open
  ucol_openRules
  ucol_close

Stable:
  ICU 71

## ucol_cloneBinary()

U_CAPI int32_t ucol_cloneBinary | ( | const UCollator * | coll,
|  | uint8_t * | buffer,
|  | int32_t | capacity,
|  | UErrorCode * | status
| ) |  |

Creates a binary image of a collator.

This binary image can be stored and later used to instantiate a collator using ucol_openBinary. This API supports preflighting.

Parameters

  coll | Collator
  buffer | a fill-in buffer to receive the binary image
  capacity | capacity of the destination buffer
  status | for catching errors

Returns
  size of the image

See also
  ucol_openBinary

Stable:
  ICU 3.2

## ucol_close()

U_CAPI void ucol_close | ( | UCollator * | coll | ) |

Close a UCollator.

Once closed, a UCollator should not be used. Every open collator should be closed. Otherwise, a memory leak will result.

Parameters

  coll | The UCollator to close.

See also
  ucol_open
  ucol_openRules
  ucol_clone

Stable:
  ICU 2.0

## ucol_countAvailable()

U_CAPI int32_t ucol_countAvailable | ( | void |  | ) |

Determine how many locales have collation rules available.

This function is most useful as determining the loop ending condition for calls to `ucol_getAvailable`.

Returns
  The number of locales for which collation rules are available.

See also
  ucol_getAvailable

Stable:
  ICU 2.0

## ucol_equal()

U_CAPI UBool ucol_equal | ( | const UCollator * | coll,
|  | const UChar * | source,
|  | int32_t | sourceLength,
|  | const UChar * | target,
|  | int32_t | targetLength
| ) |  |

Compare two strings for equality.

This function is equivalent to `ucol_strcoll` == UCOL_EQUAL

Parameters

  coll | The UCollator containing the comparison rules.
  source | The source string.
  sourceLength | The length of source, or -1 if null-terminated.
  target | The target string.
  targetLength | The length of target, or -1 if null-terminated.

Returns
  true if source is equal to target, false otherwise

See also
  ucol_strcoll
  ucol_greater
  ucol_greaterOrEqual

Stable:
  ICU 2.0

## ucol_getAttribute()

U_CAPI UColAttributeValue ucol_getAttribute | ( | const UCollator * | coll,
|  | UColAttribute | attr,
|  | UErrorCode * | status
| ) |  |

Universal attribute getter.

Parameters

  coll | collator which attributes are to be changed
  attr | attribute type

Returns
  attribute value

Parameters

  status | to indicate whether the operation went on smoothly or there were errors

See also
  UColAttribute
  UColAttributeValue
  ucol_setAttribute

Stable:
  ICU 2.0

## ucol_getAvailable()

U_CAPI const char * ucol_getAvailable | ( | int32_t | localeIndex | ) |

Get a locale for which collation rules are available.

A UCollator in a locale returned by this function will perform the correct collation for the locale.

Parameters

  localeIndex | The index of the desired locale.

Returns
  A locale for which collation rules are available, or 0 if none.

See also
  ucol_countAvailable

Stable:
  ICU 2.0

## ucol_getBound()

U_CAPI int32_t ucol_getBound | ( | const uint8_t * | source,
|  | int32_t | sourceLength,
|  | UColBoundMode | boundType,
|  | uint32_t | noOfLevels,
|  | uint8_t * | result,
|  | int32_t | resultLength,
|  | UErrorCode * | status
| ) |  |

Produce a bound for a given sortkey and a number of levels.

Return value is always the number of bytes needed, regardless of whether the result buffer was big enough or even valid.
Resulting bounds can be used to produce a range of strings that are between upper and lower bounds. For example, if bounds are produced for a sortkey of string "smith", strings between upper and lower bounds with one level would include "Smith", "SMITH", "sMiTh".
There are two upper bounds that can be produced. If UCOL_BOUND_UPPER is produced, strings matched would be as above. However, if bound produced using UCOL_BOUND_UPPER_LONG is used, the above example will also match "Smithsonian" and similar.
For more on usage, see example in cintltst/capitst.c in procedure TestBounds. Sort keys may be compared using `strcmp`.

Parameters

  source | The source sortkey.
  sourceLength | The length of source, or -1 if null-terminated. (If an unmodified sortkey is passed, it is always null terminated).
  boundType | Type of bound required. It can be UCOL_BOUND_LOWER, which produces a lower inclusive bound, UCOL_BOUND_UPPER, that produces upper bound that matches strings of the same length or UCOL_BOUND_UPPER_LONG that matches strings that have the same starting substring as the source string.
  noOfLevels | Number of levels required in the resulting bound (for most uses, the recommended value is 1). See users guide for explanation on number of levels a sortkey can have.
  result | A pointer to a buffer to receive the resulting sortkey.
  resultLength | The maximum size of result.
  status | Used for returning error code if something went wrong. If the number of levels requested is higher than the number of levels in the source key, a warning (U_SORT_KEY_TOO_SHORT_WARNING) is issued.

Returns
  The size needed to fully store the bound.

See also
  ucol_keyHashCode

Stable:
  ICU 2.1

## ucol_getContractions()

int32_t ucol_getContractions | ( | const UCollator * | coll,
|  | USet * | conts,
|  | UErrorCode * | status
| ) |  |

Get a set containing the contractions defined by the collator.

The set includes both the root collator's contractions and the contractions defined by the collator. This set will contain only strings. If a tailoring explicitly suppresses contractions from the root collator (like Russian), removed contractions will not be in the resulting set.

Parameters

  coll | collator
  conts | the set to hold the result. It gets emptied before contractions are added.
  status | to hold the error code

Returns
  the size of the contraction set

Deprecated:
  ICU 3.4, use ucol_getContractionsAndExpansions instead

## ucol_getContractionsAndExpansions()

U_CAPI void ucol_getContractionsAndExpansions | ( | const UCollator * | coll,
|  | USet * | contractions,
|  | USet * | expansions,
|  | UBool | addPrefixes,
|  | UErrorCode * | status
| ) |  |

Get a set containing the expansions defined by the collator.

The set includes both the root collator's expansions and the expansions defined by the tailoring

Parameters

  coll | collator
  contractions | if not NULL, the set to hold the contractions
  expansions | if not NULL, the set to hold the expansions
  addPrefixes | add the prefix contextual elements to contractions
  status | to hold the error code

Stable:
  ICU 3.4

## ucol_getDisplayName()

U_CAPI int32_t ucol_getDisplayName | ( | const char * | objLoc,
|  | const char * | dispLoc,
|  | UChar * | result,
|  | int32_t | resultLength,
|  | UErrorCode * | status
| ) |  |

Get the display name for a UCollator.

The display name is suitable for presentation to a user.

Parameters

  objLoc | The locale of the collator in question.
  dispLoc | The locale for display.
  result | A pointer to a buffer to receive the attribute.
  resultLength | The maximum size of result.
  status | A pointer to a UErrorCode to receive any errors

Returns
  The total buffer size needed; if greater than resultLength, the output was truncated.

Stable:
  ICU 2.0

## ucol_getEquivalentReorderCodes()

U_CAPI int32_t ucol_getEquivalentReorderCodes | ( | int32_t | reorderCode,
|  | int32_t * | dest,
|  | int32_t | destCapacity,
|  | UErrorCode * | pErrorCode
| ) |  |

Retrieves the reorder codes that are grouped with the given reorder code.

Some reorder codes will be grouped and must reorder together. Beginning with ICU 55, scripts only reorder together if they are primary-equal, for example Hiragana and Katakana.

Parameters

  reorderCode | The reorder code to determine equivalence for.
  dest | The array to fill with the script ordering.
  destCapacity | The length of dest. If it is 0, then dest may be NULL and the function will only return the length of the result without writing any codes (pre-flighting).
  pErrorCode | Must be a valid pointer to an error code value, which must not indicate a failure before the function call.

Returns
  The number of reordering codes written to the dest array.

See also
  ucol_setReorderCodes
  ucol_getReorderCodes
  UScriptCode
  UColReorderCode

Stable:
  ICU 4.8

## ucol_getFunctionalEquivalent()

U_CAPI int32_t ucol_getFunctionalEquivalent | ( | char * | result,
|  | int32_t | resultCapacity,
|  | const char * | keyword,
|  | const char * | locale,
|  | UBool * | isAvailable,
|  | UErrorCode * | status
| ) |  |

Return the functionally equivalent locale for the specified input locale, with respect to given keyword, for the collation service.

If two different input locale + keyword combinations produce the same result locale, then collators instantiated for these two different input locales will behave equivalently. The converse is not always true; two collators may in fact be equivalent, but return different results, due to internal details. The return result has no other meaning than that stated above, and implies nothing as to the relationship between the two locales. This is intended for use by applications who wish to cache collators, or otherwise reuse collators when possible. The functional equivalent may change over time. For more information, please see the Locales and Services section of the ICU User Guide.

Parameters

  result | fillin for the functionally equivalent result locale
  resultCapacity | capacity of the fillin buffer
  keyword | a particular keyword as enumerated by ucol_getKeywords.
  locale | the specified input locale
  isAvailable | if non-NULL, pointer to a fillin parameter that on return indicates whether the specified input locale was 'available' to the collation service. A locale is defined as 'available' if it physically exists within the collation locale data.
  status | pointer to input-output error code

Returns
  the actual buffer size needed for the locale. If greater than resultCapacity, the returned full name will be truncated and an error code will be returned.

Stable:
  ICU 3.0

## ucol_getKeywords()

U_CAPI UEnumeration * ucol_getKeywords | ( | UErrorCode * | status | ) |

Create a string enumerator of all possible keywords that are relevant to collation.

At this point, the only recognized keyword for this service is "collation".

Parameters

  status | input-output error code

Returns
  a string enumeration over locale strings. The caller is responsible for closing the result.

Stable:
  ICU 3.0

## ucol_getKeywordValues()

U_CAPI UEnumeration * ucol_getKeywordValues | ( | const char * | keyword,
|  | UErrorCode * | status
| ) |  |

Given a keyword, create a string enumeration of all values for that keyword that are currently in use.

Parameters

  keyword | a particular keyword as enumerated by ucol_getKeywords. If any other keyword is passed in, *status is set to U_ILLEGAL_ARGUMENT_ERROR.
  status | input-output error code

Returns
  a string enumeration over collation keyword values, or NULL upon error. The caller is responsible for closing the result.

Stable:
  ICU 3.0

## ucol_getKeywordValuesForLocale()

U_CAPI UEnumeration * ucol_getKeywordValuesForLocale | ( | const char * | key,
|  | const char * | locale,
|  | UBool | commonlyUsed,
|  | UErrorCode * | status
| ) |  |

Given a key and a locale, returns an array of string values in a preferred order that would make a difference.

These are all and only those values where the open (creation) of the service with the locale formed from the input locale plus input keyword and that value has different behavior than creation with the input locale alone.

Parameters

  key | one of the keys supported by this service. For now, only "collation" is supported.
  locale | the locale
  commonlyUsed | if set to true it will return only commonly used values with the given locale in preferred order. Otherwise, it will return all the available values for the locale.
  status | error status

Returns
  a string enumeration over keyword values for the given key and the locale.

Stable:
  ICU 4.2

## ucol_getLocale()

const char * ucol_getLocale | ( | const UCollator * | coll,
|  | ULocDataLocaleType | type,
|  | UErrorCode * | status
| ) |  |

gets the locale name of the collator.

If the collator is instantiated from the rules, then this function returns NULL.

Parameters

  coll | The UCollator for which the locale is needed
  type | You can choose between requested, valid and actual locale. For description see the definition of ULocDataLocaleType in uloc.h
  status | error code of the operation

Returns
  real locale name from which the collation data comes. If the collator was instantiated from rules, returns NULL.

Deprecated:
  ICU 2.8 Use ucol_getLocaleByType instead

## ucol_getLocaleByType()

U_CAPI const char * ucol_getLocaleByType | ( | const UCollator * | coll,
|  | ULocDataLocaleType | type,
|  | UErrorCode * | status
| ) |  |

gets the locale name of the collator.

If the collator is instantiated from the rules, then this function returns NULL.

Parameters

  coll | The UCollator for which the locale is needed
  type | You can choose between requested, valid and actual locale. For description see the definition of ULocDataLocaleType in uloc.h
  status | error code of the operation

Returns
  real locale name from which the collation data comes. If the collator was instantiated from rules, returns NULL.

Stable:
  ICU 2.8

## ucol_getMaxVariable()

U_CAPI UColReorderCode ucol_getMaxVariable | ( | const UCollator * | coll | ) |

Returns the maximum reordering group whose characters are affected by UCOL_ALTERNATE_HANDLING.

Parameters

  coll | the collator

Returns
  the maximum variable reordering group.

See also
  ucol_setMaxVariable

Stable:
  ICU 53

## ucol_getReorderCodes()

U_CAPI int32_t ucol_getReorderCodes | ( | const UCollator * | coll,
|  | int32_t * | dest,
|  | int32_t | destCapacity,
|  | UErrorCode * | pErrorCode
| ) |  |

Retrieves the reordering codes for this collator.

These reordering codes are a combination of UScript codes and UColReorderCode entries.

Parameters

  coll | The UCollator to query.
  dest | The array to fill with the script ordering.
  destCapacity | The length of dest. If it is 0, then dest may be NULL and the function will only return the length of the result without writing any codes (pre-flighting).
  pErrorCode | Must be a valid pointer to an error code value, which must not indicate a failure before the function call.

Returns
  The number of reordering codes written to the dest array.

See also
  ucol_setReorderCodes
  ucol_getEquivalentReorderCodes
  UScriptCode
  UColReorderCode

Stable:
  ICU 4.8

## ucol_getRules()

U_CAPI const UChar * ucol_getRules | ( | const UCollator * | coll,
|  | int32_t * | length
| ) |  |

Get the collation tailoring rules from a UCollator.

The rules will follow the rule syntax.

Parameters

  coll | The UCollator to query.
  length |

Returns
  The collation tailoring rules.

Stable:
  ICU 2.0

## ucol_getRulesEx()

U_CAPI int32_t ucol_getRulesEx | ( | const UCollator * | coll,
|  | UColRuleOption | delta,
|  | UChar * | buffer,
|  | int32_t | bufferLen
| ) |  |

Returns current rules.

Delta defines whether full rules are returned or just the tailoring. Returns number of UChars needed to store rules. If buffer is NULL or bufferLen is not enough to store rules, will store up to available space.

ucol_getRules() should normally be used instead. See https://unicode-org.github.io/icu/userguide/collation/customization#building-on-existing-locales

Parameters

  coll | collator to get the rules from
  delta | one of UCOL_TAILORING_ONLY, UCOL_FULL_RULES.
  buffer | buffer to store the result in. If NULL, you'll get no rules.
  bufferLen | length of buffer to store rules in. If less than needed you'll get only the part that fits in.

Returns
  current rules

Stable:
  ICU 2.0

See also
  UCOL_FULL_RULES

## ucol_getShortDefinitionString()

int32_t ucol_getShortDefinitionString | ( | const UCollator * | coll,
|  | const char * | locale,
|  | char * | buffer,
|  | int32_t | capacity,
|  | UErrorCode * | status
| ) |  |

Get the short definition string for a collator.

This API harvests the collator's locale and the attribute set and produces a string that can be used for opening a collator with the same attributes using the ucol_openFromShortString API. This string will be normalized. The structure and the syntax of the string is defined in the "Naming collators" section of the users guide: https://unicode-org.github.io/icu/userguide/collation/concepts#collator-naming-scheme This API supports preflighting.

Parameters

  coll | a collator
  locale | a locale that will appear as a collators locale in the resulting short string definition. If NULL, the locale will be harvested from the collator.
  buffer | space to hold the resulting string
  capacity | capacity of the buffer
  status | for returning errors. All the preflighting errors are featured

Returns
  length of the resulting string

See also
  ucol_openFromShortString
  ucol_normalizeShortDefinitionString

Deprecated:
  ICU 54

## ucol_getSortKey()

U_CAPI int32_t ucol_getSortKey | ( | const UCollator * | coll,
|  | const UChar * | source,
|  | int32_t | sourceLength,
|  | uint8_t * | result,
|  | int32_t | resultLength
| ) |  |

Get a sort key for a string from a UCollator.

Sort keys may be compared using `strcmp`.

Note that sort keys are often less efficient than simply doing comparison.
For more details, see the ICU User Guide.

Like ICU functions that write to an output buffer, the buffer contents is undefined if the buffer capacity (resultLength parameter) is too small. Unlike ICU functions that write a string to an output buffer, the terminating zero byte is counted in the sort key length.

Parameters

  coll | The UCollator containing the collation rules.
  source | The string to transform.
  sourceLength | The length of source, or -1 if null-terminated.
  result | A pointer to a buffer to receive the attribute.
  resultLength | The maximum size of result.

Returns
  The size needed to fully store the sort key. If there was an internal error generating the sort key, a zero value is returned.

See also
  ucol_keyHashCode

Stable:
  ICU 2.0

## ucol_getStrength()

U_CAPI UCollationStrength ucol_getStrength | ( | const UCollator * | coll | ) |

Get the collation strength used in a UCollator.

The strength influences how strings are compared.

Parameters

  coll | The UCollator to query.

Returns
  The collation strength; one of UCOL_PRIMARY, UCOL_SECONDARY, UCOL_TERTIARY, UCOL_QUATERNARY, UCOL_IDENTICAL

See also
  ucol_setStrength

Stable:
  ICU 2.0

## ucol_getTailoredSet()

U_CAPI USet * ucol_getTailoredSet | ( | const UCollator * | coll,
|  | UErrorCode * | status
| ) |  |

Get a Unicode set that contains all the characters and sequences tailored in this collator.

The result must be disposed of by using uset_close.

Parameters

  coll | The UCollator for which we want to get tailored chars
  status | error code of the operation

Returns
  a pointer to newly created USet. Must be be disposed by using uset_close

See also
  ucol_openRules
  uset_close

Stable:
  ICU 2.4

## ucol_getUCAVersion()

U_CAPI void ucol_getUCAVersion | ( | const UCollator * | coll,
|  | UVersionInfo | info
| ) |  |

Gets the UCA version information for a Collator.

Version is the UCA version number (3.1.1, 4.0).

Parameters

  coll | The UCollator to query.
  info | the version # information, the result will be filled in

Stable:
  ICU 2.8

## ucol_getUnsafeSet()

U_CAPI int32_t ucol_getUnsafeSet | ( | const UCollator * | coll,
|  | USet * | unsafe,
|  | UErrorCode * | status
| ) |  |

Calculates the set of unsafe code points, given a collator.

A character is unsafe if you could append any character and cause the ordering to alter significantly. Collation sorts in normalized order, so anything that rearranges in normalization can cause this. Thus if you have a character like a_umlaut, and you add a lower_dot to it, then it normalizes to a_lower_dot + umlaut, and sorts differently.

Parameters

  coll | Collator
  unsafe | a fill-in set to receive the unsafe points
  status | for catching errors

Returns
  number of elements in the set

Internal:
  Do not use. This API is for internal use only. ICU 3.0

## ucol_getVariableTop()

U_CAPI uint32_t ucol_getVariableTop | ( | const UCollator * | coll,
|  | UErrorCode * | status
| ) |  |

Gets the variable top value of a Collator.

Parameters

  coll | collator which variable top needs to be retrieved
  status | error code (not changed by function). If error code is set, the return value is undefined.

Returns
  the variable top primary weight

See also
  ucol_getMaxVariable
  ucol_setVariableTop
  ucol_restoreVariableTop

Stable:
  ICU 2.0

## ucol_getVersion()

U_CAPI void ucol_getVersion | ( | const UCollator * | coll,
|  | UVersionInfo | info
| ) |  |

Gets the version information for a Collator.

Version is currently an opaque 32-bit number which depends, among other things, on major versions of the collator tailoring and UCA.

Parameters

  coll | The UCollator to query.
  info | the version # information, the result will be filled in

Stable:
  ICU 2.0

## ucol_greater()

U_CAPI UBool ucol_greater | ( | const UCollator * | coll,
|  | const UChar * | source,
|  | int32_t | sourceLength,
|  | const UChar * | target,
|  | int32_t | targetLength
| ) |  |

Determine if one string is greater than another.

This function is equivalent to `ucol_strcoll` == UCOL_GREATER

Parameters

  coll | The UCollator containing the comparison rules.
  source | The source string.
  sourceLength | The length of source, or -1 if null-terminated.
  target | The target string.
  targetLength | The length of target, or -1 if null-terminated.

Returns
  true if source is greater than target, false otherwise.

See also
  ucol_strcoll
  ucol_greaterOrEqual
  ucol_equal

Stable:
  ICU 2.0

## ucol_greaterOrEqual()

U_CAPI UBool ucol_greaterOrEqual | ( | const UCollator * | coll,
|  | const UChar * | source,
|  | int32_t | sourceLength,
|  | const UChar * | target,
|  | int32_t | targetLength
| ) |  |

Determine if one string is greater than or equal to another.

This function is equivalent to `ucol_strcoll` != UCOL_LESS

Parameters

  coll | The UCollator containing the comparison rules.
  source | The source string.
  sourceLength | The length of source, or -1 if null-terminated.
  target | The target string.
  targetLength | The length of target, or -1 if null-terminated.

Returns
  true if source is greater than or equal to target, false otherwise.

See also
  ucol_strcoll
  ucol_greater
  ucol_equal

Stable:
  ICU 2.0

## ucol_mergeSortkeys()

U_CAPI int32_t ucol_mergeSortkeys | ( | const uint8_t * | src1,
|  | int32_t | src1Length,
|  | const uint8_t * | src2,
|  | int32_t | src2Length,
|  | uint8_t * | dest,
|  | int32_t | destCapacity
| ) |  |

Merges two sort keys.

The levels are merged with their corresponding counterparts (primaries with primaries, secondaries with secondaries etc.). Between the values from the same level a separator is inserted.

This is useful, for example, for combining sort keys from first and last names to sort such pairs. See http://www.unicode.org/reports/tr10/#Merging_Sort_Keys

The recommended way to achieve "merged" sorting is by concatenating strings with U+FFFE between them. The concatenation has the same sort order as the merged sort keys, but merge(getSortKey(str1), getSortKey(str2)) may differ from getSortKey(str1 + '\uFFFE' + str2). Using strings with U+FFFE may yield shorter sort keys.

For details about Sort Key Features see https://unicode-org.github.io/icu/userguide/collation/api#sort-key-features

It is possible to merge multiple sort keys by consecutively merging another one with the intermediate result.

The length of the merge result is the sum of the lengths of the input sort keys.

Example (uncompressed):

    191B1D 01 050505 01 910505 00
    1F2123 01 050505 01 910505 00

will be merged as

    191B1D 02 1F2123 01 050505 02 050505 01 910505 02 910505 00

If the destination buffer is not big enough, then its contents are undefined. If any of source lengths are zero or any of the source pointers are NULL/undefined, the result is of size zero.

Parameters

  src1 | the first sort key
  src1Length | the length of the first sort key, including the zero byte at the end; can be -1 if the function is to find the length
  src2 | the second sort key
  src2Length | the length of the second sort key, including the zero byte at the end; can be -1 if the function is to find the length
  dest | the buffer where the merged sort key is written, can be NULL if destCapacity==0
  destCapacity | the number of bytes in the dest buffer

Returns
  the length of the merged sort key, src1Length+src2Length; can be larger than destCapacity, or 0 if an error occurs (only for illegal arguments), in which cases the contents of dest is undefined

Stable:
  ICU 2.0

## ucol_nextSortKeyPart()

U_CAPI int32_t ucol_nextSortKeyPart | ( | const UCollator * | coll,
|  | UCharIterator * | iter,
|  | uint32_t | state[2],
|  | uint8_t * | dest,
|  | int32_t | count,
|  | UErrorCode * | status
| ) |  |

Gets the next count bytes of a sort key.

Caller needs to preserve state array between calls and to provide the same type of UCharIterator set with the same string. The destination buffer provided must be big enough to store the number of requested bytes.

The generated sort key may or may not be compatible with sort keys generated using ucol_getSortKey().

Parameters

  coll | The UCollator containing the collation rules.
  iter | UCharIterator containing the string we need the sort key to be calculated for.
  state | Opaque state of sortkey iteration.
  dest | Buffer to hold the resulting sortkey part
  count | number of sort key bytes required.
  status | error code indicator.

Returns
  the actual number of bytes of a sortkey. It can be smaller than count if we have reached the end of the sort key.

Stable:
  ICU 2.6

## ucol_normalizeShortDefinitionString()

int32_t ucol_normalizeShortDefinitionString | ( | const char * | source,
|  | char * | destination,
|  | int32_t | capacity,
|  | UParseError * | parseError,
|  | UErrorCode * | status
| ) |  |

Verifies and normalizes short definition string.

Normalized short definition string has all the option sorted by the argument name, so that equivalent definition strings are the same. This API supports preflighting.

Parameters

  source | definition string
  destination | space to hold the resulting string
  capacity | capacity of the buffer
  parseError | if not NULL, structure that will get filled with error's pre and post context in case of error.
  status | Error code. This API will return an error if an invalid attribute or attribute/value combination is specified. All the preflighting errors are also featured

Returns
  length of the resulting normalized string.

See also
  ucol_openFromShortString
  ucol_getShortDefinitionString

Deprecated:
  ICU 54

## ucol_open()

U_CAPI UCollator * ucol_open | ( | const char * | loc,
|  | UErrorCode * | status
| ) |  |

Open a UCollator for comparing strings.

For some languages, multiple collation types are available; for example, "de@collation=phonebook". Starting with ICU 54, collation attributes can be specified via locale keywords as well, in the old locale extension syntax ("el@colCaseFirst=upper") or in language tag syntax ("el-u-kf-upper"). See User Guide: Collation API.

The UCollator pointer is used in all the calls to the Collation service. After finished, collator must be disposed of by calling `ucol_close`.

Parameters

  loc | The locale containing the required collation rules. Special values for locales can be passed in - if NULL is passed for the locale, the default locale collation rules will be used. If empty string ("") or "root" are passed, the root collator will be returned.
  status | A pointer to a UErrorCode to receive any errors

Returns
  A pointer to a UCollator, or 0 if an error occurred.

See also
  ucol_openRules
  ucol_clone
  ucol_close

Stable:
  ICU 2.0

## ucol_openAvailableLocales()

U_CAPI UEnumeration * ucol_openAvailableLocales | ( | UErrorCode * | status | ) |

Create a string enumerator of all locales for which a valid collator may be opened.

Parameters

  status | input-output error code

Returns
  a string enumeration over locale strings. The caller is responsible for closing the result.

Stable:
  ICU 3.0

## ucol_openBinary()

U_CAPI UCollator * ucol_openBinary | ( | const uint8_t * | bin,
|  | int32_t | length,
|  | const UCollator * | base,
|  | UErrorCode * | status
| ) |  |

Opens a collator from a collator binary image created using ucol_cloneBinary.

Binary image used in instantiation of the collator remains owned by the user and should stay around for the lifetime of the collator. The API also takes a base collator which must be the root collator.

Parameters

  bin | binary image owned by the user and required through the lifetime of the collator
  length | size of the image. If negative, the API will try to figure out the length of the image
  base | Base collator, for lookup of untailored characters. Must be the root collator, must not be NULL. The base is required to be present through the lifetime of the collator.
  status | for catching errors

Returns
  newly created collator

See also
  ucol_cloneBinary

Stable:
  ICU 3.2

## ucol_openFromShortString()

UCollator * ucol_openFromShortString | ( | const char * | definition,
|  | UBool | forceDefaults,
|  | UParseError * | parseError,
|  | UErrorCode * | status
| ) |  |

Open a collator defined by a short form string.

The structure and the syntax of the string is defined in the "Naming collators" section of the users guide: https://unicode-org.github.io/icu/userguide/collation/concepts#collator-naming-scheme Attributes are overridden by the subsequent attributes. So, for "S2_S3", final strength will be 3. 3066bis locale overrides individual locale parts. The call to this function is equivalent to a call to ucol_open, followed by a series of calls to ucol_setAttribute and ucol_setVariableTop.

Parameters

  definition | A short string containing a locale and a set of attributes. Attributes not explicitly mentioned are left at the default state for a locale.
  parseError | if not NULL, structure that will get filled with error's pre and post context in case of error.
  forceDefaults | if false, the settings that are the same as the collator default settings will not be applied (for example, setting French secondary on a French collator would not be executed). If true, all the settings will be applied regardless of the collator default value. If the definition strings are to be cached, should be set to false.
  status | Error code. Apart from regular error conditions connected to instantiating collators (like out of memory or similar), this API will return an error if an invalid attribute or attribute/value combination is specified.

Returns
  A pointer to a UCollator or 0 if an error occurred (including an invalid attribute).

See also
  ucol_open
  ucol_setAttribute
  ucol_setVariableTop
  ucol_getShortDefinitionString
  ucol_normalizeShortDefinitionString

Deprecated:
  ICU 54 Use ucol_open() with language tag collation keywords instead.

## ucol_openRules()

U_CAPI UCollator * ucol_openRules | ( | const UChar * | rules,
|  | int32_t | rulesLength,
|  | UColAttributeValue | normalizationMode,
|  | UCollationStrength | strength,
|  | UParseError * | parseError,
|  | UErrorCode * | status
| ) |  |

Produce a UCollator instance according to the rules supplied.

The rules are used to change the default ordering, defined in the UCA in a process called tailoring. The resulting UCollator pointer can be used in the same way as the one obtained by `ucol_open`.

Parameters

  rules | A string describing the collation rules. For the syntax of the rules please see users guide.
  rulesLength | The length of rules, or -1 if null-terminated.
  normalizationMode | The normalization mode: One of UCOL_OFF (expect the text to not need normalization), UCOL_ON (normalize), or UCOL_DEFAULT (set the mode according to the rules)
  strength | The default collation strength; one of UCOL_PRIMARY, UCOL_SECONDARY, UCOL_TERTIARY, UCOL_IDENTICAL,UCOL_DEFAULT_STRENGTH - can be also set in the rules.
  parseError | A pointer to UParseError to receive information about errors occurred during parsing. This argument can currently be set to NULL, but at users own risk. Please provide a real structure.
  status | A pointer to a UErrorCode to receive any errors

Returns
  A pointer to a UCollator. It is not guaranteed that NULL be returned in case of error - please use status argument to check for errors.

See also
  ucol_open
  ucol_clone
  ucol_close

Stable:
  ICU 2.0

## ucol_prepareShortStringOpen()

U_CAPI void ucol_prepareShortStringOpen | ( | const char * | definition,
|  | UBool | forceDefaults,
|  | UParseError * | parseError,
|  | UErrorCode * | status
| ) |  |

Touches all resources needed for instantiating a collator from a short string definition, thus filling up the cache.

Parameters

  definition | A short string containing a locale and a set of attributes. Attributes not explicitly mentioned are left at the default state for a locale.
  parseError | if not NULL, structure that will get filled with error's pre and post context in case of error.
  forceDefaults | if false, the settings that are the same as the collator default settings will not be applied (for example, setting French secondary on a French collator would not be executed). If true, all the settings will be applied regardless of the collator default value. If the definition strings are to be cached, should be set to false.
  status | Error code. Apart from regular error conditions connected to instantiating collators (like out of memory or similar), this API will return an error if an invalid attribute or attribute/value combination is specified.

See also
  ucol_openFromShortString

Internal:
  Do not use. This API is for internal use only. ICU 3.2.1

## ucol_restoreVariableTop()

void ucol_restoreVariableTop | ( | UCollator * | coll,
|  | const uint32_t | varTop,
|  | UErrorCode * | status
| ) |  |

Sets the variable top to the specified primary weight.

Beginning with ICU 53, the variable top is pinned to the top of one of the supported reordering groups, and it must not be beyond the last of those groups. See ucol_setMaxVariable().

Parameters

  coll | collator to be set
  varTop | primary weight, as returned by ucol_setVariableTop or ucol_getVariableTop
  status | error code

See also
  ucol_getVariableTop
  ucol_setVariableTop

Deprecated:
  ICU 53 Call ucol_setMaxVariable() instead.

## ucol_safeClone()

UCollator * ucol_safeClone | ( | const UCollator * | coll,
|  | void * | stackBuffer,
|  | int32_t * | pBufferSize,
|  | UErrorCode * | status
| ) |  |

Thread safe cloning operation.

The result is a clone of a given collator.

Parameters

  coll | collator to be cloned
  stackBuffer | Deprecated functionality as of ICU 52, use NULL. user allocated space for the new clone. If NULL new memory will be allocated. If buffer is not large enough, new memory will be allocated. Clients can use the U_COL_SAFECLONE_BUFFERSIZE.
  pBufferSize | Deprecated functionality as of ICU 52, use NULL or 1. pointer to size of allocated space. If *pBufferSize == 0, a sufficient size for use in cloning will be returned ('pre-flighting') If *pBufferSize is not enough for a stack-based safe clone, new memory will be allocated.
  status | to indicate whether the operation went on smoothly or there were errors An informational status value, U_SAFECLONE_ALLOCATED_ERROR, is used if pBufferSize != NULL and any allocations were necessary

Returns
  pointer to the new clone

See also
  ucol_open
  ucol_openRules
  ucol_close

Deprecated:
  ICU 71 Use ucol_clone() instead.

## ucol_setAttribute()

U_CAPI void ucol_setAttribute | ( | UCollator * | coll,
|  | UColAttribute | attr,
|  | UColAttributeValue | value,
|  | UErrorCode * | status
| ) |  |

Universal attribute setter.

Parameters

  coll | collator which attributes are to be changed
  attr | attribute type
  value | attribute value
  status | to indicate whether the operation went on smoothly or there were errors

See also
  UColAttribute
  UColAttributeValue
  ucol_getAttribute

Stable:
  ICU 2.0

## ucol_setMaxVariable()

U_CAPI void ucol_setMaxVariable | ( | UCollator * | coll,
|  | UColReorderCode | group,
|  | UErrorCode * | pErrorCode
| ) |  |

Sets the variable top to the top of the specified reordering group.

The variable top determines the highest-sorting character which is affected by UCOL_ALTERNATE_HANDLING. If that attribute is set to UCOL_NON_IGNORABLE, then the variable top has no effect.

Parameters

  coll | the collator
  group | one of UCOL_REORDER_CODE_SPACE, UCOL_REORDER_CODE_PUNCTUATION, UCOL_REORDER_CODE_SYMBOL, UCOL_REORDER_CODE_CURRENCY; or UCOL_REORDER_CODE_DEFAULT to restore the default max variable group
  pErrorCode | Standard ICU error code. Its input value must pass the U_SUCCESS() test, or else the function returns immediately. Check for U_FAILURE() on output or use with function chaining. (See User Guide for details.)

See also
  ucol_getMaxVariable

Stable:
  ICU 53

## ucol_setReorderCodes()

U_CAPI void ucol_setReorderCodes | ( | UCollator * | coll,
|  | const int32_t * | reorderCodes,
|  | int32_t | reorderCodesLength,
|  | UErrorCode * | pErrorCode
| ) |  |

Sets the reordering codes for this collator.

Collation reordering allows scripts and some other groups of characters to be moved relative to each other. This reordering is done on top of the DUCET/CLDR standard collation order. Reordering can specify groups to be placed at the start and/or the end of the collation order. These groups are specified using UScript codes and UColReorderCode entries.

By default, reordering codes specified for the start of the order are placed in the order given after several special non-script blocks. These special groups of characters are space, punctuation, symbol, currency, and digit. These special groups are represented with UColReorderCode entries. Script groups can be intermingled with these special non-script groups if those special groups are explicitly specified in the reordering.

The special code OTHERS stands for any script that is not explicitly mentioned in the list of reordering codes given. Anything that is after OTHERS will go at the very end of the reordering in the order given.

The special reorder code DEFAULT will reset the reordering for this collator to the default for this collator. The default reordering may be the DUCET/CLDR order or may be a reordering that was specified when this collator was created from resource data or from rules. The DEFAULT code must be the sole code supplied when it is used. If not, then U_ILLEGAL_ARGUMENT_ERROR will be set.

The special reorder code NONE will remove any reordering for this collator. The result of setting no reordering will be to have the DUCET/CLDR ordering used. The NONE code must be the sole code supplied when it is used.

Parameters

  coll | The UCollator to set.
  reorderCodes | An array of script codes in the new order. This can be NULL if the length is also set to 0. An empty array will clear any reordering codes on the collator.
  reorderCodesLength | The length of reorderCodes.
  pErrorCode | Must be a valid pointer to an error code value, which must not indicate a failure before the function call.

See also
  ucol_getReorderCodes
  ucol_getEquivalentReorderCodes
  UScriptCode
  UColReorderCode

Stable:
  ICU 4.8

## ucol_setStrength()

U_CAPI void ucol_setStrength | ( | UCollator * | coll,
|  | UCollationStrength | strength
| ) |  |

Set the collation strength used in a UCollator.

The strength influences how strings are compared.

Parameters

  coll | The UCollator to set.
  strength | The desired collation strength; one of UCOL_PRIMARY, UCOL_SECONDARY, UCOL_TERTIARY, UCOL_QUATERNARY, UCOL_IDENTICAL, UCOL_DEFAULT

See also
  ucol_getStrength

Stable:
  ICU 2.0

## ucol_setVariableTop()

uint32_t ucol_setVariableTop | ( | UCollator * | coll,
|  | const UChar * | varTop,
|  | int32_t | len,
|  | UErrorCode * | status
| ) |  |

Sets the variable top to the primary weight of the specified string.

Beginning with ICU 53, the variable top is pinned to the top of one of the supported reordering groups, and it must not be beyond the last of those groups. See ucol_setMaxVariable().

Parameters

  coll | the collator
  varTop | one or more (if contraction) UChars to which the variable top should be set
  len | length of variable top string. If -1 it is considered to be zero terminated.
  status | error code. If error code is set, the return value is undefined. Errors set by this function are: U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond the last reordering group supported by ucol_setMaxVariable()

Returns
  variable top primary weight

See also
  ucol_getVariableTop
  ucol_restoreVariableTop

Deprecated:
  ICU 53 Call ucol_setMaxVariable() instead.

## ucol_strcoll()

U_CAPI UCollationResult ucol_strcoll | ( | const UCollator * | coll,
|  | const UChar * | source,
|  | int32_t | sourceLength,
|  | const UChar * | target,
|  | int32_t | targetLength
| ) |  |

Compare two strings.

The strings will be compared using the options already specified.

Parameters

  coll | The UCollator containing the comparison rules.
  source | The source string.
  sourceLength | The length of source, or -1 if null-terminated.
  target | The target string.
  targetLength | The length of target, or -1 if null-terminated.

Returns
  The result of comparing the strings; one of UCOL_EQUAL, UCOL_GREATER, UCOL_LESS

See also
  ucol_greater
  ucol_greaterOrEqual
  ucol_equal

Stable:
  ICU 2.0

## ucol_strcollIter()

U_CAPI UCollationResult ucol_strcollIter | ( | const UCollator * | coll,
|  | UCharIterator * | sIter,
|  | UCharIterator * | tIter,
|  | UErrorCode * | status
| ) |  |

Compare two UTF-8 encoded strings.

The strings will be compared using the options already specified.

Parameters

  coll | The UCollator containing the comparison rules.
  sIter | The source string iterator.
  tIter | The target string iterator.

Returns
  The result of comparing the strings; one of UCOL_EQUAL, UCOL_GREATER, UCOL_LESS

Parameters

  status | A pointer to a UErrorCode to receive any errors

See also
  ucol_strcoll

Stable:
  ICU 2.6

## ucol_strcollUTF8()

U_CAPI UCollationResult ucol_strcollUTF8 | ( | const UCollator * | coll,
|  | const char * | source,
|  | int32_t | sourceLength,
|  | const char * | target,
|  | int32_t | targetLength,
|  | UErrorCode * | status
| ) |  |

Compare two strings in UTF-8.

The strings will be compared using the options already specified. Note: When input string contains malformed a UTF-8 byte sequence, this function treats these bytes as REPLACEMENT CHARACTER (U+FFFD).

Parameters

  coll | The UCollator containing the comparison rules.
  source | The source UTF-8 string.
  sourceLength | The length of source, or -1 if null-terminated.
  target | The target UTF-8 string.
  targetLength | The length of target, or -1 if null-terminated.
  status | A pointer to a UErrorCode to receive any errors

Returns
  The result of comparing the strings; one of UCOL_EQUAL, UCOL_GREATER, UCOL_LESS

See also
  ucol_greater
  ucol_greaterOrEqual
  ucol_equal

Stable:
  ICU 50