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