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