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