]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/unicode/ucoleitr.h
ICU-59180.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / ucoleitr.h
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
b75a7d8f
A
3/*
4*******************************************************************************
57a6839d 5* Copyright (C) 2001-2014, International Business Machines
b75a7d8f
A
6* Corporation and others. All Rights Reserved.
7*******************************************************************************
8*
57a6839d 9* File ucoleitr.h
b75a7d8f
A
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 */
374ca955 30#define UCOL_NULLORDER ((int32_t)0xFFFFFFFF)
b75a7d8f 31
4388f060
A
32#ifndef U_HIDE_INTERNAL_API
33/**
57a6839d
A
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
46f4442e
A
37 * to be returned.
38 *
39 * @internal
40 */
41#define UCOL_PROCESSED_NULLORDER ((int64_t)U_INT64_MAX)
4388f060 42#endif /* U_HIDE_INTERNAL_API */
46f4442e 43
b75a7d8f
A
44#include "unicode/ucol.h"
45
46/**
47 * The UCollationElements struct.
48 * For usage in C programs.
49 * @stable ICU 2.0
50 */
51typedef 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.
57a6839d 62 * For example, consider the following in Slovak and in traditional Spanish collation:
b75a7d8f
A
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>
57a6839d 67 * And in German phonebook collation,
b75a7d8f
A
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
57a6839d 106 * collation orders with the value 0 are ignored.
b75a7d8f
A
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
57a6839d 109 * type of the collation order is <strong>int32_t</strong>.
b75a7d8f
A
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
57a6839d 120 * @param status A pointer to a UErrorCode to receive any errors.
b75a7d8f
A
121 * @return a struct containing collation element information
122 * @stable ICU 2.0
123 */
374ca955 124U_STABLE UCollationElements* U_EXPORT2
b75a7d8f
A
125ucol_openElements(const UCollator *coll,
126 const UChar *text,
127 int32_t textLength,
128 UErrorCode *status);
129
729e4ab9 130
b75a7d8f
A
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 */
374ca955 138U_STABLE int32_t U_EXPORT2
b75a7d8f
A
139ucol_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 */
374ca955 147U_STABLE void U_EXPORT2
b75a7d8f
A
148ucol_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 */
374ca955 159U_STABLE void U_EXPORT2
b75a7d8f
A
160ucol_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.
57a6839d 166 * @param status A pointer to a UErrorCode to receive any errors.
b75a7d8f
A
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 */
374ca955 171U_STABLE int32_t U_EXPORT2
b75a7d8f
A
172ucol_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.
b75a7d8f 178 * @param elems The UCollationElements containing the text.
57a6839d 179 * @param status A pointer to a UErrorCode to receive any errors. Noteably
b75a7d8f
A
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 */
374ca955 187U_STABLE int32_t U_EXPORT2
b75a7d8f 188ucol_previous(UCollationElements *elems, UErrorCode *status);
46f4442e 189
4388f060 190#ifndef U_HIDE_INTERNAL_API
46f4442e 191/**
57a6839d
A
192 * DO NOT USE, INTERNAL FUNCTION THAT WAS REMOVED AND THEN
193 * TEMPORARILY RESTORED TO PREVENT THE BUILD FROM BREAKING.
46f4442e
A
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.
57a6839d 201 * @return The next collation elements ordering, otherwise returns UCOL_PROCESSED_NULLORDER
46f4442e
A
202 * if an error has occured or if the end of string has been reached
203 *
204 * @internal
205 */
206U_INTERNAL int64_t U_EXPORT2
207ucol_nextProcessed(UCollationElements *elems, int32_t *ixLow, int32_t *ixHigh, UErrorCode *status);
208
209/**
57a6839d
A
210 * DO NOT USE, INTERNAL FUNCTION THAT WAS REMOVED AND THEN
211 * TEMPORARILY RESTORED TO PREVENT THE BUILD FROM BREAKING.
46f4442e
A
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.
57a6839d
A
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
46f4442e
A
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
57a6839d 222 * @param status A pointer to an UErrorCode to receive any errors. Noteably
46f4442e
A
223 * a U_BUFFER_OVERFLOW_ERROR is returned if the internal stack
224 * buffer has been exhausted.
57a6839d 225 * @return The previous collation elements ordering, otherwise returns
46f4442e
A
226 * UCOL_PROCESSED_NULLORDER if an error has occured or if the start of
227 * string has been reached.
228 *
229 * @internal
230 */
231U_INTERNAL int64_t U_EXPORT2
232ucol_previousProcessed(UCollationElements *elems, int32_t *ixLow, int32_t *ixHigh, UErrorCode *status);
4388f060 233#endif /* U_HIDE_INTERNAL_API */
b75a7d8f
A
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 */
374ca955 246U_STABLE int32_t U_EXPORT2
b75a7d8f
A
247ucol_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.
57a6839d 257 * @param status A pointer to a UErrorCode to receive any errors.
b75a7d8f
A
258 * @see ucol_getText
259 * @stable ICU 2.0
260 */
374ca955 261U_STABLE void U_EXPORT2
b75a7d8f
A
262ucol_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 */
374ca955 276U_STABLE int32_t U_EXPORT2
b75a7d8f
A
277ucol_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.
57a6839d 287 * @param status A pointer to a UErrorCode to receive any errors.
b75a7d8f
A
288 * @see ucol_getOffset
289 * @stable ICU 2.0
290 */
374ca955 291U_STABLE void U_EXPORT2
b75a7d8f
A
292ucol_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.
374ca955 300* @stable ICU 2.6
b75a7d8f 301*/
374ca955 302U_STABLE int32_t U_EXPORT2
b75a7d8f
A
303ucol_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.
374ca955 309* @stable ICU 2.6
b75a7d8f 310*/
374ca955 311U_STABLE int32_t U_EXPORT2
b75a7d8f
A
312ucol_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.
374ca955 318* @stable ICU 2.6
b75a7d8f 319*/
374ca955 320U_STABLE int32_t U_EXPORT2
b75a7d8f
A
321ucol_tertiaryOrder (int32_t order);
322
323#endif /* #if !UCONFIG_NO_COLLATION */
324
325#endif