1*0e209d39SAndroid Build Coastguard Worker // © 2017 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker 4*0e209d39SAndroid Build Coastguard Worker // ucptrie.h (modified from utrie2.h) 5*0e209d39SAndroid Build Coastguard Worker // created: 2017dec29 Markus W. Scherer 6*0e209d39SAndroid Build Coastguard Worker 7*0e209d39SAndroid Build Coastguard Worker #ifndef __UCPTRIE_H__ 8*0e209d39SAndroid Build Coastguard Worker #define __UCPTRIE_H__ 9*0e209d39SAndroid Build Coastguard Worker 10*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 11*0e209d39SAndroid Build Coastguard Worker #include "unicode/ucpmap.h" 12*0e209d39SAndroid Build Coastguard Worker #include "unicode/utf8.h" 13*0e209d39SAndroid Build Coastguard Worker 14*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API 15*0e209d39SAndroid Build Coastguard Worker #include "unicode/localpointer.h" 16*0e209d39SAndroid Build Coastguard Worker #endif // U_SHOW_CPLUSPLUS_API 17*0e209d39SAndroid Build Coastguard Worker 18*0e209d39SAndroid Build Coastguard Worker U_CDECL_BEGIN 19*0e209d39SAndroid Build Coastguard Worker 20*0e209d39SAndroid Build Coastguard Worker /** 21*0e209d39SAndroid Build Coastguard Worker * \file 22*0e209d39SAndroid Build Coastguard Worker * \brief C API: This file defines an immutable Unicode code point trie. 23*0e209d39SAndroid Build Coastguard Worker * 24*0e209d39SAndroid Build Coastguard Worker * @see UCPTrie 25*0e209d39SAndroid Build Coastguard Worker * @see UMutableCPTrie 26*0e209d39SAndroid Build Coastguard Worker */ 27*0e209d39SAndroid Build Coastguard Worker 28*0e209d39SAndroid Build Coastguard Worker #ifndef U_IN_DOXYGEN 29*0e209d39SAndroid Build Coastguard Worker /** @internal */ 30*0e209d39SAndroid Build Coastguard Worker typedef union UCPTrieData { 31*0e209d39SAndroid Build Coastguard Worker /** @internal */ 32*0e209d39SAndroid Build Coastguard Worker const void *ptr0; 33*0e209d39SAndroid Build Coastguard Worker /** @internal */ 34*0e209d39SAndroid Build Coastguard Worker const uint16_t *ptr16; 35*0e209d39SAndroid Build Coastguard Worker /** @internal */ 36*0e209d39SAndroid Build Coastguard Worker const uint32_t *ptr32; 37*0e209d39SAndroid Build Coastguard Worker /** @internal */ 38*0e209d39SAndroid Build Coastguard Worker const uint8_t *ptr8; 39*0e209d39SAndroid Build Coastguard Worker } UCPTrieData; 40*0e209d39SAndroid Build Coastguard Worker #endif 41*0e209d39SAndroid Build Coastguard Worker 42*0e209d39SAndroid Build Coastguard Worker /** 43*0e209d39SAndroid Build Coastguard Worker * Immutable Unicode code point trie structure. 44*0e209d39SAndroid Build Coastguard Worker * Fast, reasonably compact, map from Unicode code points (U+0000..U+10FFFF) to integer values. 45*0e209d39SAndroid Build Coastguard Worker * For details see https://icu.unicode.org/design/struct/utrie 46*0e209d39SAndroid Build Coastguard Worker * 47*0e209d39SAndroid Build Coastguard Worker * Do not access UCPTrie fields directly; use public functions and macros. 48*0e209d39SAndroid Build Coastguard Worker * Functions are easy to use: They support all trie types and value widths. 49*0e209d39SAndroid Build Coastguard Worker * 50*0e209d39SAndroid Build Coastguard Worker * When performance is really important, macros provide faster access. 51*0e209d39SAndroid Build Coastguard Worker * Most macros are specific to either "fast" or "small" tries, see UCPTrieType. 52*0e209d39SAndroid Build Coastguard Worker * There are "fast" macros for special optimized use cases. 53*0e209d39SAndroid Build Coastguard Worker * 54*0e209d39SAndroid Build Coastguard Worker * The macros will return bogus values, or may crash, if used on the wrong type or value width. 55*0e209d39SAndroid Build Coastguard Worker * 56*0e209d39SAndroid Build Coastguard Worker * @see UMutableCPTrie 57*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 58*0e209d39SAndroid Build Coastguard Worker */ 59*0e209d39SAndroid Build Coastguard Worker struct UCPTrie { 60*0e209d39SAndroid Build Coastguard Worker #ifndef U_IN_DOXYGEN 61*0e209d39SAndroid Build Coastguard Worker /** @internal */ 62*0e209d39SAndroid Build Coastguard Worker const uint16_t *index; 63*0e209d39SAndroid Build Coastguard Worker /** @internal */ 64*0e209d39SAndroid Build Coastguard Worker UCPTrieData data; 65*0e209d39SAndroid Build Coastguard Worker 66*0e209d39SAndroid Build Coastguard Worker /** @internal */ 67*0e209d39SAndroid Build Coastguard Worker int32_t indexLength; 68*0e209d39SAndroid Build Coastguard Worker /** @internal */ 69*0e209d39SAndroid Build Coastguard Worker int32_t dataLength; 70*0e209d39SAndroid Build Coastguard Worker /** Start of the last range which ends at U+10FFFF. @internal */ 71*0e209d39SAndroid Build Coastguard Worker UChar32 highStart; 72*0e209d39SAndroid Build Coastguard Worker /** highStart>>12 @internal */ 73*0e209d39SAndroid Build Coastguard Worker uint16_t shifted12HighStart; 74*0e209d39SAndroid Build Coastguard Worker 75*0e209d39SAndroid Build Coastguard Worker /** @internal */ 76*0e209d39SAndroid Build Coastguard Worker int8_t type; // UCPTrieType 77*0e209d39SAndroid Build Coastguard Worker /** @internal */ 78*0e209d39SAndroid Build Coastguard Worker int8_t valueWidth; // UCPTrieValueWidth 79*0e209d39SAndroid Build Coastguard Worker 80*0e209d39SAndroid Build Coastguard Worker /** padding/reserved @internal */ 81*0e209d39SAndroid Build Coastguard Worker uint32_t reserved32; 82*0e209d39SAndroid Build Coastguard Worker /** padding/reserved @internal */ 83*0e209d39SAndroid Build Coastguard Worker uint16_t reserved16; 84*0e209d39SAndroid Build Coastguard Worker 85*0e209d39SAndroid Build Coastguard Worker /** 86*0e209d39SAndroid Build Coastguard Worker * Internal index-3 null block offset. 87*0e209d39SAndroid Build Coastguard Worker * Set to an impossibly high value (e.g., 0xffff) if there is no dedicated index-3 null block. 88*0e209d39SAndroid Build Coastguard Worker * @internal 89*0e209d39SAndroid Build Coastguard Worker */ 90*0e209d39SAndroid Build Coastguard Worker uint16_t index3NullOffset; 91*0e209d39SAndroid Build Coastguard Worker /** 92*0e209d39SAndroid Build Coastguard Worker * Internal data null block offset, not shifted. 93*0e209d39SAndroid Build Coastguard Worker * Set to an impossibly high value (e.g., 0xfffff) if there is no dedicated data null block. 94*0e209d39SAndroid Build Coastguard Worker * @internal 95*0e209d39SAndroid Build Coastguard Worker */ 96*0e209d39SAndroid Build Coastguard Worker int32_t dataNullOffset; 97*0e209d39SAndroid Build Coastguard Worker /** @internal */ 98*0e209d39SAndroid Build Coastguard Worker uint32_t nullValue; 99*0e209d39SAndroid Build Coastguard Worker 100*0e209d39SAndroid Build Coastguard Worker #ifdef UCPTRIE_DEBUG 101*0e209d39SAndroid Build Coastguard Worker /** @internal */ 102*0e209d39SAndroid Build Coastguard Worker const char *name; 103*0e209d39SAndroid Build Coastguard Worker #endif 104*0e209d39SAndroid Build Coastguard Worker #endif 105*0e209d39SAndroid Build Coastguard Worker }; 106*0e209d39SAndroid Build Coastguard Worker #ifndef U_IN_DOXYGEN 107*0e209d39SAndroid Build Coastguard Worker typedef struct UCPTrie UCPTrie; 108*0e209d39SAndroid Build Coastguard Worker #endif 109*0e209d39SAndroid Build Coastguard Worker 110*0e209d39SAndroid Build Coastguard Worker /** 111*0e209d39SAndroid Build Coastguard Worker * Selectors for the type of a UCPTrie. 112*0e209d39SAndroid Build Coastguard Worker * Different trade-offs for size vs. speed. 113*0e209d39SAndroid Build Coastguard Worker * 114*0e209d39SAndroid Build Coastguard Worker * @see umutablecptrie_buildImmutable 115*0e209d39SAndroid Build Coastguard Worker * @see ucptrie_openFromBinary 116*0e209d39SAndroid Build Coastguard Worker * @see ucptrie_getType 117*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 118*0e209d39SAndroid Build Coastguard Worker */ 119*0e209d39SAndroid Build Coastguard Worker enum UCPTrieType { 120*0e209d39SAndroid Build Coastguard Worker /** 121*0e209d39SAndroid Build Coastguard Worker * For ucptrie_openFromBinary() to accept any type. 122*0e209d39SAndroid Build Coastguard Worker * ucptrie_getType() will return the actual type. 123*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 124*0e209d39SAndroid Build Coastguard Worker */ 125*0e209d39SAndroid Build Coastguard Worker UCPTRIE_TYPE_ANY = -1, 126*0e209d39SAndroid Build Coastguard Worker /** 127*0e209d39SAndroid Build Coastguard Worker * Fast/simple/larger BMP data structure. Use functions and "fast" macros. 128*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 129*0e209d39SAndroid Build Coastguard Worker */ 130*0e209d39SAndroid Build Coastguard Worker UCPTRIE_TYPE_FAST, 131*0e209d39SAndroid Build Coastguard Worker /** 132*0e209d39SAndroid Build Coastguard Worker * Small/slower BMP data structure. Use functions and "small" macros. 133*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 134*0e209d39SAndroid Build Coastguard Worker */ 135*0e209d39SAndroid Build Coastguard Worker UCPTRIE_TYPE_SMALL 136*0e209d39SAndroid Build Coastguard Worker }; 137*0e209d39SAndroid Build Coastguard Worker #ifndef U_IN_DOXYGEN 138*0e209d39SAndroid Build Coastguard Worker typedef enum UCPTrieType UCPTrieType; 139*0e209d39SAndroid Build Coastguard Worker #endif 140*0e209d39SAndroid Build Coastguard Worker 141*0e209d39SAndroid Build Coastguard Worker /** 142*0e209d39SAndroid Build Coastguard Worker * Selectors for the number of bits in a UCPTrie data value. 143*0e209d39SAndroid Build Coastguard Worker * 144*0e209d39SAndroid Build Coastguard Worker * @see umutablecptrie_buildImmutable 145*0e209d39SAndroid Build Coastguard Worker * @see ucptrie_openFromBinary 146*0e209d39SAndroid Build Coastguard Worker * @see ucptrie_getValueWidth 147*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 148*0e209d39SAndroid Build Coastguard Worker */ 149*0e209d39SAndroid Build Coastguard Worker enum UCPTrieValueWidth { 150*0e209d39SAndroid Build Coastguard Worker /** 151*0e209d39SAndroid Build Coastguard Worker * For ucptrie_openFromBinary() to accept any data value width. 152*0e209d39SAndroid Build Coastguard Worker * ucptrie_getValueWidth() will return the actual data value width. 153*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 154*0e209d39SAndroid Build Coastguard Worker */ 155*0e209d39SAndroid Build Coastguard Worker UCPTRIE_VALUE_BITS_ANY = -1, 156*0e209d39SAndroid Build Coastguard Worker /** 157*0e209d39SAndroid Build Coastguard Worker * The trie stores 16 bits per data value. 158*0e209d39SAndroid Build Coastguard Worker * It returns them as unsigned values 0..0xffff=65535. 159*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 160*0e209d39SAndroid Build Coastguard Worker */ 161*0e209d39SAndroid Build Coastguard Worker UCPTRIE_VALUE_BITS_16, 162*0e209d39SAndroid Build Coastguard Worker /** 163*0e209d39SAndroid Build Coastguard Worker * The trie stores 32 bits per data value. 164*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 165*0e209d39SAndroid Build Coastguard Worker */ 166*0e209d39SAndroid Build Coastguard Worker UCPTRIE_VALUE_BITS_32, 167*0e209d39SAndroid Build Coastguard Worker /** 168*0e209d39SAndroid Build Coastguard Worker * The trie stores 8 bits per data value. 169*0e209d39SAndroid Build Coastguard Worker * It returns them as unsigned values 0..0xff=255. 170*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 171*0e209d39SAndroid Build Coastguard Worker */ 172*0e209d39SAndroid Build Coastguard Worker UCPTRIE_VALUE_BITS_8 173*0e209d39SAndroid Build Coastguard Worker }; 174*0e209d39SAndroid Build Coastguard Worker #ifndef U_IN_DOXYGEN 175*0e209d39SAndroid Build Coastguard Worker typedef enum UCPTrieValueWidth UCPTrieValueWidth; 176*0e209d39SAndroid Build Coastguard Worker #endif 177*0e209d39SAndroid Build Coastguard Worker 178*0e209d39SAndroid Build Coastguard Worker /** 179*0e209d39SAndroid Build Coastguard Worker * Opens a trie from its binary form, stored in 32-bit-aligned memory. 180*0e209d39SAndroid Build Coastguard Worker * Inverse of ucptrie_toBinary(). 181*0e209d39SAndroid Build Coastguard Worker * 182*0e209d39SAndroid Build Coastguard Worker * The memory must remain valid and unchanged as long as the trie is used. 183*0e209d39SAndroid Build Coastguard Worker * You must ucptrie_close() the trie once you are done using it. 184*0e209d39SAndroid Build Coastguard Worker * 185*0e209d39SAndroid Build Coastguard Worker * @param type selects the trie type; results in an 186*0e209d39SAndroid Build Coastguard Worker * U_INVALID_FORMAT_ERROR if it does not match the binary data; 187*0e209d39SAndroid Build Coastguard Worker * use UCPTRIE_TYPE_ANY to accept any type 188*0e209d39SAndroid Build Coastguard Worker * @param valueWidth selects the number of bits in a data value; results in an 189*0e209d39SAndroid Build Coastguard Worker * U_INVALID_FORMAT_ERROR if it does not match the binary data; 190*0e209d39SAndroid Build Coastguard Worker * use UCPTRIE_VALUE_BITS_ANY to accept any data value width 191*0e209d39SAndroid Build Coastguard Worker * @param data a pointer to 32-bit-aligned memory containing the binary data of a UCPTrie 192*0e209d39SAndroid Build Coastguard Worker * @param length the number of bytes available at data; 193*0e209d39SAndroid Build Coastguard Worker * can be more than necessary 194*0e209d39SAndroid Build Coastguard Worker * @param pActualLength receives the actual number of bytes at data taken up by the trie data; 195*0e209d39SAndroid Build Coastguard Worker * can be NULL 196*0e209d39SAndroid Build Coastguard Worker * @param pErrorCode an in/out ICU UErrorCode 197*0e209d39SAndroid Build Coastguard Worker * @return the trie 198*0e209d39SAndroid Build Coastguard Worker * 199*0e209d39SAndroid Build Coastguard Worker * @see umutablecptrie_open 200*0e209d39SAndroid Build Coastguard Worker * @see umutablecptrie_buildImmutable 201*0e209d39SAndroid Build Coastguard Worker * @see ucptrie_toBinary 202*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 203*0e209d39SAndroid Build Coastguard Worker */ 204*0e209d39SAndroid Build Coastguard Worker U_CAPI UCPTrie * U_EXPORT2 205*0e209d39SAndroid Build Coastguard Worker ucptrie_openFromBinary(UCPTrieType type, UCPTrieValueWidth valueWidth, 206*0e209d39SAndroid Build Coastguard Worker const void *data, int32_t length, int32_t *pActualLength, 207*0e209d39SAndroid Build Coastguard Worker UErrorCode *pErrorCode); 208*0e209d39SAndroid Build Coastguard Worker 209*0e209d39SAndroid Build Coastguard Worker /** 210*0e209d39SAndroid Build Coastguard Worker * Closes a trie and releases associated memory. 211*0e209d39SAndroid Build Coastguard Worker * 212*0e209d39SAndroid Build Coastguard Worker * @param trie the trie 213*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 214*0e209d39SAndroid Build Coastguard Worker */ 215*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 216*0e209d39SAndroid Build Coastguard Worker ucptrie_close(UCPTrie *trie); 217*0e209d39SAndroid Build Coastguard Worker 218*0e209d39SAndroid Build Coastguard Worker /** 219*0e209d39SAndroid Build Coastguard Worker * Returns the trie type. 220*0e209d39SAndroid Build Coastguard Worker * 221*0e209d39SAndroid Build Coastguard Worker * @param trie the trie 222*0e209d39SAndroid Build Coastguard Worker * @return the trie type 223*0e209d39SAndroid Build Coastguard Worker * @see ucptrie_openFromBinary 224*0e209d39SAndroid Build Coastguard Worker * @see UCPTRIE_TYPE_ANY 225*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 226*0e209d39SAndroid Build Coastguard Worker */ 227*0e209d39SAndroid Build Coastguard Worker U_CAPI UCPTrieType U_EXPORT2 228*0e209d39SAndroid Build Coastguard Worker ucptrie_getType(const UCPTrie *trie); 229*0e209d39SAndroid Build Coastguard Worker 230*0e209d39SAndroid Build Coastguard Worker /** 231*0e209d39SAndroid Build Coastguard Worker * Returns the number of bits in a trie data value. 232*0e209d39SAndroid Build Coastguard Worker * 233*0e209d39SAndroid Build Coastguard Worker * @param trie the trie 234*0e209d39SAndroid Build Coastguard Worker * @return the number of bits in a trie data value 235*0e209d39SAndroid Build Coastguard Worker * @see ucptrie_openFromBinary 236*0e209d39SAndroid Build Coastguard Worker * @see UCPTRIE_VALUE_BITS_ANY 237*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 238*0e209d39SAndroid Build Coastguard Worker */ 239*0e209d39SAndroid Build Coastguard Worker U_CAPI UCPTrieValueWidth U_EXPORT2 240*0e209d39SAndroid Build Coastguard Worker ucptrie_getValueWidth(const UCPTrie *trie); 241*0e209d39SAndroid Build Coastguard Worker 242*0e209d39SAndroid Build Coastguard Worker /** 243*0e209d39SAndroid Build Coastguard Worker * Returns the value for a code point as stored in the trie, with range checking. 244*0e209d39SAndroid Build Coastguard Worker * Returns the trie error value if c is not in the range 0..U+10FFFF. 245*0e209d39SAndroid Build Coastguard Worker * 246*0e209d39SAndroid Build Coastguard Worker * Easier to use than UCPTRIE_FAST_GET() and similar macros but slower. 247*0e209d39SAndroid Build Coastguard Worker * Easier to use because, unlike the macros, this function works on all UCPTrie 248*0e209d39SAndroid Build Coastguard Worker * objects, for all types and value widths. 249*0e209d39SAndroid Build Coastguard Worker * 250*0e209d39SAndroid Build Coastguard Worker * @param trie the trie 251*0e209d39SAndroid Build Coastguard Worker * @param c the code point 252*0e209d39SAndroid Build Coastguard Worker * @return the trie value, 253*0e209d39SAndroid Build Coastguard Worker * or the trie error value if the code point is not in the range 0..U+10FFFF 254*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 255*0e209d39SAndroid Build Coastguard Worker */ 256*0e209d39SAndroid Build Coastguard Worker U_CAPI uint32_t U_EXPORT2 257*0e209d39SAndroid Build Coastguard Worker ucptrie_get(const UCPTrie *trie, UChar32 c); 258*0e209d39SAndroid Build Coastguard Worker 259*0e209d39SAndroid Build Coastguard Worker /** 260*0e209d39SAndroid Build Coastguard Worker * Returns the last code point such that all those from start to there have the same value. 261*0e209d39SAndroid Build Coastguard Worker * Can be used to efficiently iterate over all same-value ranges in a trie. 262*0e209d39SAndroid Build Coastguard Worker * (This is normally faster than iterating over code points and get()ting each value, 263*0e209d39SAndroid Build Coastguard Worker * but much slower than a data structure that stores ranges directly.) 264*0e209d39SAndroid Build Coastguard Worker * 265*0e209d39SAndroid Build Coastguard Worker * If the UCPMapValueFilter function pointer is not NULL, then 266*0e209d39SAndroid Build Coastguard Worker * the value to be delivered is passed through that function, and the return value is the end 267*0e209d39SAndroid Build Coastguard Worker * of the range where all values are modified to the same actual value. 268*0e209d39SAndroid Build Coastguard Worker * The value is unchanged if that function pointer is NULL. 269*0e209d39SAndroid Build Coastguard Worker * 270*0e209d39SAndroid Build Coastguard Worker * Example: 271*0e209d39SAndroid Build Coastguard Worker * \code 272*0e209d39SAndroid Build Coastguard Worker * UChar32 start = 0, end; 273*0e209d39SAndroid Build Coastguard Worker * uint32_t value; 274*0e209d39SAndroid Build Coastguard Worker * while ((end = ucptrie_getRange(trie, start, UCPMAP_RANGE_NORMAL, 0, 275*0e209d39SAndroid Build Coastguard Worker * NULL, NULL, &value)) >= 0) { 276*0e209d39SAndroid Build Coastguard Worker * // Work with the range start..end and its value. 277*0e209d39SAndroid Build Coastguard Worker * start = end + 1; 278*0e209d39SAndroid Build Coastguard Worker * } 279*0e209d39SAndroid Build Coastguard Worker * \endcode 280*0e209d39SAndroid Build Coastguard Worker * 281*0e209d39SAndroid Build Coastguard Worker * @param trie the trie 282*0e209d39SAndroid Build Coastguard Worker * @param start range start 283*0e209d39SAndroid Build Coastguard Worker * @param option defines whether surrogates are treated normally, 284*0e209d39SAndroid Build Coastguard Worker * or as having the surrogateValue; usually UCPMAP_RANGE_NORMAL 285*0e209d39SAndroid Build Coastguard Worker * @param surrogateValue value for surrogates; ignored if option==UCPMAP_RANGE_NORMAL 286*0e209d39SAndroid Build Coastguard Worker * @param filter a pointer to a function that may modify the trie data value, 287*0e209d39SAndroid Build Coastguard Worker * or NULL if the values from the trie are to be used unmodified 288*0e209d39SAndroid Build Coastguard Worker * @param context an opaque pointer that is passed on to the filter function 289*0e209d39SAndroid Build Coastguard Worker * @param pValue if not NULL, receives the value that every code point start..end has; 290*0e209d39SAndroid Build Coastguard Worker * may have been modified by filter(context, trie value) 291*0e209d39SAndroid Build Coastguard Worker * if that function pointer is not NULL 292*0e209d39SAndroid Build Coastguard Worker * @return the range end code point, or -1 if start is not a valid code point 293*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 294*0e209d39SAndroid Build Coastguard Worker */ 295*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2 296*0e209d39SAndroid Build Coastguard Worker ucptrie_getRange(const UCPTrie *trie, UChar32 start, 297*0e209d39SAndroid Build Coastguard Worker UCPMapRangeOption option, uint32_t surrogateValue, 298*0e209d39SAndroid Build Coastguard Worker UCPMapValueFilter *filter, const void *context, uint32_t *pValue); 299*0e209d39SAndroid Build Coastguard Worker 300*0e209d39SAndroid Build Coastguard Worker /** 301*0e209d39SAndroid Build Coastguard Worker * Writes a memory-mappable form of the trie into 32-bit aligned memory. 302*0e209d39SAndroid Build Coastguard Worker * Inverse of ucptrie_openFromBinary(). 303*0e209d39SAndroid Build Coastguard Worker * 304*0e209d39SAndroid Build Coastguard Worker * @param trie the trie 305*0e209d39SAndroid Build Coastguard Worker * @param data a pointer to 32-bit-aligned memory to be filled with the trie data; 306*0e209d39SAndroid Build Coastguard Worker * can be NULL if capacity==0 307*0e209d39SAndroid Build Coastguard Worker * @param capacity the number of bytes available at data, or 0 for pure preflighting 308*0e209d39SAndroid Build Coastguard Worker * @param pErrorCode an in/out ICU UErrorCode; 309*0e209d39SAndroid Build Coastguard Worker * U_BUFFER_OVERFLOW_ERROR if the capacity is too small 310*0e209d39SAndroid Build Coastguard Worker * @return the number of bytes written or (if buffer overflow) needed for the trie 311*0e209d39SAndroid Build Coastguard Worker * 312*0e209d39SAndroid Build Coastguard Worker * @see ucptrie_openFromBinary() 313*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 314*0e209d39SAndroid Build Coastguard Worker */ 315*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2 316*0e209d39SAndroid Build Coastguard Worker ucptrie_toBinary(const UCPTrie *trie, void *data, int32_t capacity, UErrorCode *pErrorCode); 317*0e209d39SAndroid Build Coastguard Worker 318*0e209d39SAndroid Build Coastguard Worker /** 319*0e209d39SAndroid Build Coastguard Worker * Macro parameter value for a trie with 16-bit data values. 320*0e209d39SAndroid Build Coastguard Worker * Use the name of this macro as a "dataAccess" parameter in other macros. 321*0e209d39SAndroid Build Coastguard Worker * Do not use this macro in any other way. 322*0e209d39SAndroid Build Coastguard Worker * 323*0e209d39SAndroid Build Coastguard Worker * @see UCPTRIE_VALUE_BITS_16 324*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 325*0e209d39SAndroid Build Coastguard Worker */ 326*0e209d39SAndroid Build Coastguard Worker #define UCPTRIE_16(trie, i) ((trie)->data.ptr16[i]) 327*0e209d39SAndroid Build Coastguard Worker 328*0e209d39SAndroid Build Coastguard Worker /** 329*0e209d39SAndroid Build Coastguard Worker * Macro parameter value for a trie with 32-bit data values. 330*0e209d39SAndroid Build Coastguard Worker * Use the name of this macro as a "dataAccess" parameter in other macros. 331*0e209d39SAndroid Build Coastguard Worker * Do not use this macro in any other way. 332*0e209d39SAndroid Build Coastguard Worker * 333*0e209d39SAndroid Build Coastguard Worker * @see UCPTRIE_VALUE_BITS_32 334*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 335*0e209d39SAndroid Build Coastguard Worker */ 336*0e209d39SAndroid Build Coastguard Worker #define UCPTRIE_32(trie, i) ((trie)->data.ptr32[i]) 337*0e209d39SAndroid Build Coastguard Worker 338*0e209d39SAndroid Build Coastguard Worker /** 339*0e209d39SAndroid Build Coastguard Worker * Macro parameter value for a trie with 8-bit data values. 340*0e209d39SAndroid Build Coastguard Worker * Use the name of this macro as a "dataAccess" parameter in other macros. 341*0e209d39SAndroid Build Coastguard Worker * Do not use this macro in any other way. 342*0e209d39SAndroid Build Coastguard Worker * 343*0e209d39SAndroid Build Coastguard Worker * @see UCPTRIE_VALUE_BITS_8 344*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 345*0e209d39SAndroid Build Coastguard Worker */ 346*0e209d39SAndroid Build Coastguard Worker #define UCPTRIE_8(trie, i) ((trie)->data.ptr8[i]) 347*0e209d39SAndroid Build Coastguard Worker 348*0e209d39SAndroid Build Coastguard Worker /** 349*0e209d39SAndroid Build Coastguard Worker * Returns a trie value for a code point, with range checking. 350*0e209d39SAndroid Build Coastguard Worker * Returns the trie error value if c is not in the range 0..U+10FFFF. 351*0e209d39SAndroid Build Coastguard Worker * 352*0e209d39SAndroid Build Coastguard Worker * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 353*0e209d39SAndroid Build Coastguard Worker * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 354*0e209d39SAndroid Build Coastguard Worker * @param c (UChar32, in) the input code point 355*0e209d39SAndroid Build Coastguard Worker * @return The code point's trie value. 356*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 357*0e209d39SAndroid Build Coastguard Worker */ 358*0e209d39SAndroid Build Coastguard Worker #define UCPTRIE_FAST_GET(trie, dataAccess, c) dataAccess(trie, _UCPTRIE_CP_INDEX(trie, 0xffff, c)) 359*0e209d39SAndroid Build Coastguard Worker 360*0e209d39SAndroid Build Coastguard Worker /** 361*0e209d39SAndroid Build Coastguard Worker * Returns a 16-bit trie value for a code point, with range checking. 362*0e209d39SAndroid Build Coastguard Worker * Returns the trie error value if c is not in the range U+0000..U+10FFFF. 363*0e209d39SAndroid Build Coastguard Worker * 364*0e209d39SAndroid Build Coastguard Worker * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_SMALL 365*0e209d39SAndroid Build Coastguard Worker * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 366*0e209d39SAndroid Build Coastguard Worker * @param c (UChar32, in) the input code point 367*0e209d39SAndroid Build Coastguard Worker * @return The code point's trie value. 368*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 369*0e209d39SAndroid Build Coastguard Worker */ 370*0e209d39SAndroid Build Coastguard Worker #define UCPTRIE_SMALL_GET(trie, dataAccess, c) \ 371*0e209d39SAndroid Build Coastguard Worker dataAccess(trie, _UCPTRIE_CP_INDEX(trie, UCPTRIE_SMALL_MAX, c)) 372*0e209d39SAndroid Build Coastguard Worker 373*0e209d39SAndroid Build Coastguard Worker /** 374*0e209d39SAndroid Build Coastguard Worker * UTF-16: Reads the next code point (UChar32 c, out), post-increments src, 375*0e209d39SAndroid Build Coastguard Worker * and gets a value from the trie. 376*0e209d39SAndroid Build Coastguard Worker * Sets the trie error value if c is an unpaired surrogate. 377*0e209d39SAndroid Build Coastguard Worker * 378*0e209d39SAndroid Build Coastguard Worker * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 379*0e209d39SAndroid Build Coastguard Worker * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 380*0e209d39SAndroid Build Coastguard Worker * @param src (const UChar *, in/out) the source text pointer 381*0e209d39SAndroid Build Coastguard Worker * @param limit (const UChar *, in) the limit pointer for the text, or NULL if NUL-terminated 382*0e209d39SAndroid Build Coastguard Worker * @param c (UChar32, out) variable for the code point 383*0e209d39SAndroid Build Coastguard Worker * @param result (out) variable for the trie lookup result 384*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 385*0e209d39SAndroid Build Coastguard Worker */ 386*0e209d39SAndroid Build Coastguard Worker #define UCPTRIE_FAST_U16_NEXT(trie, dataAccess, src, limit, c, result) UPRV_BLOCK_MACRO_BEGIN { \ 387*0e209d39SAndroid Build Coastguard Worker (c) = *(src)++; \ 388*0e209d39SAndroid Build Coastguard Worker int32_t __index; \ 389*0e209d39SAndroid Build Coastguard Worker if (!U16_IS_SURROGATE(c)) { \ 390*0e209d39SAndroid Build Coastguard Worker __index = _UCPTRIE_FAST_INDEX(trie, c); \ 391*0e209d39SAndroid Build Coastguard Worker } else { \ 392*0e209d39SAndroid Build Coastguard Worker uint16_t __c2; \ 393*0e209d39SAndroid Build Coastguard Worker if (U16_IS_SURROGATE_LEAD(c) && (src) != (limit) && U16_IS_TRAIL(__c2 = *(src))) { \ 394*0e209d39SAndroid Build Coastguard Worker ++(src); \ 395*0e209d39SAndroid Build Coastguard Worker (c) = U16_GET_SUPPLEMENTARY((c), __c2); \ 396*0e209d39SAndroid Build Coastguard Worker __index = _UCPTRIE_SMALL_INDEX(trie, c); \ 397*0e209d39SAndroid Build Coastguard Worker } else { \ 398*0e209d39SAndroid Build Coastguard Worker __index = (trie)->dataLength - UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET; \ 399*0e209d39SAndroid Build Coastguard Worker } \ 400*0e209d39SAndroid Build Coastguard Worker } \ 401*0e209d39SAndroid Build Coastguard Worker (result) = dataAccess(trie, __index); \ 402*0e209d39SAndroid Build Coastguard Worker } UPRV_BLOCK_MACRO_END 403*0e209d39SAndroid Build Coastguard Worker 404*0e209d39SAndroid Build Coastguard Worker /** 405*0e209d39SAndroid Build Coastguard Worker * UTF-16: Reads the previous code point (UChar32 c, out), pre-decrements src, 406*0e209d39SAndroid Build Coastguard Worker * and gets a value from the trie. 407*0e209d39SAndroid Build Coastguard Worker * Sets the trie error value if c is an unpaired surrogate. 408*0e209d39SAndroid Build Coastguard Worker * 409*0e209d39SAndroid Build Coastguard Worker * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 410*0e209d39SAndroid Build Coastguard Worker * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 411*0e209d39SAndroid Build Coastguard Worker * @param start (const UChar *, in) the start pointer for the text 412*0e209d39SAndroid Build Coastguard Worker * @param src (const UChar *, in/out) the source text pointer 413*0e209d39SAndroid Build Coastguard Worker * @param c (UChar32, out) variable for the code point 414*0e209d39SAndroid Build Coastguard Worker * @param result (out) variable for the trie lookup result 415*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 416*0e209d39SAndroid Build Coastguard Worker */ 417*0e209d39SAndroid Build Coastguard Worker #define UCPTRIE_FAST_U16_PREV(trie, dataAccess, start, src, c, result) UPRV_BLOCK_MACRO_BEGIN { \ 418*0e209d39SAndroid Build Coastguard Worker (c) = *--(src); \ 419*0e209d39SAndroid Build Coastguard Worker int32_t __index; \ 420*0e209d39SAndroid Build Coastguard Worker if (!U16_IS_SURROGATE(c)) { \ 421*0e209d39SAndroid Build Coastguard Worker __index = _UCPTRIE_FAST_INDEX(trie, c); \ 422*0e209d39SAndroid Build Coastguard Worker } else { \ 423*0e209d39SAndroid Build Coastguard Worker uint16_t __c2; \ 424*0e209d39SAndroid Build Coastguard Worker if (U16_IS_SURROGATE_TRAIL(c) && (src) != (start) && U16_IS_LEAD(__c2 = *((src) - 1))) { \ 425*0e209d39SAndroid Build Coastguard Worker --(src); \ 426*0e209d39SAndroid Build Coastguard Worker (c) = U16_GET_SUPPLEMENTARY(__c2, (c)); \ 427*0e209d39SAndroid Build Coastguard Worker __index = _UCPTRIE_SMALL_INDEX(trie, c); \ 428*0e209d39SAndroid Build Coastguard Worker } else { \ 429*0e209d39SAndroid Build Coastguard Worker __index = (trie)->dataLength - UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET; \ 430*0e209d39SAndroid Build Coastguard Worker } \ 431*0e209d39SAndroid Build Coastguard Worker } \ 432*0e209d39SAndroid Build Coastguard Worker (result) = dataAccess(trie, __index); \ 433*0e209d39SAndroid Build Coastguard Worker } UPRV_BLOCK_MACRO_END 434*0e209d39SAndroid Build Coastguard Worker 435*0e209d39SAndroid Build Coastguard Worker /** 436*0e209d39SAndroid Build Coastguard Worker * UTF-8: Post-increments src and gets a value from the trie. 437*0e209d39SAndroid Build Coastguard Worker * Sets the trie error value for an ill-formed byte sequence. 438*0e209d39SAndroid Build Coastguard Worker * 439*0e209d39SAndroid Build Coastguard Worker * Unlike UCPTRIE_FAST_U16_NEXT() this UTF-8 macro does not provide the code point 440*0e209d39SAndroid Build Coastguard Worker * because it would be more work to do so and is often not needed. 441*0e209d39SAndroid Build Coastguard Worker * If the trie value differs from the error value, then the byte sequence is well-formed, 442*0e209d39SAndroid Build Coastguard Worker * and the code point can be assembled without revalidation. 443*0e209d39SAndroid Build Coastguard Worker * 444*0e209d39SAndroid Build Coastguard Worker * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 445*0e209d39SAndroid Build Coastguard Worker * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 446*0e209d39SAndroid Build Coastguard Worker * @param src (const char *, in/out) the source text pointer 447*0e209d39SAndroid Build Coastguard Worker * @param limit (const char *, in) the limit pointer for the text (must not be NULL) 448*0e209d39SAndroid Build Coastguard Worker * @param result (out) variable for the trie lookup result 449*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 450*0e209d39SAndroid Build Coastguard Worker */ 451*0e209d39SAndroid Build Coastguard Worker #define UCPTRIE_FAST_U8_NEXT(trie, dataAccess, src, limit, result) UPRV_BLOCK_MACRO_BEGIN { \ 452*0e209d39SAndroid Build Coastguard Worker int32_t __lead = (uint8_t)*(src)++; \ 453*0e209d39SAndroid Build Coastguard Worker if (!U8_IS_SINGLE(__lead)) { \ 454*0e209d39SAndroid Build Coastguard Worker uint8_t __t1, __t2, __t3; \ 455*0e209d39SAndroid Build Coastguard Worker if ((src) != (limit) && \ 456*0e209d39SAndroid Build Coastguard Worker (__lead >= 0xe0 ? \ 457*0e209d39SAndroid Build Coastguard Worker __lead < 0xf0 ? /* U+0800..U+FFFF except surrogates */ \ 458*0e209d39SAndroid Build Coastguard Worker U8_LEAD3_T1_BITS[__lead &= 0xf] & (1 << ((__t1 = *(src)) >> 5)) && \ 459*0e209d39SAndroid Build Coastguard Worker ++(src) != (limit) && (__t2 = *(src) - 0x80) <= 0x3f && \ 460*0e209d39SAndroid Build Coastguard Worker (__lead = ((int32_t)(trie)->index[(__lead << 6) + (__t1 & 0x3f)]) + __t2, 1) \ 461*0e209d39SAndroid Build Coastguard Worker : /* U+10000..U+10FFFF */ \ 462*0e209d39SAndroid Build Coastguard Worker (__lead -= 0xf0) <= 4 && \ 463*0e209d39SAndroid Build Coastguard Worker U8_LEAD4_T1_BITS[(__t1 = *(src)) >> 4] & (1 << __lead) && \ 464*0e209d39SAndroid Build Coastguard Worker (__lead = (__lead << 6) | (__t1 & 0x3f), ++(src) != (limit)) && \ 465*0e209d39SAndroid Build Coastguard Worker (__t2 = *(src) - 0x80) <= 0x3f && \ 466*0e209d39SAndroid Build Coastguard Worker ++(src) != (limit) && (__t3 = *(src) - 0x80) <= 0x3f && \ 467*0e209d39SAndroid Build Coastguard Worker (__lead = __lead >= (trie)->shifted12HighStart ? \ 468*0e209d39SAndroid Build Coastguard Worker (trie)->dataLength - UCPTRIE_HIGH_VALUE_NEG_DATA_OFFSET : \ 469*0e209d39SAndroid Build Coastguard Worker ucptrie_internalSmallU8Index((trie), __lead, __t2, __t3), 1) \ 470*0e209d39SAndroid Build Coastguard Worker : /* U+0080..U+07FF */ \ 471*0e209d39SAndroid Build Coastguard Worker __lead >= 0xc2 && (__t1 = *(src) - 0x80) <= 0x3f && \ 472*0e209d39SAndroid Build Coastguard Worker (__lead = (int32_t)(trie)->index[__lead & 0x1f] + __t1, 1))) { \ 473*0e209d39SAndroid Build Coastguard Worker ++(src); \ 474*0e209d39SAndroid Build Coastguard Worker } else { \ 475*0e209d39SAndroid Build Coastguard Worker __lead = (trie)->dataLength - UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET; /* ill-formed*/ \ 476*0e209d39SAndroid Build Coastguard Worker } \ 477*0e209d39SAndroid Build Coastguard Worker } \ 478*0e209d39SAndroid Build Coastguard Worker (result) = dataAccess(trie, __lead); \ 479*0e209d39SAndroid Build Coastguard Worker } UPRV_BLOCK_MACRO_END 480*0e209d39SAndroid Build Coastguard Worker 481*0e209d39SAndroid Build Coastguard Worker /** 482*0e209d39SAndroid Build Coastguard Worker * UTF-8: Pre-decrements src and gets a value from the trie. 483*0e209d39SAndroid Build Coastguard Worker * Sets the trie error value for an ill-formed byte sequence. 484*0e209d39SAndroid Build Coastguard Worker * 485*0e209d39SAndroid Build Coastguard Worker * Unlike UCPTRIE_FAST_U16_PREV() this UTF-8 macro does not provide the code point 486*0e209d39SAndroid Build Coastguard Worker * because it would be more work to do so and is often not needed. 487*0e209d39SAndroid Build Coastguard Worker * If the trie value differs from the error value, then the byte sequence is well-formed, 488*0e209d39SAndroid Build Coastguard Worker * and the code point can be assembled without revalidation. 489*0e209d39SAndroid Build Coastguard Worker * 490*0e209d39SAndroid Build Coastguard Worker * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 491*0e209d39SAndroid Build Coastguard Worker * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 492*0e209d39SAndroid Build Coastguard Worker * @param start (const char *, in) the start pointer for the text 493*0e209d39SAndroid Build Coastguard Worker * @param src (const char *, in/out) the source text pointer 494*0e209d39SAndroid Build Coastguard Worker * @param result (out) variable for the trie lookup result 495*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 496*0e209d39SAndroid Build Coastguard Worker */ 497*0e209d39SAndroid Build Coastguard Worker #define UCPTRIE_FAST_U8_PREV(trie, dataAccess, start, src, result) UPRV_BLOCK_MACRO_BEGIN { \ 498*0e209d39SAndroid Build Coastguard Worker int32_t __index = (uint8_t)*--(src); \ 499*0e209d39SAndroid Build Coastguard Worker if (!U8_IS_SINGLE(__index)) { \ 500*0e209d39SAndroid Build Coastguard Worker __index = ucptrie_internalU8PrevIndex((trie), __index, (const uint8_t *)(start), \ 501*0e209d39SAndroid Build Coastguard Worker (const uint8_t *)(src)); \ 502*0e209d39SAndroid Build Coastguard Worker (src) -= __index & 7; \ 503*0e209d39SAndroid Build Coastguard Worker __index >>= 3; \ 504*0e209d39SAndroid Build Coastguard Worker } \ 505*0e209d39SAndroid Build Coastguard Worker (result) = dataAccess(trie, __index); \ 506*0e209d39SAndroid Build Coastguard Worker } UPRV_BLOCK_MACRO_END 507*0e209d39SAndroid Build Coastguard Worker 508*0e209d39SAndroid Build Coastguard Worker /** 509*0e209d39SAndroid Build Coastguard Worker * Returns a trie value for an ASCII code point, without range checking. 510*0e209d39SAndroid Build Coastguard Worker * 511*0e209d39SAndroid Build Coastguard Worker * @param trie (const UCPTrie *, in) the trie (of either fast or small type) 512*0e209d39SAndroid Build Coastguard Worker * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 513*0e209d39SAndroid Build Coastguard Worker * @param c (UChar32, in) the input code point; must be U+0000..U+007F 514*0e209d39SAndroid Build Coastguard Worker * @return The ASCII code point's trie value. 515*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 516*0e209d39SAndroid Build Coastguard Worker */ 517*0e209d39SAndroid Build Coastguard Worker #define UCPTRIE_ASCII_GET(trie, dataAccess, c) dataAccess(trie, c) 518*0e209d39SAndroid Build Coastguard Worker 519*0e209d39SAndroid Build Coastguard Worker /** 520*0e209d39SAndroid Build Coastguard Worker * Returns a trie value for a BMP code point (U+0000..U+FFFF), without range checking. 521*0e209d39SAndroid Build Coastguard Worker * Can be used to look up a value for a UTF-16 code unit if other parts of 522*0e209d39SAndroid Build Coastguard Worker * the string processing check for surrogates. 523*0e209d39SAndroid Build Coastguard Worker * 524*0e209d39SAndroid Build Coastguard Worker * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 525*0e209d39SAndroid Build Coastguard Worker * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 526*0e209d39SAndroid Build Coastguard Worker * @param c (UChar32, in) the input code point, must be U+0000..U+FFFF 527*0e209d39SAndroid Build Coastguard Worker * @return The BMP code point's trie value. 528*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 529*0e209d39SAndroid Build Coastguard Worker */ 530*0e209d39SAndroid Build Coastguard Worker #define UCPTRIE_FAST_BMP_GET(trie, dataAccess, c) dataAccess(trie, _UCPTRIE_FAST_INDEX(trie, c)) 531*0e209d39SAndroid Build Coastguard Worker 532*0e209d39SAndroid Build Coastguard Worker /** 533*0e209d39SAndroid Build Coastguard Worker * Returns a trie value for a supplementary code point (U+10000..U+10FFFF), 534*0e209d39SAndroid Build Coastguard Worker * without range checking. 535*0e209d39SAndroid Build Coastguard Worker * 536*0e209d39SAndroid Build Coastguard Worker * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 537*0e209d39SAndroid Build Coastguard Worker * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 538*0e209d39SAndroid Build Coastguard Worker * @param c (UChar32, in) the input code point, must be U+10000..U+10FFFF 539*0e209d39SAndroid Build Coastguard Worker * @return The supplementary code point's trie value. 540*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 541*0e209d39SAndroid Build Coastguard Worker */ 542*0e209d39SAndroid Build Coastguard Worker #define UCPTRIE_FAST_SUPP_GET(trie, dataAccess, c) dataAccess(trie, _UCPTRIE_SMALL_INDEX(trie, c)) 543*0e209d39SAndroid Build Coastguard Worker 544*0e209d39SAndroid Build Coastguard Worker /* Internal definitions ----------------------------------------------------- */ 545*0e209d39SAndroid Build Coastguard Worker 546*0e209d39SAndroid Build Coastguard Worker #ifndef U_IN_DOXYGEN 547*0e209d39SAndroid Build Coastguard Worker 548*0e209d39SAndroid Build Coastguard Worker /** 549*0e209d39SAndroid Build Coastguard Worker * Internal implementation constants. 550*0e209d39SAndroid Build Coastguard Worker * These are needed for the API macros, but users should not use these directly. 551*0e209d39SAndroid Build Coastguard Worker * @internal 552*0e209d39SAndroid Build Coastguard Worker */ 553*0e209d39SAndroid Build Coastguard Worker enum { 554*0e209d39SAndroid Build Coastguard Worker /** @internal */ 555*0e209d39SAndroid Build Coastguard Worker UCPTRIE_FAST_SHIFT = 6, 556*0e209d39SAndroid Build Coastguard Worker 557*0e209d39SAndroid Build Coastguard Worker /** Number of entries in a data block for code points below the fast limit. 64=0x40 @internal */ 558*0e209d39SAndroid Build Coastguard Worker UCPTRIE_FAST_DATA_BLOCK_LENGTH = 1 << UCPTRIE_FAST_SHIFT, 559*0e209d39SAndroid Build Coastguard Worker 560*0e209d39SAndroid Build Coastguard Worker /** Mask for getting the lower bits for the in-fast-data-block offset. @internal */ 561*0e209d39SAndroid Build Coastguard Worker UCPTRIE_FAST_DATA_MASK = UCPTRIE_FAST_DATA_BLOCK_LENGTH - 1, 562*0e209d39SAndroid Build Coastguard Worker 563*0e209d39SAndroid Build Coastguard Worker /** @internal */ 564*0e209d39SAndroid Build Coastguard Worker UCPTRIE_SMALL_MAX = 0xfff, 565*0e209d39SAndroid Build Coastguard Worker 566*0e209d39SAndroid Build Coastguard Worker /** 567*0e209d39SAndroid Build Coastguard Worker * Offset from dataLength (to be subtracted) for fetching the 568*0e209d39SAndroid Build Coastguard Worker * value returned for out-of-range code points and ill-formed UTF-8/16. 569*0e209d39SAndroid Build Coastguard Worker * @internal 570*0e209d39SAndroid Build Coastguard Worker */ 571*0e209d39SAndroid Build Coastguard Worker UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET = 1, 572*0e209d39SAndroid Build Coastguard Worker /** 573*0e209d39SAndroid Build Coastguard Worker * Offset from dataLength (to be subtracted) for fetching the 574*0e209d39SAndroid Build Coastguard Worker * value returned for code points highStart..U+10FFFF. 575*0e209d39SAndroid Build Coastguard Worker * @internal 576*0e209d39SAndroid Build Coastguard Worker */ 577*0e209d39SAndroid Build Coastguard Worker UCPTRIE_HIGH_VALUE_NEG_DATA_OFFSET = 2 578*0e209d39SAndroid Build Coastguard Worker }; 579*0e209d39SAndroid Build Coastguard Worker 580*0e209d39SAndroid Build Coastguard Worker /* Internal functions and macros -------------------------------------------- */ 581*0e209d39SAndroid Build Coastguard Worker // Do not conditionalize with #ifndef U_HIDE_INTERNAL_API, needed for public API 582*0e209d39SAndroid Build Coastguard Worker 583*0e209d39SAndroid Build Coastguard Worker /** @internal */ 584*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2 585*0e209d39SAndroid Build Coastguard Worker ucptrie_internalSmallIndex(const UCPTrie *trie, UChar32 c); 586*0e209d39SAndroid Build Coastguard Worker 587*0e209d39SAndroid Build Coastguard Worker /** @internal */ 588*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2 589*0e209d39SAndroid Build Coastguard Worker ucptrie_internalSmallU8Index(const UCPTrie *trie, int32_t lt1, uint8_t t2, uint8_t t3); 590*0e209d39SAndroid Build Coastguard Worker 591*0e209d39SAndroid Build Coastguard Worker /** 592*0e209d39SAndroid Build Coastguard Worker * Internal function for part of the UCPTRIE_FAST_U8_PREVxx() macro implementations. 593*0e209d39SAndroid Build Coastguard Worker * Do not call directly. 594*0e209d39SAndroid Build Coastguard Worker * @internal 595*0e209d39SAndroid Build Coastguard Worker */ 596*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2 597*0e209d39SAndroid Build Coastguard Worker ucptrie_internalU8PrevIndex(const UCPTrie *trie, UChar32 c, 598*0e209d39SAndroid Build Coastguard Worker const uint8_t *start, const uint8_t *src); 599*0e209d39SAndroid Build Coastguard Worker 600*0e209d39SAndroid Build Coastguard Worker /** Internal trie getter for a code point below the fast limit. Returns the data index. @internal */ 601*0e209d39SAndroid Build Coastguard Worker #define _UCPTRIE_FAST_INDEX(trie, c) \ 602*0e209d39SAndroid Build Coastguard Worker ((int32_t)(trie)->index[(c) >> UCPTRIE_FAST_SHIFT] + ((c) & UCPTRIE_FAST_DATA_MASK)) 603*0e209d39SAndroid Build Coastguard Worker 604*0e209d39SAndroid Build Coastguard Worker /** Internal trie getter for a code point at or above the fast limit. Returns the data index. @internal */ 605*0e209d39SAndroid Build Coastguard Worker #define _UCPTRIE_SMALL_INDEX(trie, c) \ 606*0e209d39SAndroid Build Coastguard Worker ((c) >= (trie)->highStart ? \ 607*0e209d39SAndroid Build Coastguard Worker (trie)->dataLength - UCPTRIE_HIGH_VALUE_NEG_DATA_OFFSET : \ 608*0e209d39SAndroid Build Coastguard Worker ucptrie_internalSmallIndex(trie, c)) 609*0e209d39SAndroid Build Coastguard Worker 610*0e209d39SAndroid Build Coastguard Worker /** 611*0e209d39SAndroid Build Coastguard Worker * Internal trie getter for a code point, with checking that c is in U+0000..10FFFF. 612*0e209d39SAndroid Build Coastguard Worker * Returns the data index. 613*0e209d39SAndroid Build Coastguard Worker * @internal 614*0e209d39SAndroid Build Coastguard Worker */ 615*0e209d39SAndroid Build Coastguard Worker #define _UCPTRIE_CP_INDEX(trie, fastMax, c) \ 616*0e209d39SAndroid Build Coastguard Worker ((uint32_t)(c) <= (uint32_t)(fastMax) ? \ 617*0e209d39SAndroid Build Coastguard Worker _UCPTRIE_FAST_INDEX(trie, c) : \ 618*0e209d39SAndroid Build Coastguard Worker (uint32_t)(c) <= 0x10ffff ? \ 619*0e209d39SAndroid Build Coastguard Worker _UCPTRIE_SMALL_INDEX(trie, c) : \ 620*0e209d39SAndroid Build Coastguard Worker (trie)->dataLength - UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET) 621*0e209d39SAndroid Build Coastguard Worker 622*0e209d39SAndroid Build Coastguard Worker U_CDECL_END 623*0e209d39SAndroid Build Coastguard Worker 624*0e209d39SAndroid Build Coastguard Worker #endif // U_IN_DOXYGEN 625*0e209d39SAndroid Build Coastguard Worker 626*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API 627*0e209d39SAndroid Build Coastguard Worker 628*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN 629*0e209d39SAndroid Build Coastguard Worker 630*0e209d39SAndroid Build Coastguard Worker /** 631*0e209d39SAndroid Build Coastguard Worker * \class LocalUCPTriePointer 632*0e209d39SAndroid Build Coastguard Worker * "Smart pointer" class, closes a UCPTrie via ucptrie_close(). 633*0e209d39SAndroid Build Coastguard Worker * For most methods see the LocalPointerBase base class. 634*0e209d39SAndroid Build Coastguard Worker * 635*0e209d39SAndroid Build Coastguard Worker * @see LocalPointerBase 636*0e209d39SAndroid Build Coastguard Worker * @see LocalPointer 637*0e209d39SAndroid Build Coastguard Worker * @stable ICU 63 638*0e209d39SAndroid Build Coastguard Worker */ 639*0e209d39SAndroid Build Coastguard Worker U_DEFINE_LOCAL_OPEN_POINTER(LocalUCPTriePointer, UCPTrie, ucptrie_close); 640*0e209d39SAndroid Build Coastguard Worker 641*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END 642*0e209d39SAndroid Build Coastguard Worker 643*0e209d39SAndroid Build Coastguard Worker #endif // U_SHOW_CPLUSPLUS_API 644*0e209d39SAndroid Build Coastguard Worker 645*0e209d39SAndroid Build Coastguard Worker #endif 646