jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ******************************************************************************* jpayne@69: * Copyright (C) 2001-2014, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: ******************************************************************************* jpayne@69: * jpayne@69: * File ucoleitr.h jpayne@69: * jpayne@69: * Modification History: jpayne@69: * jpayne@69: * Date Name Description jpayne@69: * 02/15/2001 synwee Modified all methods to process its own function jpayne@69: * instead of calling the equivalent c++ api (coleitr.h) jpayne@69: *******************************************************************************/ jpayne@69: jpayne@69: #ifndef UCOLEITR_H jpayne@69: #define UCOLEITR_H jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if !UCONFIG_NO_COLLATION jpayne@69: jpayne@69: /** jpayne@69: * This indicates an error has occured during processing or if no more CEs is jpayne@69: * to be returned. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: #define UCOL_NULLORDER ((int32_t)0xFFFFFFFF) jpayne@69: jpayne@69: #include "unicode/ucol.h" jpayne@69: jpayne@69: /** jpayne@69: * The UCollationElements struct. jpayne@69: * For usage in C programs. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: typedef struct UCollationElements UCollationElements; jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C API: UCollationElements jpayne@69: * jpayne@69: * The UCollationElements API is used as an iterator to walk through each jpayne@69: * character of an international string. Use the iterator to return the jpayne@69: * ordering priority of the positioned character. The ordering priority of a jpayne@69: * character, which we refer to as a key, defines how a character is collated jpayne@69: * in the given collation object. jpayne@69: * For example, consider the following in Slovak and in traditional Spanish collation: jpayne@69: *
jpayne@69:  * .       "ca" -> the first key is key('c') and second key is key('a').
jpayne@69:  * .       "cha" -> the first key is key('ch') and second key is key('a').
jpayne@69:  * 
jpayne@69: * And in German phonebook collation, jpayne@69: *
jpayne@69:  * .       "b"-> the first key is key('a'), the second key is key('e'), and
jpayne@69:  * .       the third key is key('b').
jpayne@69:  * 
jpayne@69: *

Example of the iterator usage: (without error checking) jpayne@69: *

jpayne@69:  * .  void CollationElementIterator_Example()
jpayne@69:  * .  {
jpayne@69:  * .      UChar *s;
jpayne@69:  * .      t_int32 order, primaryOrder;
jpayne@69:  * .      UCollationElements *c;
jpayne@69:  * .      UCollatorOld *coll;
jpayne@69:  * .      UErrorCode success = U_ZERO_ERROR;
jpayne@69:  * .      s=(UChar*)malloc(sizeof(UChar) * (strlen("This is a test")+1) );
jpayne@69:  * .      u_uastrcpy(s, "This is a test");
jpayne@69:  * .      coll = ucol_open(NULL, &success);
jpayne@69:  * .      c = ucol_openElements(coll, str, u_strlen(str), &status);
jpayne@69:  * .      order = ucol_next(c, &success);
jpayne@69:  * .      ucol_reset(c);
jpayne@69:  * .      order = ucol_prev(c, &success);
jpayne@69:  * .      free(s);
jpayne@69:  * .      ucol_close(coll);
jpayne@69:  * .      ucol_closeElements(c);
jpayne@69:  * .  }
jpayne@69:  * 
jpayne@69: *

