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