|
||||
File indexing completed on 2025-01-18 10:13:10
0001 // © 2016 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 /* 0004 ******************************************************************************* 0005 * Copyright (C) 2001-2014, International Business Machines 0006 * Corporation and others. All Rights Reserved. 0007 ******************************************************************************* 0008 * 0009 * File ucoleitr.h 0010 * 0011 * Modification History: 0012 * 0013 * Date Name Description 0014 * 02/15/2001 synwee Modified all methods to process its own function 0015 * instead of calling the equivalent c++ api (coleitr.h) 0016 *******************************************************************************/ 0017 0018 #ifndef UCOLEITR_H 0019 #define UCOLEITR_H 0020 0021 #include "unicode/utypes.h" 0022 0023 #if !UCONFIG_NO_COLLATION 0024 0025 /** 0026 * This indicates an error has occurred during processing or if no more CEs is 0027 * to be returned. 0028 * @stable ICU 2.0 0029 */ 0030 #define UCOL_NULLORDER ((int32_t)0xFFFFFFFF) 0031 0032 #include "unicode/ucol.h" 0033 0034 /** 0035 * The UCollationElements struct. 0036 * For usage in C programs. 0037 * @stable ICU 2.0 0038 */ 0039 typedef struct UCollationElements UCollationElements; 0040 0041 /** 0042 * \file 0043 * \brief C API: UCollationElements 0044 * 0045 * The UCollationElements API is used as an iterator to walk through each 0046 * character of an international string. Use the iterator to return the 0047 * ordering priority of the positioned character. The ordering priority of a 0048 * character, which we refer to as a key, defines how a character is collated 0049 * in the given collation object. 0050 * For example, consider the following in Slovak and in traditional Spanish collation: 0051 * <pre> 0052 * . "ca" -> the first key is key('c') and second key is key('a'). 0053 * . "cha" -> the first key is key('ch') and second key is key('a'). 0054 * </pre> 0055 * And in German phonebook collation, 0056 * <pre> 0057 * . "<ae ligature>b"-> the first key is key('a'), the second key is key('e'), and 0058 * . the third key is key('b'). 0059 * </pre> 0060 * <p>Example of the iterator usage: (without error checking) 0061 * <pre> 0062 * . void CollationElementIterator_Example() 0063 * . { 0064 * . UChar *s; 0065 * . t_int32 order, primaryOrder; 0066 * . UCollationElements *c; 0067 * . UCollatorOld *coll; 0068 * . UErrorCode success = U_ZERO_ERROR; 0069 * . str=(UChar*)malloc(sizeof(UChar) * (strlen("This is a test")+1) ); 0070 * . u_uastrcpy(str, "This is a test"); 0071 * . coll = ucol_open(NULL, &success); 0072 * . c = ucol_openElements(coll, str, u_strlen(str), &status); 0073 * . order = ucol_next(c, &success); 0074 * . ucol_reset(c); 0075 * . order = ucol_prev(c, &success); 0076 * . free(str); 0077 * . ucol_close(coll); 0078 * . ucol_closeElements(c); 0079 * . } 0080 * </pre> 0081 * <p> 0082 * ucol_next() returns the collation order of the next. 0083 * ucol_prev() returns the collation order of the previous character. 0084 * The Collation Element Iterator moves only in one direction between calls to 0085 * ucol_reset. That is, ucol_next() and ucol_prev can not be inter-used. 0086 * Whenever ucol_prev is to be called after ucol_next() or vice versa, 0087 * ucol_reset has to be called first to reset the status, shifting pointers to 0088 * either the end or the start of the string. Hence at the next call of 0089 * ucol_prev or ucol_next, the first or last collation order will be returned. 0090 * If a change of direction is done without a ucol_reset, the result is 0091 * undefined. 0092 * The result of a forward iterate (ucol_next) and reversed result of the 0093 * backward iterate (ucol_prev) on the same string are equivalent, if 0094 * collation orders with the value 0 are ignored. 0095 * Character based on the comparison level of the collator. A collation order 0096 * consists of primary order, secondary order and tertiary order. The data 0097 * type of the collation order is <strong>int32_t</strong>. 0098 * 0099 * @see UCollator 0100 */ 0101 0102 /** 0103 * Open the collation elements for a string. 0104 * 0105 * The UCollationElements retains a pointer to the supplied text. 0106 * The caller must not modify or delete the text while the UCollationElements 0107 * object is used to iterate over this text. 0108 * 0109 * @param coll The collator containing the desired collation rules. 0110 * @param text The text to iterate over. 0111 * @param textLength The number of characters in text, or -1 if null-terminated 0112 * @param status A pointer to a UErrorCode to receive any errors. 0113 * @return a struct containing collation element information 0114 * @stable ICU 2.0 0115 */ 0116 U_CAPI UCollationElements* U_EXPORT2 0117 ucol_openElements(const UCollator *coll, 0118 const UChar *text, 0119 int32_t textLength, 0120 UErrorCode *status); 0121 0122 /** 0123 * get a hash code for a key... Not very useful! 0124 * @param key the given key. 0125 * @param length the size of the key array. 0126 * @return the hash code. 0127 * @stable ICU 2.0 0128 */ 0129 U_CAPI int32_t U_EXPORT2 0130 ucol_keyHashCode(const uint8_t* key, int32_t length); 0131 0132 /** 0133 * Close a UCollationElements. 0134 * Once closed, a UCollationElements may no longer be used. 0135 * @param elems The UCollationElements to close. 0136 * @stable ICU 2.0 0137 */ 0138 U_CAPI void U_EXPORT2 0139 ucol_closeElements(UCollationElements *elems); 0140 0141 /** 0142 * Reset the collation elements to their initial state. 0143 * This will move the 'cursor' to the beginning of the text. 0144 * Property settings for collation will be reset to the current status. 0145 * @param elems The UCollationElements to reset. 0146 * @see ucol_next 0147 * @see ucol_previous 0148 * @stable ICU 2.0 0149 */ 0150 U_CAPI void U_EXPORT2 0151 ucol_reset(UCollationElements *elems); 0152 0153 /** 0154 * Get the ordering priority of the next collation element in the text. 0155 * A single character may contain more than one collation element. 0156 * @param elems The UCollationElements containing the text. 0157 * @param status A pointer to a UErrorCode to receive any errors. 0158 * @return The next collation elements ordering, otherwise returns UCOL_NULLORDER 0159 * if an error has occurred or if the end of string has been reached 0160 * @stable ICU 2.0 0161 */ 0162 U_CAPI int32_t U_EXPORT2 0163 ucol_next(UCollationElements *elems, UErrorCode *status); 0164 0165 /** 0166 * Get the ordering priority of the previous collation element in the text. 0167 * A single character may contain more than one collation element. 0168 * Note that internally a stack is used to store buffered collation elements. 0169 * @param elems The UCollationElements containing the text. 0170 * @param status A pointer to a UErrorCode to receive any errors. Notably 0171 * a U_BUFFER_OVERFLOW_ERROR is returned if the internal stack 0172 * buffer has been exhausted. 0173 * @return The previous collation elements ordering, otherwise returns 0174 * UCOL_NULLORDER if an error has occurred or if the start of string has 0175 * been reached. 0176 * @stable ICU 2.0 0177 */ 0178 U_CAPI int32_t U_EXPORT2 0179 ucol_previous(UCollationElements *elems, UErrorCode *status); 0180 0181 /** 0182 * Get the maximum length of any expansion sequences that end with the 0183 * specified comparison order. 0184 * This is useful for .... ? 0185 * @param elems The UCollationElements containing the text. 0186 * @param order A collation order returned by previous or next. 0187 * @return maximum size of the expansion sequences ending with the collation 0188 * element or 1 if collation element does not occur at the end of any 0189 * expansion sequence 0190 * @stable ICU 2.0 0191 */ 0192 U_CAPI int32_t U_EXPORT2 0193 ucol_getMaxExpansion(const UCollationElements *elems, int32_t order); 0194 0195 /** 0196 * Set the text containing the collation elements. 0197 * Property settings for collation will remain the same. 0198 * In order to reset the iterator to the current collation property settings, 0199 * the API reset() has to be called. 0200 * 0201 * The UCollationElements retains a pointer to the supplied text. 0202 * The caller must not modify or delete the text while the UCollationElements 0203 * object is used to iterate over this text. 0204 * 0205 * @param elems The UCollationElements to set. 0206 * @param text The source text containing the collation elements. 0207 * @param textLength The length of text, or -1 if null-terminated. 0208 * @param status A pointer to a UErrorCode to receive any errors. 0209 * @see ucol_getText 0210 * @stable ICU 2.0 0211 */ 0212 U_CAPI void U_EXPORT2 0213 ucol_setText( UCollationElements *elems, 0214 const UChar *text, 0215 int32_t textLength, 0216 UErrorCode *status); 0217 0218 /** 0219 * Get the offset of the current source character. 0220 * This is an offset into the text of the character containing the current 0221 * collation elements. 0222 * @param elems The UCollationElements to query. 0223 * @return The offset of the current source character. 0224 * @see ucol_setOffset 0225 * @stable ICU 2.0 0226 */ 0227 U_CAPI int32_t U_EXPORT2 0228 ucol_getOffset(const UCollationElements *elems); 0229 0230 /** 0231 * Set the offset of the current source character. 0232 * This is an offset into the text of the character to be processed. 0233 * Property settings for collation will remain the same. 0234 * In order to reset the iterator to the current collation property settings, 0235 * the API reset() has to be called. 0236 * @param elems The UCollationElements to set. 0237 * @param offset The desired character offset. 0238 * @param status A pointer to a UErrorCode to receive any errors. 0239 * @see ucol_getOffset 0240 * @stable ICU 2.0 0241 */ 0242 U_CAPI void U_EXPORT2 0243 ucol_setOffset(UCollationElements *elems, 0244 int32_t offset, 0245 UErrorCode *status); 0246 0247 /** 0248 * Get the primary order of a collation order. 0249 * @param order the collation order 0250 * @return the primary order of a collation order. 0251 * @stable ICU 2.6 0252 */ 0253 U_CAPI int32_t U_EXPORT2 0254 ucol_primaryOrder (int32_t order); 0255 0256 /** 0257 * Get the secondary order of a collation order. 0258 * @param order the collation order 0259 * @return the secondary order of a collation order. 0260 * @stable ICU 2.6 0261 */ 0262 U_CAPI int32_t U_EXPORT2 0263 ucol_secondaryOrder (int32_t order); 0264 0265 /** 0266 * Get the tertiary order of a collation order. 0267 * @param order the collation order 0268 * @return the tertiary order of a collation order. 0269 * @stable ICU 2.6 0270 */ 0271 U_CAPI int32_t U_EXPORT2 0272 ucol_tertiaryOrder (int32_t order); 0273 0274 #endif /* #if !UCONFIG_NO_COLLATION */ 0275 0276 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |