2 *******************************************************************************
3 * Copyright (C) 2001-2008, 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)
31 * This indicates an error has occured during processing or there are no more CEs
36 #define UCOL_PROCESSED_NULLORDER ((int64_t)U_INT64_MAX)
38 #include "unicode/ucol.h"
41 * The UCollationElements struct.
42 * For usage in C programs.
45 typedef struct UCollationElements UCollationElements
;
49 * \brief C API: UCollationElements
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:
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').
63 * . "<ae ligature>b"-> the first key is key('a'), the second key is key('e'), and
64 * . the third key is key('b').
66 * <p>Example of the iterator usage: (without error checking)
68 * . void CollationElementIterator_Example()
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);
81 * . order = ucol_prev(c, &success);
84 * . ucol_closeElements(c);
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
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>.
109 * Open the collation elements for a string.
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
118 U_STABLE UCollationElements
* U_EXPORT2
119 ucol_openElements(const UCollator
*coll
,
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.
131 U_STABLE
int32_t U_EXPORT2
132 ucol_keyHashCode(const uint8_t* key
, int32_t length
);
135 * Close a UCollationElements.
136 * Once closed, a UCollationElements may no longer be used.
137 * @param elems The UCollationElements to close.
140 U_STABLE
void U_EXPORT2
141 ucol_closeElements(UCollationElements
*elems
);
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.
152 U_STABLE
void U_EXPORT2
153 ucol_reset(UCollationElements
*elems
);
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
164 U_STABLE
int32_t U_EXPORT2
165 ucol_next(UCollationElements
*elems
, UErrorCode
*status
);
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
183 U_STABLE
int32_t U_EXPORT2
184 ucol_previous(UCollationElements
*elems
, UErrorCode
*status
);
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.
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
199 U_INTERNAL
int64_t U_EXPORT2
200 ucol_nextProcessed(UCollationElements
*elems
, int32_t *ixLow
, int32_t *ixHigh
, UErrorCode
*status
);
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.
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.
222 U_INTERNAL
int64_t U_EXPORT2
223 ucol_previousProcessed(UCollationElements
*elems
, int32_t *ixLow
, int32_t *ixHigh
, UErrorCode
*status
);
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
236 U_STABLE
int32_t U_EXPORT2
237 ucol_getMaxExpansion(const UCollationElements
*elems
, int32_t order
);
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.
251 U_STABLE
void U_EXPORT2
252 ucol_setText( UCollationElements
*elems
,
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
266 U_STABLE
int32_t U_EXPORT2
267 ucol_getOffset(const UCollationElements
*elems
);
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
281 U_STABLE
void U_EXPORT2
282 ucol_setOffset(UCollationElements
*elems
,
287 * Get the primary order of a collation order.
288 * @param order the collation order
289 * @return the primary order of a collation order.
292 U_STABLE
int32_t U_EXPORT2
293 ucol_primaryOrder (int32_t order
);
296 * Get the secondary order of a collation order.
297 * @param order the collation order
298 * @return the secondary order of a collation order.
301 U_STABLE
int32_t U_EXPORT2
302 ucol_secondaryOrder (int32_t order
);
305 * Get the tertiary order of a collation order.
306 * @param order the collation order
307 * @return the tertiary order of a collation order.
310 U_STABLE
int32_t U_EXPORT2
311 ucol_tertiaryOrder (int32_t order
);
313 #endif /* #if !UCONFIG_NO_COLLATION */