29 typedef union UCPTrieData {
33 const uint16_t *ptr16;
35 const uint32_t *ptr32;
61 const uint16_t *index;
72 uint16_t shifted12HighStart;
89 uint16_t index3NullOffset;
95 int32_t dataNullOffset;
106 typedef struct UCPTrie UCPTrie;
203 U_CAPI UCPTrie * U_EXPORT2
205 const void *data, int32_t length, int32_t *pActualLength,
325 #define UCPTRIE_16(trie, i) ((trie)->data.ptr16[i]) 335 #define UCPTRIE_32(trie, i) ((trie)->data.ptr32[i]) 345 #define UCPTRIE_8(trie, i) ((trie)->data.ptr8[i]) 357 #define UCPTRIE_FAST_GET(trie, dataAccess, c) dataAccess(trie, _UCPTRIE_CP_INDEX(trie, 0xffff, c)) 369 #define UCPTRIE_SMALL_GET(trie, dataAccess, c) \ 370 dataAccess(trie, _UCPTRIE_CP_INDEX(trie, UCPTRIE_SMALL_MAX, c)) 385 #define UCPTRIE_FAST_U16_NEXT(trie, dataAccess, src, limit, c, result) UPRV_BLOCK_MACRO_BEGIN { \ 388 if (!U16_IS_SURROGATE(c)) { \ 389 __index = _UCPTRIE_FAST_INDEX(trie, c); \ 392 if (U16_IS_SURROGATE_LEAD(c) && (src) != (limit) && U16_IS_TRAIL(__c2 = *(src))) { \ 394 (c) = U16_GET_SUPPLEMENTARY((c), __c2); \ 395 __index = _UCPTRIE_SMALL_INDEX(trie, c); \ 397 __index = (trie)->dataLength - UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET; \ 400 (result) = dataAccess(trie, __index); \ 401 } UPRV_BLOCK_MACRO_END 416 #define UCPTRIE_FAST_U16_PREV(trie, dataAccess, start, src, c, result) UPRV_BLOCK_MACRO_BEGIN { \ 419 if (!U16_IS_SURROGATE(c)) { \ 420 __index = _UCPTRIE_FAST_INDEX(trie, c); \ 423 if (U16_IS_SURROGATE_TRAIL(c) && (src) != (start) && U16_IS_LEAD(__c2 = *((src) - 1))) { \ 425 (c) = U16_GET_SUPPLEMENTARY(__c2, (c)); \ 426 __index = _UCPTRIE_SMALL_INDEX(trie, c); \ 428 __index = (trie)->dataLength - UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET; \ 431 (result) = dataAccess(trie, __index); \ 432 } UPRV_BLOCK_MACRO_END 450 #define UCPTRIE_FAST_U8_NEXT(trie, dataAccess, src, limit, result) UPRV_BLOCK_MACRO_BEGIN { \ 451 int32_t __lead = (uint8_t)*(src)++; \ 452 if (!U8_IS_SINGLE(__lead)) { \ 453 uint8_t __t1, __t2, __t3; \ 454 if ((src) != (limit) && \ 457 U8_LEAD3_T1_BITS[__lead &= 0xf] & (1 << ((__t1 = *(src)) >> 5)) && \ 458 ++(src) != (limit) && (__t2 = *(src) - 0x80) <= 0x3f && \ 459 (__lead = ((int32_t)(trie)->index[(__lead << 6) + (__t1 & 0x3f)]) + __t2, 1) \ 461 (__lead -= 0xf0) <= 4 && \ 462 U8_LEAD4_T1_BITS[(__t1 = *(src)) >> 4] & (1 << __lead) && \ 463 (__lead = (__lead << 6) | (__t1 & 0x3f), ++(src) != (limit)) && \ 464 (__t2 = *(src) - 0x80) <= 0x3f && \ 465 ++(src) != (limit) && (__t3 = *(src) - 0x80) <= 0x3f && \ 466 (__lead = __lead >= (trie)->shifted12HighStart ? \ 467 (trie)->dataLength - UCPTRIE_HIGH_VALUE_NEG_DATA_OFFSET : \ 468 ucptrie_internalSmallU8Index((trie), __lead, __t2, __t3), 1) \ 470 __lead >= 0xc2 && (__t1 = *(src) - 0x80) <= 0x3f && \ 471 (__lead = (int32_t)(trie)->index[__lead & 0x1f] + __t1, 1))) { \ 474 __lead = (trie)->dataLength - UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET; \ 477 (result) = dataAccess(trie, __lead); \ 478 } UPRV_BLOCK_MACRO_END 496 #define UCPTRIE_FAST_U8_PREV(trie, dataAccess, start, src, result) UPRV_BLOCK_MACRO_BEGIN { \ 497 int32_t __index = (uint8_t)*--(src); \ 498 if (!U8_IS_SINGLE(__index)) { \ 499 __index = ucptrie_internalU8PrevIndex((trie), __index, (const uint8_t *)(start), \ 500 (const uint8_t *)(src)); \ 501 (src) -= __index & 7; \ 504 (result) = dataAccess(trie, __index); \ 505 } UPRV_BLOCK_MACRO_END 516 #define UCPTRIE_ASCII_GET(trie, dataAccess, c) dataAccess(trie, c) 529 #define UCPTRIE_FAST_BMP_GET(trie, dataAccess, c) dataAccess(trie, _UCPTRIE_FAST_INDEX(trie, c)) 541 #define UCPTRIE_FAST_SUPP_GET(trie, dataAccess, c) dataAccess(trie, _UCPTRIE_SMALL_INDEX(trie, c)) 554 UCPTRIE_FAST_SHIFT = 6,
557 UCPTRIE_FAST_DATA_BLOCK_LENGTH = 1 << UCPTRIE_FAST_SHIFT,
560 UCPTRIE_FAST_DATA_MASK = UCPTRIE_FAST_DATA_BLOCK_LENGTH - 1,
563 UCPTRIE_SMALL_MAX = 0xfff,
570 UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET = 1,
576 UCPTRIE_HIGH_VALUE_NEG_DATA_OFFSET = 2
584 ucptrie_internalSmallIndex(
const UCPTrie *trie,
UChar32 c);
588 ucptrie_internalSmallU8Index(
const UCPTrie *trie, int32_t lt1, uint8_t t2, uint8_t t3);
596 ucptrie_internalU8PrevIndex(
const UCPTrie *trie,
UChar32 c,
597 const uint8_t *start,
const uint8_t *src);
600 #define _UCPTRIE_FAST_INDEX(trie, c) \ 601 ((int32_t)(trie)->index[(c) >> UCPTRIE_FAST_SHIFT] + ((c) & UCPTRIE_FAST_DATA_MASK)) 604 #define _UCPTRIE_SMALL_INDEX(trie, c) \ 605 ((c) >= (trie)->highStart ? \ 606 (trie)->dataLength - UCPTRIE_HIGH_VALUE_NEG_DATA_OFFSET : \ 607 ucptrie_internalSmallIndex(trie, c)) 614 #define _UCPTRIE_CP_INDEX(trie, fastMax, c) \ 615 ((uint32_t)(c) <= (uint32_t)(fastMax) ? \ 616 _UCPTRIE_FAST_INDEX(trie, c) : \ 617 (uint32_t)(c) <= 0x10ffff ? \ 618 _UCPTRIE_SMALL_INDEX(trie, c) : \ 619 (trie)->dataLength - UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET) 623 #endif // U_IN_DOXYGEN 625 #if U_SHOW_CPLUSPLUS_API 642 #endif // U_SHOW_CPLUSPLUS_API UCPMapRangeOption
Selectors for how ucpmap_getRange() etc.
U_CAPI UCPTrieType ucptrie_getType(const UCPTrie *trie)
Returns the trie type.
U_CAPI UCPTrie * ucptrie_openFromBinary(UCPTrieType type, UCPTrieValueWidth valueWidth, const void *data, int32_t length, int32_t *pActualLength, UErrorCode *pErrorCode)
Opens a trie from its binary form, stored in 32-bit-aligned memory.
#define U_CAPI
This is used to declare a function as a public ICU C API.
UCPTrieValueWidth
Selectors for the number of bits in a UCPTrie data value.
Immutable Unicode code point trie structure.
This file defines an abstract map from Unicode code points to integer values.
#define U_INTERNAL
This is used to declare a function as an internal ICU C API.
The trie stores 8 bits per data value.
C API: 8-bit Unicode handling macros.
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
"Smart pointer" class, closes a UCPTrie via ucptrie_close().
U_CAPI uint32_t ucptrie_get(const UCPTrie *trie, UChar32 c)
Returns the value for a code point as stored in the trie, with range checking.
Fast/simple/larger BMP data structure.
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
C++ API: "Smart pointers" for use with and in ICU4C C++ code.
U_CAPI int32_t ucptrie_toBinary(const UCPTrie *trie, void *data, int32_t capacity, UErrorCode *pErrorCode)
Writes a memory-mappable form of the trie into 32-bit aligned memory.
uint32_t UCPMapValueFilter(const void *context, uint32_t value)
Callback function type: Modifies a map value.
The trie stores 32 bits per data value.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
The trie stores 16 bits per data value.
U_CAPI UCPTrieValueWidth ucptrie_getValueWidth(const UCPTrie *trie)
Returns the number of bits in a trie data value.
For ucptrie_openFromBinary() to accept any data value width.
U_CAPI void ucptrie_close(UCPTrie *trie)
Closes a trie and releases associated memory.
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
For ucptrie_openFromBinary() to accept any type.
Basic definitions for ICU, for both C and C++ APIs.
U_CAPI UChar32 ucptrie_getRange(const UCPTrie *trie, UChar32 start, UCPMapRangeOption option, uint32_t surrogateValue, UCPMapValueFilter *filter, const void *context, uint32_t *pValue)
Returns the last code point such that all those from start to there have the same value...
UCPTrieType
Selectors for the type of a UCPTrie.
Small/slower BMP data structure.