| 1 |
// © 2016 and later: Unicode, Inc. and others. |
| 2 |
// License & terms of use: http://www.unicode.org/copyright.html |
| 3 |
/* |
| 4 |
******************************************************************************* |
| 5 |
* Copyright (C) 2001-2014, International Business Machines |
| 6 |
* Corporation and others. All Rights Reserved. |
| 7 |
******************************************************************************* |
| 8 |
* |
| 9 |
* File ucoleitr.h |
| 10 |
* |
| 11 |
* Modification History: |
| 12 |
* |
| 13 |
* Date Name Description |
| 14 |
* 02/15/2001 synwee Modified all methods to process its own function |
| 15 |
* instead of calling the equivalent c++ api (coleitr.h) |
| 16 |
*******************************************************************************/ |
| 17 |
|
| 18 |
#ifndef UCOLEITR_H |
| 19 |
#define UCOLEITR_H |
| 20 |
|
| 21 |
#include "unicode/utypes.h" |
| 22 |
|
| 23 |
#if !UCONFIG_NO_COLLATION |
| 24 |
|
| 25 |
/** |
| 26 |
* This indicates an error has occurred during processing or if no more CEs is |
| 27 |
* to be returned. |
| 28 |
* @stable ICU 2.0 |
| 29 |
*/ |
| 30 |
#define UCOL_NULLORDER ((int32_t)0xFFFFFFFF) |
| 31 |
|
| 32 |
#include "unicode/ucol.h" |
| 33 |
|
| 34 |
/** |
| 35 |
* The UCollationElements struct. |
| 36 |
* For usage in C programs. |
| 37 |
* @stable ICU 2.0 |
| 38 |
*/ |
| 39 |
typedef struct UCollationElements UCollationElements; |
| 40 |
|
| 41 |
/** |
| 42 |
* \file |
| 43 |
* \brief C API: UCollationElements |
| 44 |
* |
| 45 |
* The UCollationElements API is used as an iterator to walk through each |
| 46 |
* character of an international string. Use the iterator to return the |
| 47 |
* ordering priority of the positioned character. The ordering priority of a |
| 48 |
* character, which we refer to as a key, defines how a character is collated |
| 49 |
* in the given collation object. |
| 50 |
* For example, consider the following in Slovak and in traditional Spanish collation: |
| 51 |
* <pre> |
| 52 |
* . "ca" -> the first key is key('c') and second key is key('a'). |
| 53 |
* . "cha" -> the first key is key('ch') and second key is key('a'). |
| 54 |
* </pre> |
| 55 |
* And in German phonebook collation, |
| 56 |
* <pre> |
| 57 |
* . "<ae ligature>b"-> the first key is key('a'), the second key is key('e'), and |
| 58 |
* . the third key is key('b'). |
| 59 |
* </pre> |
| 60 |
* <p>Example of the iterator usage: (without error checking) |
| 61 |
* <pre> |
| 62 |
* . void CollationElementIterator_Example() |
| 63 |
* . { |
| 64 |
* . UChar *s; |
| 65 |
* . t_int32 order, primaryOrder; |
| 66 |
* . UCollationElements *c; |
| 67 |
* . UCollatorOld *coll; |
| 68 |
* . UErrorCode success = U_ZERO_ERROR; |
| 69 |
* . str=(UChar*)malloc(sizeof(UChar) * (strlen("This is a test")+1) ); |
| 70 |
* . u_uastrcpy(str, "This is a test"); |
| 71 |
* . coll = ucol_open(NULL, &success); |
| 72 |
* . c = ucol_openElements(coll, str, u_strlen(str), &status); |
| 73 |
* . order = ucol_next(c, &success); |
| 74 |
* . ucol_reset(c); |
| 75 |
* . order = ucol_prev(c, &success); |
| 76 |
* . free(str); |
| 77 |
* . ucol_close(coll); |
| 78 |
* . ucol_closeElements(c); |
| 79 |
* . } |
| 80 |
* </pre> |
| 81 |
* <p> |
| 82 |
* ucol_next() returns the collation order of the next. |
| 83 |
* ucol_prev() returns the collation order of the previous character. |
| 84 |
* The Collation Element Iterator moves only in one direction between calls to |
| 85 |
* ucol_reset. That is, ucol_next() and ucol_prev can not be inter-used. |
| 86 |
* Whenever ucol_prev is to be called after ucol_next() or vice versa, |
| 87 |
* ucol_reset has to be called first to reset the status, shifting pointers to |
| 88 |
* either the end or the start of the string. Hence at the next call of |
| 89 |
* ucol_prev or ucol_next, the first or last collation order will be returned. |
| 90 |
* If a change of direction is done without a ucol_reset, the result is |
| 91 |
* undefined. |
| 92 |
* The result of a forward iterate (ucol_next) and reversed result of the |
| 93 |
* backward iterate (ucol_prev) on the same string are equivalent, if |
| 94 |
* collation orders with the value 0 are ignored. |
| 95 |
* Character based on the comparison level of the collator. A collation order |
| 96 |
* consists of primary order, secondary order and tertiary order. The data |
| 97 |
* type of the collation order is <strong>int32_t</strong>. |
| 98 |
* |
| 99 |
* @see UCollator |
| 100 |
*/ |
| 101 |
|
| 102 |
/** |
| 103 |
* Open the collation elements for a string. |
| 104 |
* |
| 105 |
* The UCollationElements retains a pointer to the supplied text. |
| 106 |
* The caller must not modify or delete the text while the UCollationElements |
| 107 |
* object is used to iterate over this text. |
| 108 |
* |
| 109 |
* @param coll The collator containing the desired collation rules. |
| 110 |
* @param text The text to iterate over. |
| 111 |
* @param textLength The number of characters in text, or -1 if null-terminated |
| 112 |
* @param status A pointer to a UErrorCode to receive any errors. |
| 113 |
* @return a struct containing collation element information |
| 114 |
* @stable ICU 2.0 |
| 115 |
*/ |
| 116 |
U_CAPI UCollationElements* U_EXPORT2 |
| 117 |
ucol_openElements(const UCollator *coll, |
| 118 |
const UChar *text, |
| 119 |
int32_t textLength, |
| 120 |
UErrorCode *status); |
| 121 |
|
| 122 |
/** |
| 123 |
* get a hash code for a key... Not very useful! |
| 124 |
* @param key the given key. |
| 125 |
* @param length the size of the key array. |
| 126 |
* @return the hash code. |
| 127 |
* @stable ICU 2.0 |
| 128 |
*/ |
| 129 |
U_CAPI int32_t U_EXPORT2 |
| 130 |
ucol_keyHashCode(const uint8_t* key, int32_t length); |
| 131 |
|
| 132 |
/** |
| 133 |
* Close a UCollationElements. |
| 134 |
* Once closed, a UCollationElements may no longer be used. |
| 135 |
* @param elems The UCollationElements to close. |
| 136 |
* @stable ICU 2.0 |
| 137 |
*/ |
| 138 |
U_CAPI void U_EXPORT2 |
| 139 |
ucol_closeElements(UCollationElements *elems); |
| 140 |
|
| 141 |
/** |
| 142 |
* Reset the collation elements to their initial state. |
| 143 |
* This will move the 'cursor' to the beginning of the text. |
| 144 |
* Property settings for collation will be reset to the current status. |
| 145 |
* @param elems The UCollationElements to reset. |
| 146 |
* @see ucol_next |
| 147 |
* @see ucol_previous |
| 148 |
* @stable ICU 2.0 |
| 149 |
*/ |
| 150 |
U_CAPI void U_EXPORT2 |
| 151 |
ucol_reset(UCollationElements *elems); |
| 152 |
|
| 153 |
/** |
| 154 |
* Get the ordering priority of the next collation element in the text. |
| 155 |
* A single character may contain more than one collation element. |
| 156 |
* @param elems The UCollationElements containing the text. |
| 157 |
* @param status A pointer to a UErrorCode to receive any errors. |
| 158 |
* @return The next collation elements ordering, otherwise returns UCOL_NULLORDER |
| 159 |
* if an error has occurred or if the end of string has been reached |
| 160 |
* @stable ICU 2.0 |
| 161 |
*/ |
| 162 |
U_CAPI int32_t U_EXPORT2 |
| 163 |
ucol_next(UCollationElements *elems, UErrorCode *status); |
| 164 |
|
| 165 |
/** |
| 166 |
* Get the ordering priority of the previous collation element in the text. |
| 167 |
* A single character may contain more than one collation element. |
| 168 |
* Note that internally a stack is used to store buffered collation elements. |
| 169 |
* @param elems The UCollationElements containing the text. |
| 170 |
* @param status A pointer to a UErrorCode to receive any errors. Notably |
| 171 |
* a U_BUFFER_OVERFLOW_ERROR is returned if the internal stack |
| 172 |
* buffer has been exhausted. |
| 173 |
* @return The previous collation elements ordering, otherwise returns |
| 174 |
* UCOL_NULLORDER if an error has occurred or if the start of string has |
| 175 |
* been reached. |
| 176 |
* @stable ICU 2.0 |
| 177 |
*/ |
| 178 |
U_CAPI int32_t U_EXPORT2 |
| 179 |
ucol_previous(UCollationElements *elems, UErrorCode *status); |
| 180 |
|
| 181 |
/** |
| 182 |
* Get the maximum length of any expansion sequences that end with the |
| 183 |
* specified comparison order. |
| 184 |
* This is useful for .... ? |
| 185 |
* @param elems The UCollationElements containing the text. |
| 186 |
* @param order A collation order returned by previous or next. |
| 187 |
* @return maximum size of the expansion sequences ending with the collation |
| 188 |
* element or 1 if collation element does not occur at the end of any |
| 189 |
* expansion sequence |
| 190 |
* @stable ICU 2.0 |
| 191 |
*/ |
| 192 |
U_CAPI int32_t U_EXPORT2 |
| 193 |
ucol_getMaxExpansion(const UCollationElements *elems, int32_t order); |
| 194 |
|
| 195 |
/** |
| 196 |
* Set the text containing the collation elements. |
| 197 |
* Property settings for collation will remain the same. |
| 198 |
* In order to reset the iterator to the current collation property settings, |
| 199 |
* the API reset() has to be called. |
| 200 |
* |
| 201 |
* The UCollationElements retains a pointer to the supplied text. |
| 202 |
* The caller must not modify or delete the text while the UCollationElements |
| 203 |
* object is used to iterate over this text. |
| 204 |
* |
| 205 |
* @param elems The UCollationElements to set. |
| 206 |
* @param text The source text containing the collation elements. |
| 207 |
* @param textLength The length of text, or -1 if null-terminated. |
| 208 |
* @param status A pointer to a UErrorCode to receive any errors. |
| 209 |
* @see ucol_getText |
| 210 |
* @stable ICU 2.0 |
| 211 |
*/ |
| 212 |
U_CAPI void U_EXPORT2 |
| 213 |
ucol_setText( UCollationElements *elems, |
| 214 |
const UChar *text, |
| 215 |
int32_t textLength, |
| 216 |
UErrorCode *status); |
| 217 |
|
| 218 |
/** |
| 219 |
* Get the offset of the current source character. |
| 220 |
* This is an offset into the text of the character containing the current |
| 221 |
* collation elements. |
| 222 |
* @param elems The UCollationElements to query. |
| 223 |
* @return The offset of the current source character. |
| 224 |
* @see ucol_setOffset |
| 225 |
* @stable ICU 2.0 |
| 226 |
*/ |
| 227 |
U_CAPI int32_t U_EXPORT2 |
| 228 |
ucol_getOffset(const UCollationElements *elems); |
| 229 |
|
| 230 |
/** |
| 231 |
* Set the offset of the current source character. |
| 232 |
* This is an offset into the text of the character to be processed. |
| 233 |
* Property settings for collation will remain the same. |
| 234 |
* In order to reset the iterator to the current collation property settings, |
| 235 |
* the API reset() has to be called. |
| 236 |
* @param elems The UCollationElements to set. |
| 237 |
* @param offset The desired character offset. |
| 238 |
* @param status A pointer to a UErrorCode to receive any errors. |
| 239 |
* @see ucol_getOffset |
| 240 |
* @stable ICU 2.0 |
| 241 |
*/ |
| 242 |
U_CAPI void U_EXPORT2 |
| 243 |
ucol_setOffset(UCollationElements *elems, |
| 244 |
int32_t offset, |
| 245 |
UErrorCode *status); |
| 246 |
|
| 247 |
/** |
| 248 |
* Get the primary order of a collation order. |
| 249 |
* @param order the collation order |
| 250 |
* @return the primary order of a collation order. |
| 251 |
* @stable ICU 2.6 |
| 252 |
*/ |
| 253 |
U_CAPI int32_t U_EXPORT2 |
| 254 |
ucol_primaryOrder (int32_t order); |
| 255 |
|
| 256 |
/** |
| 257 |
* Get the secondary order of a collation order. |
| 258 |
* @param order the collation order |
| 259 |
* @return the secondary order of a collation order. |
| 260 |
* @stable ICU 2.6 |
| 261 |
*/ |
| 262 |
U_CAPI int32_t U_EXPORT2 |
| 263 |
ucol_secondaryOrder (int32_t order); |
| 264 |
|
| 265 |
/** |
| 266 |
* Get the tertiary order of a collation order. |
| 267 |
* @param order the collation order |
| 268 |
* @return the tertiary order of a collation order. |
| 269 |
* @stable ICU 2.6 |
| 270 |
*/ |
| 271 |
U_CAPI int32_t U_EXPORT2 |
| 272 |
ucol_tertiaryOrder (int32_t order); |
| 273 |
|
| 274 |
#endif /* #if !UCONFIG_NO_COLLATION */ |
| 275 |
|
| 276 |
#endif |