11cb0ef41Sopenharmony_ci// © 2017 and later: Unicode, Inc. and others. 21cb0ef41Sopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ci// ucptrie.h (modified from utrie2.h) 51cb0ef41Sopenharmony_ci// created: 2017dec29 Markus W. Scherer 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci#ifndef __UCPTRIE_H__ 81cb0ef41Sopenharmony_ci#define __UCPTRIE_H__ 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci#include "unicode/utypes.h" 111cb0ef41Sopenharmony_ci#include "unicode/ucpmap.h" 121cb0ef41Sopenharmony_ci#include "unicode/utf8.h" 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci#if U_SHOW_CPLUSPLUS_API 151cb0ef41Sopenharmony_ci#include "unicode/localpointer.h" 161cb0ef41Sopenharmony_ci#endif // U_SHOW_CPLUSPLUS_API 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ciU_CDECL_BEGIN 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci/** 211cb0ef41Sopenharmony_ci * \file 221cb0ef41Sopenharmony_ci * \brief C API: This file defines an immutable Unicode code point trie. 231cb0ef41Sopenharmony_ci * 241cb0ef41Sopenharmony_ci * @see UCPTrie 251cb0ef41Sopenharmony_ci * @see UMutableCPTrie 261cb0ef41Sopenharmony_ci */ 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci#ifndef U_IN_DOXYGEN 291cb0ef41Sopenharmony_ci/** @internal */ 301cb0ef41Sopenharmony_citypedef union UCPTrieData { 311cb0ef41Sopenharmony_ci /** @internal */ 321cb0ef41Sopenharmony_ci const void *ptr0; 331cb0ef41Sopenharmony_ci /** @internal */ 341cb0ef41Sopenharmony_ci const uint16_t *ptr16; 351cb0ef41Sopenharmony_ci /** @internal */ 361cb0ef41Sopenharmony_ci const uint32_t *ptr32; 371cb0ef41Sopenharmony_ci /** @internal */ 381cb0ef41Sopenharmony_ci const uint8_t *ptr8; 391cb0ef41Sopenharmony_ci} UCPTrieData; 401cb0ef41Sopenharmony_ci#endif 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci/** 431cb0ef41Sopenharmony_ci * Immutable Unicode code point trie structure. 441cb0ef41Sopenharmony_ci * Fast, reasonably compact, map from Unicode code points (U+0000..U+10FFFF) to integer values. 451cb0ef41Sopenharmony_ci * For details see https://icu.unicode.org/design/struct/utrie 461cb0ef41Sopenharmony_ci * 471cb0ef41Sopenharmony_ci * Do not access UCPTrie fields directly; use public functions and macros. 481cb0ef41Sopenharmony_ci * Functions are easy to use: They support all trie types and value widths. 491cb0ef41Sopenharmony_ci * 501cb0ef41Sopenharmony_ci * When performance is really important, macros provide faster access. 511cb0ef41Sopenharmony_ci * Most macros are specific to either "fast" or "small" tries, see UCPTrieType. 521cb0ef41Sopenharmony_ci * There are "fast" macros for special optimized use cases. 531cb0ef41Sopenharmony_ci * 541cb0ef41Sopenharmony_ci * The macros will return bogus values, or may crash, if used on the wrong type or value width. 551cb0ef41Sopenharmony_ci * 561cb0ef41Sopenharmony_ci * @see UMutableCPTrie 571cb0ef41Sopenharmony_ci * @stable ICU 63 581cb0ef41Sopenharmony_ci */ 591cb0ef41Sopenharmony_cistruct UCPTrie { 601cb0ef41Sopenharmony_ci#ifndef U_IN_DOXYGEN 611cb0ef41Sopenharmony_ci /** @internal */ 621cb0ef41Sopenharmony_ci const uint16_t *index; 631cb0ef41Sopenharmony_ci /** @internal */ 641cb0ef41Sopenharmony_ci UCPTrieData data; 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ci /** @internal */ 671cb0ef41Sopenharmony_ci int32_t indexLength; 681cb0ef41Sopenharmony_ci /** @internal */ 691cb0ef41Sopenharmony_ci int32_t dataLength; 701cb0ef41Sopenharmony_ci /** Start of the last range which ends at U+10FFFF. @internal */ 711cb0ef41Sopenharmony_ci UChar32 highStart; 721cb0ef41Sopenharmony_ci /** highStart>>12 @internal */ 731cb0ef41Sopenharmony_ci uint16_t shifted12HighStart; 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci /** @internal */ 761cb0ef41Sopenharmony_ci int8_t type; // UCPTrieType 771cb0ef41Sopenharmony_ci /** @internal */ 781cb0ef41Sopenharmony_ci int8_t valueWidth; // UCPTrieValueWidth 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_ci /** padding/reserved @internal */ 811cb0ef41Sopenharmony_ci uint32_t reserved32; 821cb0ef41Sopenharmony_ci /** padding/reserved @internal */ 831cb0ef41Sopenharmony_ci uint16_t reserved16; 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ci /** 861cb0ef41Sopenharmony_ci * Internal index-3 null block offset. 871cb0ef41Sopenharmony_ci * Set to an impossibly high value (e.g., 0xffff) if there is no dedicated index-3 null block. 881cb0ef41Sopenharmony_ci * @internal 891cb0ef41Sopenharmony_ci */ 901cb0ef41Sopenharmony_ci uint16_t index3NullOffset; 911cb0ef41Sopenharmony_ci /** 921cb0ef41Sopenharmony_ci * Internal data null block offset, not shifted. 931cb0ef41Sopenharmony_ci * Set to an impossibly high value (e.g., 0xfffff) if there is no dedicated data null block. 941cb0ef41Sopenharmony_ci * @internal 951cb0ef41Sopenharmony_ci */ 961cb0ef41Sopenharmony_ci int32_t dataNullOffset; 971cb0ef41Sopenharmony_ci /** @internal */ 981cb0ef41Sopenharmony_ci uint32_t nullValue; 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ci#ifdef UCPTRIE_DEBUG 1011cb0ef41Sopenharmony_ci /** @internal */ 1021cb0ef41Sopenharmony_ci const char *name; 1031cb0ef41Sopenharmony_ci#endif 1041cb0ef41Sopenharmony_ci#endif 1051cb0ef41Sopenharmony_ci}; 1061cb0ef41Sopenharmony_ci#ifndef U_IN_DOXYGEN 1071cb0ef41Sopenharmony_citypedef struct UCPTrie UCPTrie; 1081cb0ef41Sopenharmony_ci#endif 1091cb0ef41Sopenharmony_ci 1101cb0ef41Sopenharmony_ci/** 1111cb0ef41Sopenharmony_ci * Selectors for the type of a UCPTrie. 1121cb0ef41Sopenharmony_ci * Different trade-offs for size vs. speed. 1131cb0ef41Sopenharmony_ci * 1141cb0ef41Sopenharmony_ci * @see umutablecptrie_buildImmutable 1151cb0ef41Sopenharmony_ci * @see ucptrie_openFromBinary 1161cb0ef41Sopenharmony_ci * @see ucptrie_getType 1171cb0ef41Sopenharmony_ci * @stable ICU 63 1181cb0ef41Sopenharmony_ci */ 1191cb0ef41Sopenharmony_cienum UCPTrieType { 1201cb0ef41Sopenharmony_ci /** 1211cb0ef41Sopenharmony_ci * For ucptrie_openFromBinary() to accept any type. 1221cb0ef41Sopenharmony_ci * ucptrie_getType() will return the actual type. 1231cb0ef41Sopenharmony_ci * @stable ICU 63 1241cb0ef41Sopenharmony_ci */ 1251cb0ef41Sopenharmony_ci UCPTRIE_TYPE_ANY = -1, 1261cb0ef41Sopenharmony_ci /** 1271cb0ef41Sopenharmony_ci * Fast/simple/larger BMP data structure. Use functions and "fast" macros. 1281cb0ef41Sopenharmony_ci * @stable ICU 63 1291cb0ef41Sopenharmony_ci */ 1301cb0ef41Sopenharmony_ci UCPTRIE_TYPE_FAST, 1311cb0ef41Sopenharmony_ci /** 1321cb0ef41Sopenharmony_ci * Small/slower BMP data structure. Use functions and "small" macros. 1331cb0ef41Sopenharmony_ci * @stable ICU 63 1341cb0ef41Sopenharmony_ci */ 1351cb0ef41Sopenharmony_ci UCPTRIE_TYPE_SMALL 1361cb0ef41Sopenharmony_ci}; 1371cb0ef41Sopenharmony_ci#ifndef U_IN_DOXYGEN 1381cb0ef41Sopenharmony_citypedef enum UCPTrieType UCPTrieType; 1391cb0ef41Sopenharmony_ci#endif 1401cb0ef41Sopenharmony_ci 1411cb0ef41Sopenharmony_ci/** 1421cb0ef41Sopenharmony_ci * Selectors for the number of bits in a UCPTrie data value. 1431cb0ef41Sopenharmony_ci * 1441cb0ef41Sopenharmony_ci * @see umutablecptrie_buildImmutable 1451cb0ef41Sopenharmony_ci * @see ucptrie_openFromBinary 1461cb0ef41Sopenharmony_ci * @see ucptrie_getValueWidth 1471cb0ef41Sopenharmony_ci * @stable ICU 63 1481cb0ef41Sopenharmony_ci */ 1491cb0ef41Sopenharmony_cienum UCPTrieValueWidth { 1501cb0ef41Sopenharmony_ci /** 1511cb0ef41Sopenharmony_ci * For ucptrie_openFromBinary() to accept any data value width. 1521cb0ef41Sopenharmony_ci * ucptrie_getValueWidth() will return the actual data value width. 1531cb0ef41Sopenharmony_ci * @stable ICU 63 1541cb0ef41Sopenharmony_ci */ 1551cb0ef41Sopenharmony_ci UCPTRIE_VALUE_BITS_ANY = -1, 1561cb0ef41Sopenharmony_ci /** 1571cb0ef41Sopenharmony_ci * The trie stores 16 bits per data value. 1581cb0ef41Sopenharmony_ci * It returns them as unsigned values 0..0xffff=65535. 1591cb0ef41Sopenharmony_ci * @stable ICU 63 1601cb0ef41Sopenharmony_ci */ 1611cb0ef41Sopenharmony_ci UCPTRIE_VALUE_BITS_16, 1621cb0ef41Sopenharmony_ci /** 1631cb0ef41Sopenharmony_ci * The trie stores 32 bits per data value. 1641cb0ef41Sopenharmony_ci * @stable ICU 63 1651cb0ef41Sopenharmony_ci */ 1661cb0ef41Sopenharmony_ci UCPTRIE_VALUE_BITS_32, 1671cb0ef41Sopenharmony_ci /** 1681cb0ef41Sopenharmony_ci * The trie stores 8 bits per data value. 1691cb0ef41Sopenharmony_ci * It returns them as unsigned values 0..0xff=255. 1701cb0ef41Sopenharmony_ci * @stable ICU 63 1711cb0ef41Sopenharmony_ci */ 1721cb0ef41Sopenharmony_ci UCPTRIE_VALUE_BITS_8 1731cb0ef41Sopenharmony_ci}; 1741cb0ef41Sopenharmony_ci#ifndef U_IN_DOXYGEN 1751cb0ef41Sopenharmony_citypedef enum UCPTrieValueWidth UCPTrieValueWidth; 1761cb0ef41Sopenharmony_ci#endif 1771cb0ef41Sopenharmony_ci 1781cb0ef41Sopenharmony_ci/** 1791cb0ef41Sopenharmony_ci * Opens a trie from its binary form, stored in 32-bit-aligned memory. 1801cb0ef41Sopenharmony_ci * Inverse of ucptrie_toBinary(). 1811cb0ef41Sopenharmony_ci * 1821cb0ef41Sopenharmony_ci * The memory must remain valid and unchanged as long as the trie is used. 1831cb0ef41Sopenharmony_ci * You must ucptrie_close() the trie once you are done using it. 1841cb0ef41Sopenharmony_ci * 1851cb0ef41Sopenharmony_ci * @param type selects the trie type; results in an 1861cb0ef41Sopenharmony_ci * U_INVALID_FORMAT_ERROR if it does not match the binary data; 1871cb0ef41Sopenharmony_ci * use UCPTRIE_TYPE_ANY to accept any type 1881cb0ef41Sopenharmony_ci * @param valueWidth selects the number of bits in a data value; results in an 1891cb0ef41Sopenharmony_ci * U_INVALID_FORMAT_ERROR if it does not match the binary data; 1901cb0ef41Sopenharmony_ci * use UCPTRIE_VALUE_BITS_ANY to accept any data value width 1911cb0ef41Sopenharmony_ci * @param data a pointer to 32-bit-aligned memory containing the binary data of a UCPTrie 1921cb0ef41Sopenharmony_ci * @param length the number of bytes available at data; 1931cb0ef41Sopenharmony_ci * can be more than necessary 1941cb0ef41Sopenharmony_ci * @param pActualLength receives the actual number of bytes at data taken up by the trie data; 1951cb0ef41Sopenharmony_ci * can be NULL 1961cb0ef41Sopenharmony_ci * @param pErrorCode an in/out ICU UErrorCode 1971cb0ef41Sopenharmony_ci * @return the trie 1981cb0ef41Sopenharmony_ci * 1991cb0ef41Sopenharmony_ci * @see umutablecptrie_open 2001cb0ef41Sopenharmony_ci * @see umutablecptrie_buildImmutable 2011cb0ef41Sopenharmony_ci * @see ucptrie_toBinary 2021cb0ef41Sopenharmony_ci * @stable ICU 63 2031cb0ef41Sopenharmony_ci */ 2041cb0ef41Sopenharmony_ciU_CAPI UCPTrie * U_EXPORT2 2051cb0ef41Sopenharmony_ciucptrie_openFromBinary(UCPTrieType type, UCPTrieValueWidth valueWidth, 2061cb0ef41Sopenharmony_ci const void *data, int32_t length, int32_t *pActualLength, 2071cb0ef41Sopenharmony_ci UErrorCode *pErrorCode); 2081cb0ef41Sopenharmony_ci 2091cb0ef41Sopenharmony_ci/** 2101cb0ef41Sopenharmony_ci * Closes a trie and releases associated memory. 2111cb0ef41Sopenharmony_ci * 2121cb0ef41Sopenharmony_ci * @param trie the trie 2131cb0ef41Sopenharmony_ci * @stable ICU 63 2141cb0ef41Sopenharmony_ci */ 2151cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2 2161cb0ef41Sopenharmony_ciucptrie_close(UCPTrie *trie); 2171cb0ef41Sopenharmony_ci 2181cb0ef41Sopenharmony_ci/** 2191cb0ef41Sopenharmony_ci * Returns the trie type. 2201cb0ef41Sopenharmony_ci * 2211cb0ef41Sopenharmony_ci * @param trie the trie 2221cb0ef41Sopenharmony_ci * @return the trie type 2231cb0ef41Sopenharmony_ci * @see ucptrie_openFromBinary 2241cb0ef41Sopenharmony_ci * @see UCPTRIE_TYPE_ANY 2251cb0ef41Sopenharmony_ci * @stable ICU 63 2261cb0ef41Sopenharmony_ci */ 2271cb0ef41Sopenharmony_ciU_CAPI UCPTrieType U_EXPORT2 2281cb0ef41Sopenharmony_ciucptrie_getType(const UCPTrie *trie); 2291cb0ef41Sopenharmony_ci 2301cb0ef41Sopenharmony_ci/** 2311cb0ef41Sopenharmony_ci * Returns the number of bits in a trie data value. 2321cb0ef41Sopenharmony_ci * 2331cb0ef41Sopenharmony_ci * @param trie the trie 2341cb0ef41Sopenharmony_ci * @return the number of bits in a trie data value 2351cb0ef41Sopenharmony_ci * @see ucptrie_openFromBinary 2361cb0ef41Sopenharmony_ci * @see UCPTRIE_VALUE_BITS_ANY 2371cb0ef41Sopenharmony_ci * @stable ICU 63 2381cb0ef41Sopenharmony_ci */ 2391cb0ef41Sopenharmony_ciU_CAPI UCPTrieValueWidth U_EXPORT2 2401cb0ef41Sopenharmony_ciucptrie_getValueWidth(const UCPTrie *trie); 2411cb0ef41Sopenharmony_ci 2421cb0ef41Sopenharmony_ci/** 2431cb0ef41Sopenharmony_ci * Returns the value for a code point as stored in the trie, with range checking. 2441cb0ef41Sopenharmony_ci * Returns the trie error value if c is not in the range 0..U+10FFFF. 2451cb0ef41Sopenharmony_ci * 2461cb0ef41Sopenharmony_ci * Easier to use than UCPTRIE_FAST_GET() and similar macros but slower. 2471cb0ef41Sopenharmony_ci * Easier to use because, unlike the macros, this function works on all UCPTrie 2481cb0ef41Sopenharmony_ci * objects, for all types and value widths. 2491cb0ef41Sopenharmony_ci * 2501cb0ef41Sopenharmony_ci * @param trie the trie 2511cb0ef41Sopenharmony_ci * @param c the code point 2521cb0ef41Sopenharmony_ci * @return the trie value, 2531cb0ef41Sopenharmony_ci * or the trie error value if the code point is not in the range 0..U+10FFFF 2541cb0ef41Sopenharmony_ci * @stable ICU 63 2551cb0ef41Sopenharmony_ci */ 2561cb0ef41Sopenharmony_ciU_CAPI uint32_t U_EXPORT2 2571cb0ef41Sopenharmony_ciucptrie_get(const UCPTrie *trie, UChar32 c); 2581cb0ef41Sopenharmony_ci 2591cb0ef41Sopenharmony_ci/** 2601cb0ef41Sopenharmony_ci * Returns the last code point such that all those from start to there have the same value. 2611cb0ef41Sopenharmony_ci * Can be used to efficiently iterate over all same-value ranges in a trie. 2621cb0ef41Sopenharmony_ci * (This is normally faster than iterating over code points and get()ting each value, 2631cb0ef41Sopenharmony_ci * but much slower than a data structure that stores ranges directly.) 2641cb0ef41Sopenharmony_ci * 2651cb0ef41Sopenharmony_ci * If the UCPMapValueFilter function pointer is not NULL, then 2661cb0ef41Sopenharmony_ci * the value to be delivered is passed through that function, and the return value is the end 2671cb0ef41Sopenharmony_ci * of the range where all values are modified to the same actual value. 2681cb0ef41Sopenharmony_ci * The value is unchanged if that function pointer is NULL. 2691cb0ef41Sopenharmony_ci * 2701cb0ef41Sopenharmony_ci * Example: 2711cb0ef41Sopenharmony_ci * \code 2721cb0ef41Sopenharmony_ci * UChar32 start = 0, end; 2731cb0ef41Sopenharmony_ci * uint32_t value; 2741cb0ef41Sopenharmony_ci * while ((end = ucptrie_getRange(trie, start, UCPMAP_RANGE_NORMAL, 0, 2751cb0ef41Sopenharmony_ci * NULL, NULL, &value)) >= 0) { 2761cb0ef41Sopenharmony_ci * // Work with the range start..end and its value. 2771cb0ef41Sopenharmony_ci * start = end + 1; 2781cb0ef41Sopenharmony_ci * } 2791cb0ef41Sopenharmony_ci * \endcode 2801cb0ef41Sopenharmony_ci * 2811cb0ef41Sopenharmony_ci * @param trie the trie 2821cb0ef41Sopenharmony_ci * @param start range start 2831cb0ef41Sopenharmony_ci * @param option defines whether surrogates are treated normally, 2841cb0ef41Sopenharmony_ci * or as having the surrogateValue; usually UCPMAP_RANGE_NORMAL 2851cb0ef41Sopenharmony_ci * @param surrogateValue value for surrogates; ignored if option==UCPMAP_RANGE_NORMAL 2861cb0ef41Sopenharmony_ci * @param filter a pointer to a function that may modify the trie data value, 2871cb0ef41Sopenharmony_ci * or NULL if the values from the trie are to be used unmodified 2881cb0ef41Sopenharmony_ci * @param context an opaque pointer that is passed on to the filter function 2891cb0ef41Sopenharmony_ci * @param pValue if not NULL, receives the value that every code point start..end has; 2901cb0ef41Sopenharmony_ci * may have been modified by filter(context, trie value) 2911cb0ef41Sopenharmony_ci * if that function pointer is not NULL 2921cb0ef41Sopenharmony_ci * @return the range end code point, or -1 if start is not a valid code point 2931cb0ef41Sopenharmony_ci * @stable ICU 63 2941cb0ef41Sopenharmony_ci */ 2951cb0ef41Sopenharmony_ciU_CAPI UChar32 U_EXPORT2 2961cb0ef41Sopenharmony_ciucptrie_getRange(const UCPTrie *trie, UChar32 start, 2971cb0ef41Sopenharmony_ci UCPMapRangeOption option, uint32_t surrogateValue, 2981cb0ef41Sopenharmony_ci UCPMapValueFilter *filter, const void *context, uint32_t *pValue); 2991cb0ef41Sopenharmony_ci 3001cb0ef41Sopenharmony_ci/** 3011cb0ef41Sopenharmony_ci * Writes a memory-mappable form of the trie into 32-bit aligned memory. 3021cb0ef41Sopenharmony_ci * Inverse of ucptrie_openFromBinary(). 3031cb0ef41Sopenharmony_ci * 3041cb0ef41Sopenharmony_ci * @param trie the trie 3051cb0ef41Sopenharmony_ci * @param data a pointer to 32-bit-aligned memory to be filled with the trie data; 3061cb0ef41Sopenharmony_ci * can be NULL if capacity==0 3071cb0ef41Sopenharmony_ci * @param capacity the number of bytes available at data, or 0 for pure preflighting 3081cb0ef41Sopenharmony_ci * @param pErrorCode an in/out ICU UErrorCode; 3091cb0ef41Sopenharmony_ci * U_BUFFER_OVERFLOW_ERROR if the capacity is too small 3101cb0ef41Sopenharmony_ci * @return the number of bytes written or (if buffer overflow) needed for the trie 3111cb0ef41Sopenharmony_ci * 3121cb0ef41Sopenharmony_ci * @see ucptrie_openFromBinary() 3131cb0ef41Sopenharmony_ci * @stable ICU 63 3141cb0ef41Sopenharmony_ci */ 3151cb0ef41Sopenharmony_ciU_CAPI int32_t U_EXPORT2 3161cb0ef41Sopenharmony_ciucptrie_toBinary(const UCPTrie *trie, void *data, int32_t capacity, UErrorCode *pErrorCode); 3171cb0ef41Sopenharmony_ci 3181cb0ef41Sopenharmony_ci/** 3191cb0ef41Sopenharmony_ci * Macro parameter value for a trie with 16-bit data values. 3201cb0ef41Sopenharmony_ci * Use the name of this macro as a "dataAccess" parameter in other macros. 3211cb0ef41Sopenharmony_ci * Do not use this macro in any other way. 3221cb0ef41Sopenharmony_ci * 3231cb0ef41Sopenharmony_ci * @see UCPTRIE_VALUE_BITS_16 3241cb0ef41Sopenharmony_ci * @stable ICU 63 3251cb0ef41Sopenharmony_ci */ 3261cb0ef41Sopenharmony_ci#define UCPTRIE_16(trie, i) ((trie)->data.ptr16[i]) 3271cb0ef41Sopenharmony_ci 3281cb0ef41Sopenharmony_ci/** 3291cb0ef41Sopenharmony_ci * Macro parameter value for a trie with 32-bit data values. 3301cb0ef41Sopenharmony_ci * Use the name of this macro as a "dataAccess" parameter in other macros. 3311cb0ef41Sopenharmony_ci * Do not use this macro in any other way. 3321cb0ef41Sopenharmony_ci * 3331cb0ef41Sopenharmony_ci * @see UCPTRIE_VALUE_BITS_32 3341cb0ef41Sopenharmony_ci * @stable ICU 63 3351cb0ef41Sopenharmony_ci */ 3361cb0ef41Sopenharmony_ci#define UCPTRIE_32(trie, i) ((trie)->data.ptr32[i]) 3371cb0ef41Sopenharmony_ci 3381cb0ef41Sopenharmony_ci/** 3391cb0ef41Sopenharmony_ci * Macro parameter value for a trie with 8-bit data values. 3401cb0ef41Sopenharmony_ci * Use the name of this macro as a "dataAccess" parameter in other macros. 3411cb0ef41Sopenharmony_ci * Do not use this macro in any other way. 3421cb0ef41Sopenharmony_ci * 3431cb0ef41Sopenharmony_ci * @see UCPTRIE_VALUE_BITS_8 3441cb0ef41Sopenharmony_ci * @stable ICU 63 3451cb0ef41Sopenharmony_ci */ 3461cb0ef41Sopenharmony_ci#define UCPTRIE_8(trie, i) ((trie)->data.ptr8[i]) 3471cb0ef41Sopenharmony_ci 3481cb0ef41Sopenharmony_ci/** 3491cb0ef41Sopenharmony_ci * Returns a trie value for a code point, with range checking. 3501cb0ef41Sopenharmony_ci * Returns the trie error value if c is not in the range 0..U+10FFFF. 3511cb0ef41Sopenharmony_ci * 3521cb0ef41Sopenharmony_ci * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 3531cb0ef41Sopenharmony_ci * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 3541cb0ef41Sopenharmony_ci * @param c (UChar32, in) the input code point 3551cb0ef41Sopenharmony_ci * @return The code point's trie value. 3561cb0ef41Sopenharmony_ci * @stable ICU 63 3571cb0ef41Sopenharmony_ci */ 3581cb0ef41Sopenharmony_ci#define UCPTRIE_FAST_GET(trie, dataAccess, c) dataAccess(trie, _UCPTRIE_CP_INDEX(trie, 0xffff, c)) 3591cb0ef41Sopenharmony_ci 3601cb0ef41Sopenharmony_ci/** 3611cb0ef41Sopenharmony_ci * Returns a 16-bit trie value for a code point, with range checking. 3621cb0ef41Sopenharmony_ci * Returns the trie error value if c is not in the range U+0000..U+10FFFF. 3631cb0ef41Sopenharmony_ci * 3641cb0ef41Sopenharmony_ci * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_SMALL 3651cb0ef41Sopenharmony_ci * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 3661cb0ef41Sopenharmony_ci * @param c (UChar32, in) the input code point 3671cb0ef41Sopenharmony_ci * @return The code point's trie value. 3681cb0ef41Sopenharmony_ci * @stable ICU 63 3691cb0ef41Sopenharmony_ci */ 3701cb0ef41Sopenharmony_ci#define UCPTRIE_SMALL_GET(trie, dataAccess, c) \ 3711cb0ef41Sopenharmony_ci dataAccess(trie, _UCPTRIE_CP_INDEX(trie, UCPTRIE_SMALL_MAX, c)) 3721cb0ef41Sopenharmony_ci 3731cb0ef41Sopenharmony_ci/** 3741cb0ef41Sopenharmony_ci * UTF-16: Reads the next code point (UChar32 c, out), post-increments src, 3751cb0ef41Sopenharmony_ci * and gets a value from the trie. 3761cb0ef41Sopenharmony_ci * Sets the trie error value if c is an unpaired surrogate. 3771cb0ef41Sopenharmony_ci * 3781cb0ef41Sopenharmony_ci * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 3791cb0ef41Sopenharmony_ci * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 3801cb0ef41Sopenharmony_ci * @param src (const UChar *, in/out) the source text pointer 3811cb0ef41Sopenharmony_ci * @param limit (const UChar *, in) the limit pointer for the text, or NULL if NUL-terminated 3821cb0ef41Sopenharmony_ci * @param c (UChar32, out) variable for the code point 3831cb0ef41Sopenharmony_ci * @param result (out) variable for the trie lookup result 3841cb0ef41Sopenharmony_ci * @stable ICU 63 3851cb0ef41Sopenharmony_ci */ 3861cb0ef41Sopenharmony_ci#define UCPTRIE_FAST_U16_NEXT(trie, dataAccess, src, limit, c, result) UPRV_BLOCK_MACRO_BEGIN { \ 3871cb0ef41Sopenharmony_ci (c) = *(src)++; \ 3881cb0ef41Sopenharmony_ci int32_t __index; \ 3891cb0ef41Sopenharmony_ci if (!U16_IS_SURROGATE(c)) { \ 3901cb0ef41Sopenharmony_ci __index = _UCPTRIE_FAST_INDEX(trie, c); \ 3911cb0ef41Sopenharmony_ci } else { \ 3921cb0ef41Sopenharmony_ci uint16_t __c2; \ 3931cb0ef41Sopenharmony_ci if (U16_IS_SURROGATE_LEAD(c) && (src) != (limit) && U16_IS_TRAIL(__c2 = *(src))) { \ 3941cb0ef41Sopenharmony_ci ++(src); \ 3951cb0ef41Sopenharmony_ci (c) = U16_GET_SUPPLEMENTARY((c), __c2); \ 3961cb0ef41Sopenharmony_ci __index = _UCPTRIE_SMALL_INDEX(trie, c); \ 3971cb0ef41Sopenharmony_ci } else { \ 3981cb0ef41Sopenharmony_ci __index = (trie)->dataLength - UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET; \ 3991cb0ef41Sopenharmony_ci } \ 4001cb0ef41Sopenharmony_ci } \ 4011cb0ef41Sopenharmony_ci (result) = dataAccess(trie, __index); \ 4021cb0ef41Sopenharmony_ci} UPRV_BLOCK_MACRO_END 4031cb0ef41Sopenharmony_ci 4041cb0ef41Sopenharmony_ci/** 4051cb0ef41Sopenharmony_ci * UTF-16: Reads the previous code point (UChar32 c, out), pre-decrements src, 4061cb0ef41Sopenharmony_ci * and gets a value from the trie. 4071cb0ef41Sopenharmony_ci * Sets the trie error value if c is an unpaired surrogate. 4081cb0ef41Sopenharmony_ci * 4091cb0ef41Sopenharmony_ci * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 4101cb0ef41Sopenharmony_ci * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 4111cb0ef41Sopenharmony_ci * @param start (const UChar *, in) the start pointer for the text 4121cb0ef41Sopenharmony_ci * @param src (const UChar *, in/out) the source text pointer 4131cb0ef41Sopenharmony_ci * @param c (UChar32, out) variable for the code point 4141cb0ef41Sopenharmony_ci * @param result (out) variable for the trie lookup result 4151cb0ef41Sopenharmony_ci * @stable ICU 63 4161cb0ef41Sopenharmony_ci */ 4171cb0ef41Sopenharmony_ci#define UCPTRIE_FAST_U16_PREV(trie, dataAccess, start, src, c, result) UPRV_BLOCK_MACRO_BEGIN { \ 4181cb0ef41Sopenharmony_ci (c) = *--(src); \ 4191cb0ef41Sopenharmony_ci int32_t __index; \ 4201cb0ef41Sopenharmony_ci if (!U16_IS_SURROGATE(c)) { \ 4211cb0ef41Sopenharmony_ci __index = _UCPTRIE_FAST_INDEX(trie, c); \ 4221cb0ef41Sopenharmony_ci } else { \ 4231cb0ef41Sopenharmony_ci uint16_t __c2; \ 4241cb0ef41Sopenharmony_ci if (U16_IS_SURROGATE_TRAIL(c) && (src) != (start) && U16_IS_LEAD(__c2 = *((src) - 1))) { \ 4251cb0ef41Sopenharmony_ci --(src); \ 4261cb0ef41Sopenharmony_ci (c) = U16_GET_SUPPLEMENTARY(__c2, (c)); \ 4271cb0ef41Sopenharmony_ci __index = _UCPTRIE_SMALL_INDEX(trie, c); \ 4281cb0ef41Sopenharmony_ci } else { \ 4291cb0ef41Sopenharmony_ci __index = (trie)->dataLength - UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET; \ 4301cb0ef41Sopenharmony_ci } \ 4311cb0ef41Sopenharmony_ci } \ 4321cb0ef41Sopenharmony_ci (result) = dataAccess(trie, __index); \ 4331cb0ef41Sopenharmony_ci} UPRV_BLOCK_MACRO_END 4341cb0ef41Sopenharmony_ci 4351cb0ef41Sopenharmony_ci/** 4361cb0ef41Sopenharmony_ci * UTF-8: Post-increments src and gets a value from the trie. 4371cb0ef41Sopenharmony_ci * Sets the trie error value for an ill-formed byte sequence. 4381cb0ef41Sopenharmony_ci * 4391cb0ef41Sopenharmony_ci * Unlike UCPTRIE_FAST_U16_NEXT() this UTF-8 macro does not provide the code point 4401cb0ef41Sopenharmony_ci * because it would be more work to do so and is often not needed. 4411cb0ef41Sopenharmony_ci * If the trie value differs from the error value, then the byte sequence is well-formed, 4421cb0ef41Sopenharmony_ci * and the code point can be assembled without revalidation. 4431cb0ef41Sopenharmony_ci * 4441cb0ef41Sopenharmony_ci * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 4451cb0ef41Sopenharmony_ci * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 4461cb0ef41Sopenharmony_ci * @param src (const char *, in/out) the source text pointer 4471cb0ef41Sopenharmony_ci * @param limit (const char *, in) the limit pointer for the text (must not be NULL) 4481cb0ef41Sopenharmony_ci * @param result (out) variable for the trie lookup result 4491cb0ef41Sopenharmony_ci * @stable ICU 63 4501cb0ef41Sopenharmony_ci */ 4511cb0ef41Sopenharmony_ci#define UCPTRIE_FAST_U8_NEXT(trie, dataAccess, src, limit, result) UPRV_BLOCK_MACRO_BEGIN { \ 4521cb0ef41Sopenharmony_ci int32_t __lead = (uint8_t)*(src)++; \ 4531cb0ef41Sopenharmony_ci if (!U8_IS_SINGLE(__lead)) { \ 4541cb0ef41Sopenharmony_ci uint8_t __t1, __t2, __t3; \ 4551cb0ef41Sopenharmony_ci if ((src) != (limit) && \ 4561cb0ef41Sopenharmony_ci (__lead >= 0xe0 ? \ 4571cb0ef41Sopenharmony_ci __lead < 0xf0 ? /* U+0800..U+FFFF except surrogates */ \ 4581cb0ef41Sopenharmony_ci U8_LEAD3_T1_BITS[__lead &= 0xf] & (1 << ((__t1 = *(src)) >> 5)) && \ 4591cb0ef41Sopenharmony_ci ++(src) != (limit) && (__t2 = *(src) - 0x80) <= 0x3f && \ 4601cb0ef41Sopenharmony_ci (__lead = ((int32_t)(trie)->index[(__lead << 6) + (__t1 & 0x3f)]) + __t2, 1) \ 4611cb0ef41Sopenharmony_ci : /* U+10000..U+10FFFF */ \ 4621cb0ef41Sopenharmony_ci (__lead -= 0xf0) <= 4 && \ 4631cb0ef41Sopenharmony_ci U8_LEAD4_T1_BITS[(__t1 = *(src)) >> 4] & (1 << __lead) && \ 4641cb0ef41Sopenharmony_ci (__lead = (__lead << 6) | (__t1 & 0x3f), ++(src) != (limit)) && \ 4651cb0ef41Sopenharmony_ci (__t2 = *(src) - 0x80) <= 0x3f && \ 4661cb0ef41Sopenharmony_ci ++(src) != (limit) && (__t3 = *(src) - 0x80) <= 0x3f && \ 4671cb0ef41Sopenharmony_ci (__lead = __lead >= (trie)->shifted12HighStart ? \ 4681cb0ef41Sopenharmony_ci (trie)->dataLength - UCPTRIE_HIGH_VALUE_NEG_DATA_OFFSET : \ 4691cb0ef41Sopenharmony_ci ucptrie_internalSmallU8Index((trie), __lead, __t2, __t3), 1) \ 4701cb0ef41Sopenharmony_ci : /* U+0080..U+07FF */ \ 4711cb0ef41Sopenharmony_ci __lead >= 0xc2 && (__t1 = *(src) - 0x80) <= 0x3f && \ 4721cb0ef41Sopenharmony_ci (__lead = (int32_t)(trie)->index[__lead & 0x1f] + __t1, 1))) { \ 4731cb0ef41Sopenharmony_ci ++(src); \ 4741cb0ef41Sopenharmony_ci } else { \ 4751cb0ef41Sopenharmony_ci __lead = (trie)->dataLength - UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET; /* ill-formed*/ \ 4761cb0ef41Sopenharmony_ci } \ 4771cb0ef41Sopenharmony_ci } \ 4781cb0ef41Sopenharmony_ci (result) = dataAccess(trie, __lead); \ 4791cb0ef41Sopenharmony_ci} UPRV_BLOCK_MACRO_END 4801cb0ef41Sopenharmony_ci 4811cb0ef41Sopenharmony_ci/** 4821cb0ef41Sopenharmony_ci * UTF-8: Pre-decrements src and gets a value from the trie. 4831cb0ef41Sopenharmony_ci * Sets the trie error value for an ill-formed byte sequence. 4841cb0ef41Sopenharmony_ci * 4851cb0ef41Sopenharmony_ci * Unlike UCPTRIE_FAST_U16_PREV() this UTF-8 macro does not provide the code point 4861cb0ef41Sopenharmony_ci * because it would be more work to do so and is often not needed. 4871cb0ef41Sopenharmony_ci * If the trie value differs from the error value, then the byte sequence is well-formed, 4881cb0ef41Sopenharmony_ci * and the code point can be assembled without revalidation. 4891cb0ef41Sopenharmony_ci * 4901cb0ef41Sopenharmony_ci * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 4911cb0ef41Sopenharmony_ci * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 4921cb0ef41Sopenharmony_ci * @param start (const char *, in) the start pointer for the text 4931cb0ef41Sopenharmony_ci * @param src (const char *, in/out) the source text pointer 4941cb0ef41Sopenharmony_ci * @param result (out) variable for the trie lookup result 4951cb0ef41Sopenharmony_ci * @stable ICU 63 4961cb0ef41Sopenharmony_ci */ 4971cb0ef41Sopenharmony_ci#define UCPTRIE_FAST_U8_PREV(trie, dataAccess, start, src, result) UPRV_BLOCK_MACRO_BEGIN { \ 4981cb0ef41Sopenharmony_ci int32_t __index = (uint8_t)*--(src); \ 4991cb0ef41Sopenharmony_ci if (!U8_IS_SINGLE(__index)) { \ 5001cb0ef41Sopenharmony_ci __index = ucptrie_internalU8PrevIndex((trie), __index, (const uint8_t *)(start), \ 5011cb0ef41Sopenharmony_ci (const uint8_t *)(src)); \ 5021cb0ef41Sopenharmony_ci (src) -= __index & 7; \ 5031cb0ef41Sopenharmony_ci __index >>= 3; \ 5041cb0ef41Sopenharmony_ci } \ 5051cb0ef41Sopenharmony_ci (result) = dataAccess(trie, __index); \ 5061cb0ef41Sopenharmony_ci} UPRV_BLOCK_MACRO_END 5071cb0ef41Sopenharmony_ci 5081cb0ef41Sopenharmony_ci/** 5091cb0ef41Sopenharmony_ci * Returns a trie value for an ASCII code point, without range checking. 5101cb0ef41Sopenharmony_ci * 5111cb0ef41Sopenharmony_ci * @param trie (const UCPTrie *, in) the trie (of either fast or small type) 5121cb0ef41Sopenharmony_ci * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 5131cb0ef41Sopenharmony_ci * @param c (UChar32, in) the input code point; must be U+0000..U+007F 5141cb0ef41Sopenharmony_ci * @return The ASCII code point's trie value. 5151cb0ef41Sopenharmony_ci * @stable ICU 63 5161cb0ef41Sopenharmony_ci */ 5171cb0ef41Sopenharmony_ci#define UCPTRIE_ASCII_GET(trie, dataAccess, c) dataAccess(trie, c) 5181cb0ef41Sopenharmony_ci 5191cb0ef41Sopenharmony_ci/** 5201cb0ef41Sopenharmony_ci * Returns a trie value for a BMP code point (U+0000..U+FFFF), without range checking. 5211cb0ef41Sopenharmony_ci * Can be used to look up a value for a UTF-16 code unit if other parts of 5221cb0ef41Sopenharmony_ci * the string processing check for surrogates. 5231cb0ef41Sopenharmony_ci * 5241cb0ef41Sopenharmony_ci * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 5251cb0ef41Sopenharmony_ci * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 5261cb0ef41Sopenharmony_ci * @param c (UChar32, in) the input code point, must be U+0000..U+FFFF 5271cb0ef41Sopenharmony_ci * @return The BMP code point's trie value. 5281cb0ef41Sopenharmony_ci * @stable ICU 63 5291cb0ef41Sopenharmony_ci */ 5301cb0ef41Sopenharmony_ci#define UCPTRIE_FAST_BMP_GET(trie, dataAccess, c) dataAccess(trie, _UCPTRIE_FAST_INDEX(trie, c)) 5311cb0ef41Sopenharmony_ci 5321cb0ef41Sopenharmony_ci/** 5331cb0ef41Sopenharmony_ci * Returns a trie value for a supplementary code point (U+10000..U+10FFFF), 5341cb0ef41Sopenharmony_ci * without range checking. 5351cb0ef41Sopenharmony_ci * 5361cb0ef41Sopenharmony_ci * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 5371cb0ef41Sopenharmony_ci * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 5381cb0ef41Sopenharmony_ci * @param c (UChar32, in) the input code point, must be U+10000..U+10FFFF 5391cb0ef41Sopenharmony_ci * @return The supplementary code point's trie value. 5401cb0ef41Sopenharmony_ci * @stable ICU 63 5411cb0ef41Sopenharmony_ci */ 5421cb0ef41Sopenharmony_ci#define UCPTRIE_FAST_SUPP_GET(trie, dataAccess, c) dataAccess(trie, _UCPTRIE_SMALL_INDEX(trie, c)) 5431cb0ef41Sopenharmony_ci 5441cb0ef41Sopenharmony_ci/* Internal definitions ----------------------------------------------------- */ 5451cb0ef41Sopenharmony_ci 5461cb0ef41Sopenharmony_ci#ifndef U_IN_DOXYGEN 5471cb0ef41Sopenharmony_ci 5481cb0ef41Sopenharmony_ci/** 5491cb0ef41Sopenharmony_ci * Internal implementation constants. 5501cb0ef41Sopenharmony_ci * These are needed for the API macros, but users should not use these directly. 5511cb0ef41Sopenharmony_ci * @internal 5521cb0ef41Sopenharmony_ci */ 5531cb0ef41Sopenharmony_cienum { 5541cb0ef41Sopenharmony_ci /** @internal */ 5551cb0ef41Sopenharmony_ci UCPTRIE_FAST_SHIFT = 6, 5561cb0ef41Sopenharmony_ci 5571cb0ef41Sopenharmony_ci /** Number of entries in a data block for code points below the fast limit. 64=0x40 @internal */ 5581cb0ef41Sopenharmony_ci UCPTRIE_FAST_DATA_BLOCK_LENGTH = 1 << UCPTRIE_FAST_SHIFT, 5591cb0ef41Sopenharmony_ci 5601cb0ef41Sopenharmony_ci /** Mask for getting the lower bits for the in-fast-data-block offset. @internal */ 5611cb0ef41Sopenharmony_ci UCPTRIE_FAST_DATA_MASK = UCPTRIE_FAST_DATA_BLOCK_LENGTH - 1, 5621cb0ef41Sopenharmony_ci 5631cb0ef41Sopenharmony_ci /** @internal */ 5641cb0ef41Sopenharmony_ci UCPTRIE_SMALL_MAX = 0xfff, 5651cb0ef41Sopenharmony_ci 5661cb0ef41Sopenharmony_ci /** 5671cb0ef41Sopenharmony_ci * Offset from dataLength (to be subtracted) for fetching the 5681cb0ef41Sopenharmony_ci * value returned for out-of-range code points and ill-formed UTF-8/16. 5691cb0ef41Sopenharmony_ci * @internal 5701cb0ef41Sopenharmony_ci */ 5711cb0ef41Sopenharmony_ci UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET = 1, 5721cb0ef41Sopenharmony_ci /** 5731cb0ef41Sopenharmony_ci * Offset from dataLength (to be subtracted) for fetching the 5741cb0ef41Sopenharmony_ci * value returned for code points highStart..U+10FFFF. 5751cb0ef41Sopenharmony_ci * @internal 5761cb0ef41Sopenharmony_ci */ 5771cb0ef41Sopenharmony_ci UCPTRIE_HIGH_VALUE_NEG_DATA_OFFSET = 2 5781cb0ef41Sopenharmony_ci}; 5791cb0ef41Sopenharmony_ci 5801cb0ef41Sopenharmony_ci/* Internal functions and macros -------------------------------------------- */ 5811cb0ef41Sopenharmony_ci// Do not conditionalize with #ifndef U_HIDE_INTERNAL_API, needed for public API 5821cb0ef41Sopenharmony_ci 5831cb0ef41Sopenharmony_ci/** @internal */ 5841cb0ef41Sopenharmony_ciU_CAPI int32_t U_EXPORT2 5851cb0ef41Sopenharmony_ciucptrie_internalSmallIndex(const UCPTrie *trie, UChar32 c); 5861cb0ef41Sopenharmony_ci 5871cb0ef41Sopenharmony_ci/** @internal */ 5881cb0ef41Sopenharmony_ciU_CAPI int32_t U_EXPORT2 5891cb0ef41Sopenharmony_ciucptrie_internalSmallU8Index(const UCPTrie *trie, int32_t lt1, uint8_t t2, uint8_t t3); 5901cb0ef41Sopenharmony_ci 5911cb0ef41Sopenharmony_ci/** 5921cb0ef41Sopenharmony_ci * Internal function for part of the UCPTRIE_FAST_U8_PREVxx() macro implementations. 5931cb0ef41Sopenharmony_ci * Do not call directly. 5941cb0ef41Sopenharmony_ci * @internal 5951cb0ef41Sopenharmony_ci */ 5961cb0ef41Sopenharmony_ciU_CAPI int32_t U_EXPORT2 5971cb0ef41Sopenharmony_ciucptrie_internalU8PrevIndex(const UCPTrie *trie, UChar32 c, 5981cb0ef41Sopenharmony_ci const uint8_t *start, const uint8_t *src); 5991cb0ef41Sopenharmony_ci 6001cb0ef41Sopenharmony_ci/** Internal trie getter for a code point below the fast limit. Returns the data index. @internal */ 6011cb0ef41Sopenharmony_ci#define _UCPTRIE_FAST_INDEX(trie, c) \ 6021cb0ef41Sopenharmony_ci ((int32_t)(trie)->index[(c) >> UCPTRIE_FAST_SHIFT] + ((c) & UCPTRIE_FAST_DATA_MASK)) 6031cb0ef41Sopenharmony_ci 6041cb0ef41Sopenharmony_ci/** Internal trie getter for a code point at or above the fast limit. Returns the data index. @internal */ 6051cb0ef41Sopenharmony_ci#define _UCPTRIE_SMALL_INDEX(trie, c) \ 6061cb0ef41Sopenharmony_ci ((c) >= (trie)->highStart ? \ 6071cb0ef41Sopenharmony_ci (trie)->dataLength - UCPTRIE_HIGH_VALUE_NEG_DATA_OFFSET : \ 6081cb0ef41Sopenharmony_ci ucptrie_internalSmallIndex(trie, c)) 6091cb0ef41Sopenharmony_ci 6101cb0ef41Sopenharmony_ci/** 6111cb0ef41Sopenharmony_ci * Internal trie getter for a code point, with checking that c is in U+0000..10FFFF. 6121cb0ef41Sopenharmony_ci * Returns the data index. 6131cb0ef41Sopenharmony_ci * @internal 6141cb0ef41Sopenharmony_ci */ 6151cb0ef41Sopenharmony_ci#define _UCPTRIE_CP_INDEX(trie, fastMax, c) \ 6161cb0ef41Sopenharmony_ci ((uint32_t)(c) <= (uint32_t)(fastMax) ? \ 6171cb0ef41Sopenharmony_ci _UCPTRIE_FAST_INDEX(trie, c) : \ 6181cb0ef41Sopenharmony_ci (uint32_t)(c) <= 0x10ffff ? \ 6191cb0ef41Sopenharmony_ci _UCPTRIE_SMALL_INDEX(trie, c) : \ 6201cb0ef41Sopenharmony_ci (trie)->dataLength - UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET) 6211cb0ef41Sopenharmony_ci 6221cb0ef41Sopenharmony_ciU_CDECL_END 6231cb0ef41Sopenharmony_ci 6241cb0ef41Sopenharmony_ci#endif // U_IN_DOXYGEN 6251cb0ef41Sopenharmony_ci 6261cb0ef41Sopenharmony_ci#if U_SHOW_CPLUSPLUS_API 6271cb0ef41Sopenharmony_ci 6281cb0ef41Sopenharmony_ciU_NAMESPACE_BEGIN 6291cb0ef41Sopenharmony_ci 6301cb0ef41Sopenharmony_ci/** 6311cb0ef41Sopenharmony_ci * \class LocalUCPTriePointer 6321cb0ef41Sopenharmony_ci * "Smart pointer" class, closes a UCPTrie via ucptrie_close(). 6331cb0ef41Sopenharmony_ci * For most methods see the LocalPointerBase base class. 6341cb0ef41Sopenharmony_ci * 6351cb0ef41Sopenharmony_ci * @see LocalPointerBase 6361cb0ef41Sopenharmony_ci * @see LocalPointer 6371cb0ef41Sopenharmony_ci * @stable ICU 63 6381cb0ef41Sopenharmony_ci */ 6391cb0ef41Sopenharmony_ciU_DEFINE_LOCAL_OPEN_POINTER(LocalUCPTriePointer, UCPTrie, ucptrie_close); 6401cb0ef41Sopenharmony_ci 6411cb0ef41Sopenharmony_ciU_NAMESPACE_END 6421cb0ef41Sopenharmony_ci 6431cb0ef41Sopenharmony_ci#endif // U_SHOW_CPLUSPLUS_API 6441cb0ef41Sopenharmony_ci 6451cb0ef41Sopenharmony_ci#endif 646