jpayne@69: * ucol_next() returns the collation order of the next. jpayne@69: * ucol_prev() returns the collation order of the previous character. jpayne@69: * The Collation Element Iterator moves only in one direction between calls to jpayne@69: * ucol_reset. That is, ucol_next() and ucol_prev can not be inter-used. jpayne@69: * Whenever ucol_prev is to be called after ucol_next() or vice versa, jpayne@69: * ucol_reset has to be called first to reset the status, shifting pointers to jpayne@69: * either the end or the start of the string. Hence at the next call of jpayne@69: * ucol_prev or ucol_next, the first or last collation order will be returned. jpayne@69: * If a change of direction is done without a ucol_reset, the result is jpayne@69: * undefined. jpayne@69: * The result of a forward iterate (ucol_next) and reversed result of the jpayne@69: * backward iterate (ucol_prev) on the same string are equivalent, if jpayne@69: * collation orders with the value 0 are ignored. jpayne@69: * Character based on the comparison level of the collator. A collation order jpayne@69: * consists of primary order, secondary order and tertiary order. The data jpayne@69: * type of the collation order is int32_t. jpayne@69: * jpayne@69: * @see UCollator jpayne@69: */ jpayne@69: jpayne@69: /** jpayne@69: * Open the collation elements for a string. jpayne@69: * jpayne@69: * @param coll The collator containing the desired collation rules. jpayne@69: * @param text The text to iterate over. jpayne@69: * @param textLength The number of characters in text, or -1 if null-terminated jpayne@69: * @param status A pointer to a UErrorCode to receive any errors. jpayne@69: * @return a struct containing collation element information jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UCollationElements* U_EXPORT2 jpayne@69: ucol_openElements(const UCollator *coll, jpayne@69: const UChar *text, jpayne@69: int32_t textLength, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * get a hash code for a key... Not very useful! jpayne@69: * @param key the given key. jpayne@69: * @param length the size of the key array. jpayne@69: * @return the hash code. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucol_keyHashCode(const uint8_t* key, int32_t length); jpayne@69: jpayne@69: /** jpayne@69: * Close a UCollationElements. jpayne@69: * Once closed, a UCollationElements may no longer be used. jpayne@69: * @param elems The UCollationElements to close. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucol_closeElements(UCollationElements *elems); jpayne@69: jpayne@69: /** jpayne@69: * Reset the collation elements to their initial state. jpayne@69: * This will move the 'cursor' to the beginning of the text. jpayne@69: * Property settings for collation will be reset to the current status. jpayne@69: * @param elems The UCollationElements to reset. jpayne@69: * @see ucol_next jpayne@69: * @see ucol_previous jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucol_reset(UCollationElements *elems); jpayne@69: jpayne@69: /** jpayne@69: * Get the ordering priority of the next collation element in the text. jpayne@69: * A single character may contain more than one collation element. jpayne@69: * @param elems The UCollationElements containing the text. jpayne@69: * @param status A pointer to a UErrorCode to receive any errors. jpayne@69: * @return The next collation elements ordering, otherwise returns UCOL_NULLORDER jpayne@69: * if an error has occured or if the end of string has been reached jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucol_next(UCollationElements *elems, UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Get the ordering priority of the previous collation element in the text. jpayne@69: * A single character may contain more than one collation element. jpayne@69: * Note that internally a stack is used to store buffered collation elements. jpayne@69: * @param elems The UCollationElements containing the text. jpayne@69: * @param status A pointer to a UErrorCode to receive any errors. Noteably jpayne@69: * a U_BUFFER_OVERFLOW_ERROR is returned if the internal stack jpayne@69: * buffer has been exhausted. jpayne@69: * @return The previous collation elements ordering, otherwise returns jpayne@69: * UCOL_NULLORDER if an error has occured or if the start of string has jpayne@69: * been reached. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucol_previous(UCollationElements *elems, UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Get the maximum length of any expansion sequences that end with the jpayne@69: * specified comparison order. jpayne@69: * This is useful for .... ? jpayne@69: * @param elems The UCollationElements containing the text. jpayne@69: * @param order A collation order returned by previous or next. jpayne@69: * @return maximum size of the expansion sequences ending with the collation jpayne@69: * element or 1 if collation element does not occur at the end of any jpayne@69: * expansion sequence jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucol_getMaxExpansion(const UCollationElements *elems, int32_t order); jpayne@69: jpayne@69: /** jpayne@69: * Set the text containing the collation elements. jpayne@69: * Property settings for collation will remain the same. jpayne@69: * In order to reset the iterator to the current collation property settings, jpayne@69: * the API reset() has to be called. jpayne@69: * @param elems The UCollationElements to set. jpayne@69: * @param text The source text containing the collation elements. jpayne@69: * @param textLength The length of text, or -1 if null-terminated. jpayne@69: * @param status A pointer to a UErrorCode to receive any errors. jpayne@69: * @see ucol_getText jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucol_setText( UCollationElements *elems, jpayne@69: const UChar *text, jpayne@69: int32_t textLength, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Get the offset of the current source character. jpayne@69: * This is an offset into the text of the character containing the current jpayne@69: * collation elements. jpayne@69: * @param elems The UCollationElements to query. jpayne@69: * @return The offset of the current source character. jpayne@69: * @see ucol_setOffset jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucol_getOffset(const UCollationElements *elems); jpayne@69: jpayne@69: /** jpayne@69: * Set the offset of the current source character. jpayne@69: * This is an offset into the text of the character to be processed. jpayne@69: * Property settings for collation will remain the same. jpayne@69: * In order to reset the iterator to the current collation property settings, jpayne@69: * the API reset() has to be called. jpayne@69: * @param elems The UCollationElements to set. jpayne@69: * @param offset The desired character offset. jpayne@69: * @param status A pointer to a UErrorCode to receive any errors. jpayne@69: * @see ucol_getOffset jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucol_setOffset(UCollationElements *elems, jpayne@69: int32_t offset, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Get the primary order of a collation order. jpayne@69: * @param order the collation order jpayne@69: * @return the primary order of a collation order. jpayne@69: * @stable ICU 2.6 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucol_primaryOrder (int32_t order); jpayne@69: jpayne@69: /** jpayne@69: * Get the secondary order of a collation order. jpayne@69: * @param order the collation order jpayne@69: * @return the secondary order of a collation order. jpayne@69: * @stable ICU 2.6 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucol_secondaryOrder (int32_t order); jpayne@69: jpayne@69: /** jpayne@69: * Get the tertiary order of a collation order. jpayne@69: * @param order the collation order jpayne@69: * @return the tertiary order of a collation order. jpayne@69: * @stable ICU 2.6 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucol_tertiaryOrder (int32_t order); jpayne@69: jpayne@69: #endif /* #if !UCONFIG_NO_COLLATION */ jpayne@69: jpayne@69: #endif