2 *******************************************************************************
3 * Copyright (C) 2001-2014, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
9 * Modification History:
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 *******************************************************************************/
19 #include "unicode/utypes.h"
21 #if !UCONFIG_NO_COLLATION
24 * This indicates an error has occured during processing or if no more CEs is
28 #define UCOL_NULLORDER ((int32_t)0xFFFFFFFF)
30 #ifndef U_HIDE_INTERNAL_API
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
39 #define UCOL_PROCESSED_NULLORDER ((int64_t)U_INT64_MAX)
40 #endif /* U_HIDE_INTERNAL_API */
42 #include "unicode/ucol.h"
45 * The UCollationElements struct.
46 * For usage in C programs.
49 typedef struct UCollationElements UCollationElements
;
53 * \brief C API: UCollationElements
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:
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').
65 * And in German phonebook collation,
67 * . "<ae ligature>b"-> the first key is key('a'), the second key is key('e'), and
68 * . the third key is key('b').
70 * <p>Example of the iterator usage: (without error checking)
72 * . void CollationElementIterator_Example()
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);
85 * . order = ucol_prev(c, &success);
88 * . ucol_closeElements(c);
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
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>.
113 * Open the collation elements for a string.
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
122 U_STABLE UCollationElements
* U_EXPORT2
123 ucol_openElements(const UCollator
*coll
,
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.
136 U_STABLE
int32_t U_EXPORT2
137 ucol_keyHashCode(const uint8_t* key
, int32_t length
);
140 * Close a UCollationElements.
141 * Once closed, a UCollationElements may no longer be used.
142 * @param elems The UCollationElements to close.
145 U_STABLE
void U_EXPORT2
146 ucol_closeElements(UCollationElements
*elems
);
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.
157 U_STABLE
void U_EXPORT2
158 ucol_reset(UCollationElements
*elems
);
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
169 U_STABLE
int32_t U_EXPORT2
170 ucol_next(UCollationElements
*elems
, UErrorCode
*status
);
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
185 U_STABLE
int32_t U_EXPORT2
186 ucol_previous(UCollationElements
*elems
, UErrorCode
*status
);
188 #ifndef U_HIDE_INTERNAL_API
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.
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
204 U_INTERNAL
int64_t U_EXPORT2
205 ucol_nextProcessed(UCollationElements
*elems
, int32_t *ixLow
, int32_t *ixHigh
, UErrorCode
*status
);
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.
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.
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 */
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
244 U_STABLE
int32_t U_EXPORT2
245 ucol_getMaxExpansion(const UCollationElements
*elems
, int32_t order
);
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.
259 U_STABLE
void U_EXPORT2
260 ucol_setText( UCollationElements
*elems
,
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
274 U_STABLE
int32_t U_EXPORT2
275 ucol_getOffset(const UCollationElements
*elems
);
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
289 U_STABLE
void U_EXPORT2
290 ucol_setOffset(UCollationElements
*elems
,
295 * Get the primary order of a collation order.
296 * @param order the collation order
297 * @return the primary order of a collation order.
300 U_STABLE
int32_t U_EXPORT2
301 ucol_primaryOrder (int32_t order
);
304 * Get the secondary order of a collation order.
305 * @param order the collation order
306 * @return the secondary order of a collation order.
309 U_STABLE
int32_t U_EXPORT2
310 ucol_secondaryOrder (int32_t order
);
313 * Get the tertiary order of a collation order.
314 * @param order the collation order
315 * @return the tertiary order of a collation order.
318 U_STABLE
int32_t U_EXPORT2
319 ucol_tertiaryOrder (int32_t order
);
321 #endif /* #if !UCONFIG_NO_COLLATION */