diff options
Diffstat (limited to 'Source/JavaScriptCore/icu/unicode/ucol.h')
-rw-r--r-- | Source/JavaScriptCore/icu/unicode/ucol.h | 358 |
1 files changed, 282 insertions, 76 deletions
diff --git a/Source/JavaScriptCore/icu/unicode/ucol.h b/Source/JavaScriptCore/icu/unicode/ucol.h index 4a4cd606e..5a459b52a 100644 --- a/Source/JavaScriptCore/icu/unicode/ucol.h +++ b/Source/JavaScriptCore/icu/unicode/ucol.h @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (c) 1996-2010, International Business Machines Corporation and others. +* Copyright (c) 1996-2013, International Business Machines Corporation and others. * All Rights Reserved. ******************************************************************************* */ @@ -17,6 +17,7 @@ #include "unicode/parseerr.h" #include "unicode/uloc.h" #include "unicode/uset.h" +#include "unicode/uscript.h" /** * \file @@ -63,12 +64,12 @@ typedef struct UCollator UCollator; /** * UCOL_LESS is returned if source string is compared to be less than target - * string in the u_strcoll() method. + * string in the ucol_strcoll() method. * UCOL_EQUAL is returned if source string is compared to be equal to target - * string in the u_strcoll() method. + * string in the ucol_strcoll() method. * UCOL_GREATER is returned if source string is compared to be greater than - * target string in the u_strcoll() method. - * @see u_strcoll() + * target string in the ucol_strcoll() method. + * @see ucol_strcoll() * <p> * Possible values for a comparison result * @stable ICU 2.0 @@ -132,18 +133,76 @@ typedef enum { } UColAttributeValue; -/** 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. - * @internal +/** + * 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 ucol_getReorderCodes + * @see ucol_setReorderCodes + * @see ucol_getEquivalentReorderCodes + * @see UScriptCode + * @stable ICU 4.8 */ -typedef enum { - 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 + typedef enum { + /** + * A special reordering code that is used to specify the default + * reordering codes for a locale. + * @stable ICU 4.8 + */ + UCOL_REORDER_CODE_DEFAULT = -1, + /** + * A special reordering code that is used to specify no reordering codes. + * @stable ICU 4.8 + */ + UCOL_REORDER_CODE_NONE = USCRIPT_UNKNOWN, + /** + * 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_OTHERS = USCRIPT_UNKNOWN, + /** + * Characters with the space property. + * This is equivalent to the rule value "space". + * @stable ICU 4.8 + */ + UCOL_REORDER_CODE_SPACE = 0x1000, + /** + * 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_FIRST = UCOL_REORDER_CODE_SPACE, + /** + * Characters with the punctuation property. + * This is equivalent to the rule value "punct". + * @stable ICU 4.8 + */ + UCOL_REORDER_CODE_PUNCTUATION = 0x1001, + /** + * Characters with the symbol property. + * This is equivalent to the rule value "symbol". + * @stable ICU 4.8 + */ + UCOL_REORDER_CODE_SYMBOL = 0x1002, + /** + * Characters with the currency property. + * This is equivalent to the rule value "currency". + * @stable ICU 4.8 + */ + UCOL_REORDER_CODE_CURRENCY = 0x1003, + /** + * Characters with the digit property. + * This is equivalent to the rule value "digit". + * @stable ICU 4.8 + */ + UCOL_REORDER_CODE_DIGIT = 0x1004, + /** + * The limit of the reorder codes. This is intended for use in range checking + * and enumeration of the reorder codes. + * @stable ICU 4.8 + */ + UCOL_REORDER_CODE_LIMIT = 0x1005 } UColReorderCode; /** @@ -179,10 +238,12 @@ typedef UColAttributeValue UCollationStrength; * @stable ICU 2.0 */ typedef enum { - /** Attribute for direction of secondary weights - used in French. + /** 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.*/ + * weights in the order they appear. + * @stable ICU 2.0 + */ UCOL_FRENCH_COLLATION, /** Attribute for handling variable elements. * Acceptable values are UCOL_NON_IGNORABLE (default) @@ -191,14 +252,18 @@ typedef enum { * 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.*/ + * level. + * @stable ICU 2.0 + */ UCOL_ALTERNATE_HANDLING, /** Controls the ordering of upper and lower case letters. * Acceptable values are UCOL_OFF (default), 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 opposite. + * @stable ICU 2.0 + */ UCOL_CASE_FIRST, /** Controls whether an extra case level (positioned before the third * level) is generated or not. Acceptable values are UCOL_OFF (default), @@ -206,7 +271,9 @@ typedef enum { * 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. */ + * and enable case level. + * @stable ICU 2.0 + */ UCOL_CASE_LEVEL, /** Controls whether the normalization check and necessary normalizations * are performed. When set to UCOL_OFF (default) no normalization check @@ -214,9 +281,13 @@ typedef enum { * 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. */ + * incremental NFD normalization is performed. + * @stable ICU 2.0 + */ UCOL_NORMALIZATION_MODE, - /** An alias for UCOL_NORMALIZATION_MODE attribute */ + /** An alias for UCOL_NORMALIZATION_MODE attribute. + * @stable ICU 2.0 + */ UCOL_DECOMPOSITION_MODE = UCOL_NORMALIZATION_MODE, /** The strength attribute. Can be either UCOL_PRIMARY, UCOL_SECONDARY, * UCOL_TERTIARY, UCOL_QUATERNARY or UCOL_IDENTICAL. The usual strength @@ -227,20 +298,37 @@ typedef enum { * UCOL_HIRAGANA_QUATERNARY mode to on. 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. */ + * to codepoints of the NFD form of the string. + * @stable ICU 2.0 + */ UCOL_STRENGTH, +#ifndef U_HIDE_DEPRECATED_API /** When turned on, this attribute positions Hiragana before all * non-ignorables on quaternary level This is a sneaky way to produce JIS - * sort order */ - UCOL_HIRAGANA_QUATERNARY_MODE, + * sort order. + * + * This attribute is an implementation detail of the CLDR Japanese tailoring. + * The implementation might change to use a different mechanism + * to achieve the same Japanese sort order. + * Since ICU 50, this attribute is not settable any more via API functions. + * @deprecated ICU 50 Implementation detail, cannot be set via API, might be removed from implementation. + */ + UCOL_HIRAGANA_QUATERNARY_MODE = UCOL_STRENGTH + 1, +#endif /* U_HIDE_DEPRECATED_API */ /** When turned on, this attribute generates a collation key * for the numeric value of substrings of digits. * This is a way to get '100' to sort AFTER '2'. Note that the longest * digit substring that can be treated as a single collation element 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 associated with a separate collation element. */ - UCOL_NUMERIC_COLLATION, + * separate digit substring associated with a separate collation element. + * @stable ICU 2.8 + */ + UCOL_NUMERIC_COLLATION = UCOL_STRENGTH + 2, + /** + * The number of UColAttribute constants. + * @stable ICU 2.0 + */ UCOL_ATTRIBUTE_COUNT } UColAttribute; @@ -248,9 +336,19 @@ typedef enum { * @stable ICU 2.0 */ typedef enum { - /** Retrieve tailoring only */ + /** + * Retrieves the tailoring rules only. + * Same as calling the version of getRules() without UColRuleOption. + * @stable ICU 2.0 + */ UCOL_TAILORING_ONLY, - /** Retrieve UCA rules and tailoring */ + /** + * Retrieves the "UCA rules" concatenated with the tailoring rules. + * The "UCA rules" are an <i>approximation</i> of the root collator's sort order. + * They are almost never used or useful at runtime and can be removed from the data. + * See http://userguide.icu-project.org/collation/customization#TOC-Building-on-Existing-Locales + * @stable ICU 2.0 + */ UCOL_FULL_RULES } UColRuleOption ; @@ -347,6 +445,7 @@ ucol_openFromShortString( const char *definition, UParseError *parseError, UErrorCode *status); +#ifndef U_HIDE_DEPRECATED_API /** * Get a set containing the contractions defined by the collator. The set includes * both the UCA contractions and the contractions defined by the collator. This set @@ -364,6 +463,7 @@ U_DEPRECATED int32_t U_EXPORT2 ucol_getContractions( const UCollator *coll, USet *conts, UErrorCode *status); +#endif /* U_HIDE_DEPRECATED_API */ /** * Get a set containing the expansions defined by the collator. The set includes @@ -435,6 +535,33 @@ ucol_strcoll( const UCollator *coll, const UChar *target, int32_t targetLength); +/** +* 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). +* @param coll The UCollator containing the comparison rules. +* @param source The source UTF-8 string. +* @param sourceLength The length of source, or -1 if null-terminated. +* @param target The target UTF-8 string. +* @param targetLength The length of target, or -1 if null-terminated. +* @param status A pointer to an UErrorCode to receive any errors +* @return The result of comparing the strings; one of UCOL_EQUAL, +* UCOL_GREATER, UCOL_LESS +* @see ucol_greater +* @see ucol_greaterOrEqual +* @see ucol_equal +* @stable ICU 50 +*/ +U_STABLE UCollationResult U_EXPORT2 +ucol_strcollUTF8( + const UCollator *coll, + const char *source, + int32_t sourceLength, + const char *target, + int32_t targetLength, + UErrorCode *status); + /** * Determine if one string is greater than another. * This function is equivalent to {@link #ucol_strcoll } == UCOL_GREATER @@ -536,37 +663,90 @@ ucol_setStrength(UCollator *coll, UCollationStrength strength); /** - * Get the current reordering of scripts (if one has been set). + * Retrieves the reordering codes for this collator. + * These reordering codes are a combination of UScript codes and UColReorderCode entries. * @param coll The UCollator to query. * @param dest The array to fill with the script ordering. - * @param 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 of the result string (pre-flighting). - * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate a failure before the function call. - * @return The length of the array of the script ordering. + * @param 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 of the result string (pre-flighting). + * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate a + * failure before the function call. + * @return The number of reordering codes written to the dest array. * @see ucol_setReorderCodes - * @internal + * @see ucol_getEquivalentReorderCodes + * @see UScriptCode + * @see UColReorderCode + * @stable ICU 4.8 */ -U_INTERNAL int32_t U_EXPORT2 +U_STABLE int32_t U_EXPORT2 ucol_getReorderCodes(const UCollator* coll, int32_t* dest, int32_t destCapacity, UErrorCode *pErrorCode); - -/** - * Set the ordering of scripts for this collator. +/** + * Sets the reordering codes for this collator. + * Collation reordering allows scripts and some other defined blocks of characters + * to be moved relative to each other as a block. 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. + * <p>By default, reordering codes specified for the start of the order are placed in the + * order given after a group of "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 blocks if those special blocks are explicitly specified in the reordering. + * <p>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. + * <p>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 <b>must</b> be the sole code supplied when it used. If not + * that will result in an U_ILLEGAL_ARGUMENT_ERROR being set. + * <p>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 <b>must</b> be the sole code supplied when it used. * @param coll The UCollator to set. - * @param reorderCodes An array of script codes in the new order. + * @param 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. * @param reorderCodesLength The length of reorderCodes. - * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate a failure before the function call. + * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate a + * failure before the function call. * @see ucol_getReorderCodes - * @internal - */ -U_INTERNAL void U_EXPORT2 + * @see ucol_getEquivalentReorderCodes + * @see UScriptCode + * @see UColReorderCode + * @stable ICU 4.8 + */ +U_STABLE void U_EXPORT2 ucol_setReorderCodes(UCollator* coll, const int32_t* reorderCodes, int32_t reorderCodesLength, UErrorCode *pErrorCode); /** + * Retrieves the reorder codes that are grouped with the given reorder code. Some reorder + * codes will be grouped and must reorder together. + * @param reorderCode The reorder code to determine equivalence for. + * @param dest The array to fill with the script ordering. + * @param 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 of the result string (pre-flighting). + * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate + * a failure before the function call. + * @return The number of reordering codes written to the dest array. + * @see ucol_setReorderCodes + * @see ucol_getReorderCodes + * @see UScriptCode + * @see UColReorderCode + * @stable ICU 4.8 + */ +U_STABLE int32_t U_EXPORT2 +ucol_getEquivalentReorderCodes(int32_t reorderCode, + int32_t* dest, + int32_t destCapacity, + UErrorCode *pErrorCode); + +/** * Get the display name for a UCollator. * The display name is suitable for presentation to a user. * @param objLoc The locale of the collator in question. @@ -705,11 +885,11 @@ ucol_getFunctionalEquivalent(char* result, int32_t resultCapacity, UBool* isAvailable, UErrorCode* status); /** - * Get the collation rules from a UCollator. + * Get the collation tailoring rules from a UCollator. * The rules will follow the rule syntax. * @param coll The UCollator to query. * @param length - * @return The collation rules. + * @return The collation tailoring rules. * @stable ICU 2.0 */ U_STABLE const UChar* U_EXPORT2 @@ -802,10 +982,10 @@ ucol_getSortKey(const UCollator *coll, * 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. Generated sortkey is not - * compatible with sortkeys generated using ucol_getSortKey - * API, since we don't do any compression. If uncompressed - * sortkeys are required, this API can be used. + * the number of requested bytes. + * + * The generated sort key may or may not be compatible with + * sort keys generated using ucol_getSortKey(). * @param coll The UCollator containing the collation rules. * @param iter UCharIterator containing the string we need * the sort key to be calculated for. @@ -909,26 +1089,40 @@ ucol_getVersion(const UCollator* coll, UVersionInfo info); U_STABLE void U_EXPORT2 ucol_getUCAVersion(const UCollator* coll, UVersionInfo info); -/** - * Merge two sort keys. The levels are merged with their corresponding counterparts +/** + * 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. - * example (uncompressed): - * 191B1D 01 050505 01 910505 00 and 1F2123 01 050505 01 910505 00 + * + * This is useful, for example, for combining sort keys from first and last names + * to sort such pairs. + * 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): + * <pre>191B1D 01 050505 01 910505 00 + * 1F2123 01 050505 01 910505 00</pre> * will be merged as - * 191B1D 02 1F212301 050505 02 050505 01 910505 02 910505 00 - * This allows for concatenating of first and last names for sorting, among other things. - * If the destination buffer is not big enough, the results are undefined. - * If any of source lengths are zero or any of source pointers are NULL/undefined, - * result is of size zero. - * @param src1 pointer to the first sortkey - * @param src1Length length of the first sortkey - * @param src2 pointer to the second sortkey - * @param src2Length length of the second sortkey - * @param dest buffer to hold the result - * @param destCapacity size of the buffer for the result - * @return size of the result. If the buffer is big enough size is always - * src1Length+src2Length-1 + * <pre>191B1D 02 1F2123 01 050505 02 050505 01 910505 02 910505 00</pre> + * + * 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. + * + * @param src1 the first sort key + * @param 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 + * @param src2 the second sort key + * @param 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 + * @param dest the buffer where the merged sort key is written, + * can be NULL if destCapacity==0 + * @param destCapacity the number of bytes in the dest buffer + * @return 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 */ U_STABLE int32_t U_EXPORT2 @@ -1018,12 +1212,13 @@ ucol_restoreVariableTop(UCollator *coll, const uint32_t varTop, UErrorCode *stat /** * Thread safe cloning operation. The result is a clone of a given collator. * @param coll collator to be cloned - * @param stackBuffer user allocated space for the new clone. + * @param stackBuffer <em>Deprecated functionality as of ICU 52, use NULL.</em><br> + * 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. - * This will probably be enough to avoid memory allocations. - * @param pBufferSize pointer to size of allocated space. + * Clients can use the U_COL_SAFECLONE_BUFFERSIZE. + * @param pBufferSize <em>Deprecated functionality as of ICU 52, use NULL or 1.</em><br> + * 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, @@ -1043,25 +1238,34 @@ ucol_safeClone(const UCollator *coll, int32_t *pBufferSize, UErrorCode *status); -/** default memory size for the new clone. It needs to be this large for os/400 large pointers - * @stable ICU 2.0 +#ifndef U_HIDE_DEPRECATED_API + +/** default memory size for the new clone. + * @deprecated ICU 52. Do not rely on ucol_safeClone() cloning into any provided buffer. */ -#define U_COL_SAFECLONE_BUFFERSIZE 512 +#define U_COL_SAFECLONE_BUFFERSIZE 1 + +#endif /* U_HIDE_DEPRECATED_API */ /** * 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 http://userguide.icu-project.org/collation/customization#TOC-Building-on-Existing-Locales * @param coll collator to get the rules from * @param delta one of UCOL_TAILORING_ONLY, UCOL_FULL_RULES. * @param buffer buffer to store the result in. If NULL, you'll get no rules. - * @param bufferLen lenght of buffer to store rules in. If less then needed you'll get only the part that fits in. + * @param bufferLen length of buffer to store rules in. If less than needed you'll get only the part that fits in. * @return current rules * @stable ICU 2.0 + * @see UCOL_FULL_RULES */ U_STABLE int32_t U_EXPORT2 ucol_getRulesEx(const UCollator *coll, UColRuleOption delta, UChar *buffer, int32_t bufferLen); +#ifndef U_HIDE_DEPRECATED_API /** * gets the locale name of the collator. If the collator * is instantiated from the rules, then this function returns @@ -1078,7 +1282,7 @@ ucol_getRulesEx(const UCollator *coll, UColRuleOption delta, UChar *buffer, int3 */ U_DEPRECATED const char * U_EXPORT2 ucol_getLocale(const UCollator *coll, ULocDataLocaleType type, UErrorCode *status); - +#endif /* U_HIDE_DEPRECATED_API */ /** * gets the locale name of the collator. If the collator @@ -1110,6 +1314,7 @@ ucol_getLocaleByType(const UCollator *coll, ULocDataLocaleType type, UErrorCode U_STABLE USet * U_EXPORT2 ucol_getTailoredSet(const UCollator *coll, UErrorCode *status); +#ifndef U_HIDE_INTERNAL_API /** * Universal attribute getter that returns UCOL_DEFAULT if the value is default * @param coll collator which attributes are to be changed @@ -1182,6 +1387,7 @@ ucol_prepareShortStringOpen( const char *definition, UBool forceDefaults, UParseError *parseError, UErrorCode *status); +#endif /* U_HIDE_INTERNAL_API */ /** Creates a binary image of a collator. This binary image can be stored and * later used to instantiate a collator using ucol_openBinary. |