|
||||
Warning, file /include/unicode/ucptrie.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // © 2017 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 0004 // ucptrie.h (modified from utrie2.h) 0005 // created: 2017dec29 Markus W. Scherer 0006 0007 #ifndef __UCPTRIE_H__ 0008 #define __UCPTRIE_H__ 0009 0010 #include "unicode/utypes.h" 0011 #include "unicode/ucpmap.h" 0012 #include "unicode/utf8.h" 0013 0014 #if U_SHOW_CPLUSPLUS_API 0015 #include "unicode/localpointer.h" 0016 #endif // U_SHOW_CPLUSPLUS_API 0017 0018 U_CDECL_BEGIN 0019 0020 /** 0021 * \file 0022 * \brief C API: This file defines an immutable Unicode code point trie. 0023 * 0024 * @see UCPTrie 0025 * @see UMutableCPTrie 0026 */ 0027 0028 #ifndef U_IN_DOXYGEN 0029 /** @internal */ 0030 typedef union UCPTrieData { 0031 /** @internal */ 0032 const void *ptr0; 0033 /** @internal */ 0034 const uint16_t *ptr16; 0035 /** @internal */ 0036 const uint32_t *ptr32; 0037 /** @internal */ 0038 const uint8_t *ptr8; 0039 } UCPTrieData; 0040 #endif 0041 0042 /** 0043 * Immutable Unicode code point trie structure. 0044 * Fast, reasonably compact, map from Unicode code points (U+0000..U+10FFFF) to integer values. 0045 * For details see https://icu.unicode.org/design/struct/utrie 0046 * 0047 * Do not access UCPTrie fields directly; use public functions and macros. 0048 * Functions are easy to use: They support all trie types and value widths. 0049 * 0050 * When performance is really important, macros provide faster access. 0051 * Most macros are specific to either "fast" or "small" tries, see UCPTrieType. 0052 * There are "fast" macros for special optimized use cases. 0053 * 0054 * The macros will return bogus values, or may crash, if used on the wrong type or value width. 0055 * 0056 * @see UMutableCPTrie 0057 * @stable ICU 63 0058 */ 0059 struct UCPTrie { 0060 #ifndef U_IN_DOXYGEN 0061 /** @internal */ 0062 const uint16_t *index; 0063 /** @internal */ 0064 UCPTrieData data; 0065 0066 /** @internal */ 0067 int32_t indexLength; 0068 /** @internal */ 0069 int32_t dataLength; 0070 /** Start of the last range which ends at U+10FFFF. @internal */ 0071 UChar32 highStart; 0072 /** highStart>>12 @internal */ 0073 uint16_t shifted12HighStart; 0074 0075 /** @internal */ 0076 int8_t type; // UCPTrieType 0077 /** @internal */ 0078 int8_t valueWidth; // UCPTrieValueWidth 0079 0080 /** padding/reserved @internal */ 0081 uint32_t reserved32; 0082 /** padding/reserved @internal */ 0083 uint16_t reserved16; 0084 0085 /** 0086 * Internal index-3 null block offset. 0087 * Set to an impossibly high value (e.g., 0xffff) if there is no dedicated index-3 null block. 0088 * @internal 0089 */ 0090 uint16_t index3NullOffset; 0091 /** 0092 * Internal data null block offset, not shifted. 0093 * Set to an impossibly high value (e.g., 0xfffff) if there is no dedicated data null block. 0094 * @internal 0095 */ 0096 int32_t dataNullOffset; 0097 /** @internal */ 0098 uint32_t nullValue; 0099 0100 #ifdef UCPTRIE_DEBUG 0101 /** @internal */ 0102 const char *name; 0103 #endif 0104 #endif 0105 }; 0106 #ifndef U_IN_DOXYGEN 0107 typedef struct UCPTrie UCPTrie; 0108 #endif 0109 0110 /** 0111 * Selectors for the type of a UCPTrie. 0112 * Different trade-offs for size vs. speed. 0113 * 0114 * @see umutablecptrie_buildImmutable 0115 * @see ucptrie_openFromBinary 0116 * @see ucptrie_getType 0117 * @stable ICU 63 0118 */ 0119 enum UCPTrieType { 0120 /** 0121 * For ucptrie_openFromBinary() to accept any type. 0122 * ucptrie_getType() will return the actual type. 0123 * @stable ICU 63 0124 */ 0125 UCPTRIE_TYPE_ANY = -1, 0126 /** 0127 * Fast/simple/larger BMP data structure. Use functions and "fast" macros. 0128 * @stable ICU 63 0129 */ 0130 UCPTRIE_TYPE_FAST, 0131 /** 0132 * Small/slower BMP data structure. Use functions and "small" macros. 0133 * @stable ICU 63 0134 */ 0135 UCPTRIE_TYPE_SMALL 0136 }; 0137 #ifndef U_IN_DOXYGEN 0138 typedef enum UCPTrieType UCPTrieType; 0139 #endif 0140 0141 /** 0142 * Selectors for the number of bits in a UCPTrie data value. 0143 * 0144 * @see umutablecptrie_buildImmutable 0145 * @see ucptrie_openFromBinary 0146 * @see ucptrie_getValueWidth 0147 * @stable ICU 63 0148 */ 0149 enum UCPTrieValueWidth { 0150 /** 0151 * For ucptrie_openFromBinary() to accept any data value width. 0152 * ucptrie_getValueWidth() will return the actual data value width. 0153 * @stable ICU 63 0154 */ 0155 UCPTRIE_VALUE_BITS_ANY = -1, 0156 /** 0157 * The trie stores 16 bits per data value. 0158 * It returns them as unsigned values 0..0xffff=65535. 0159 * @stable ICU 63 0160 */ 0161 UCPTRIE_VALUE_BITS_16, 0162 /** 0163 * The trie stores 32 bits per data value. 0164 * @stable ICU 63 0165 */ 0166 UCPTRIE_VALUE_BITS_32, 0167 /** 0168 * The trie stores 8 bits per data value. 0169 * It returns them as unsigned values 0..0xff=255. 0170 * @stable ICU 63 0171 */ 0172 UCPTRIE_VALUE_BITS_8 0173 }; 0174 #ifndef U_IN_DOXYGEN 0175 typedef enum UCPTrieValueWidth UCPTrieValueWidth; 0176 #endif 0177 0178 /** 0179 * Opens a trie from its binary form, stored in 32-bit-aligned memory. 0180 * Inverse of ucptrie_toBinary(). 0181 * 0182 * The memory must remain valid and unchanged as long as the trie is used. 0183 * You must ucptrie_close() the trie once you are done using it. 0184 * 0185 * @param type selects the trie type; results in an 0186 * U_INVALID_FORMAT_ERROR if it does not match the binary data; 0187 * use UCPTRIE_TYPE_ANY to accept any type 0188 * @param valueWidth selects the number of bits in a data value; results in an 0189 * U_INVALID_FORMAT_ERROR if it does not match the binary data; 0190 * use UCPTRIE_VALUE_BITS_ANY to accept any data value width 0191 * @param data a pointer to 32-bit-aligned memory containing the binary data of a UCPTrie 0192 * @param length the number of bytes available at data; 0193 * can be more than necessary 0194 * @param pActualLength receives the actual number of bytes at data taken up by the trie data; 0195 * can be NULL 0196 * @param pErrorCode an in/out ICU UErrorCode 0197 * @return the trie 0198 * 0199 * @see umutablecptrie_open 0200 * @see umutablecptrie_buildImmutable 0201 * @see ucptrie_toBinary 0202 * @stable ICU 63 0203 */ 0204 U_CAPI UCPTrie * U_EXPORT2 0205 ucptrie_openFromBinary(UCPTrieType type, UCPTrieValueWidth valueWidth, 0206 const void *data, int32_t length, int32_t *pActualLength, 0207 UErrorCode *pErrorCode); 0208 0209 /** 0210 * Closes a trie and releases associated memory. 0211 * 0212 * @param trie the trie 0213 * @stable ICU 63 0214 */ 0215 U_CAPI void U_EXPORT2 0216 ucptrie_close(UCPTrie *trie); 0217 0218 /** 0219 * Returns the trie type. 0220 * 0221 * @param trie the trie 0222 * @return the trie type 0223 * @see ucptrie_openFromBinary 0224 * @see UCPTRIE_TYPE_ANY 0225 * @stable ICU 63 0226 */ 0227 U_CAPI UCPTrieType U_EXPORT2 0228 ucptrie_getType(const UCPTrie *trie); 0229 0230 /** 0231 * Returns the number of bits in a trie data value. 0232 * 0233 * @param trie the trie 0234 * @return the number of bits in a trie data value 0235 * @see ucptrie_openFromBinary 0236 * @see UCPTRIE_VALUE_BITS_ANY 0237 * @stable ICU 63 0238 */ 0239 U_CAPI UCPTrieValueWidth U_EXPORT2 0240 ucptrie_getValueWidth(const UCPTrie *trie); 0241 0242 /** 0243 * Returns the value for a code point as stored in the trie, with range checking. 0244 * Returns the trie error value if c is not in the range 0..U+10FFFF. 0245 * 0246 * Easier to use than UCPTRIE_FAST_GET() and similar macros but slower. 0247 * Easier to use because, unlike the macros, this function works on all UCPTrie 0248 * objects, for all types and value widths. 0249 * 0250 * @param trie the trie 0251 * @param c the code point 0252 * @return the trie value, 0253 * or the trie error value if the code point is not in the range 0..U+10FFFF 0254 * @stable ICU 63 0255 */ 0256 U_CAPI uint32_t U_EXPORT2 0257 ucptrie_get(const UCPTrie *trie, UChar32 c); 0258 0259 /** 0260 * Returns the last code point such that all those from start to there have the same value. 0261 * Can be used to efficiently iterate over all same-value ranges in a trie. 0262 * (This is normally faster than iterating over code points and get()ting each value, 0263 * but much slower than a data structure that stores ranges directly.) 0264 * 0265 * If the UCPMapValueFilter function pointer is not NULL, then 0266 * the value to be delivered is passed through that function, and the return value is the end 0267 * of the range where all values are modified to the same actual value. 0268 * The value is unchanged if that function pointer is NULL. 0269 * 0270 * Example: 0271 * \code 0272 * UChar32 start = 0, end; 0273 * uint32_t value; 0274 * while ((end = ucptrie_getRange(trie, start, UCPMAP_RANGE_NORMAL, 0, 0275 * NULL, NULL, &value)) >= 0) { 0276 * // Work with the range start..end and its value. 0277 * start = end + 1; 0278 * } 0279 * \endcode 0280 * 0281 * @param trie the trie 0282 * @param start range start 0283 * @param option defines whether surrogates are treated normally, 0284 * or as having the surrogateValue; usually UCPMAP_RANGE_NORMAL 0285 * @param surrogateValue value for surrogates; ignored if option==UCPMAP_RANGE_NORMAL 0286 * @param filter a pointer to a function that may modify the trie data value, 0287 * or NULL if the values from the trie are to be used unmodified 0288 * @param context an opaque pointer that is passed on to the filter function 0289 * @param pValue if not NULL, receives the value that every code point start..end has; 0290 * may have been modified by filter(context, trie value) 0291 * if that function pointer is not NULL 0292 * @return the range end code point, or -1 if start is not a valid code point 0293 * @stable ICU 63 0294 */ 0295 U_CAPI UChar32 U_EXPORT2 0296 ucptrie_getRange(const UCPTrie *trie, UChar32 start, 0297 UCPMapRangeOption option, uint32_t surrogateValue, 0298 UCPMapValueFilter *filter, const void *context, uint32_t *pValue); 0299 0300 /** 0301 * Writes a memory-mappable form of the trie into 32-bit aligned memory. 0302 * Inverse of ucptrie_openFromBinary(). 0303 * 0304 * @param trie the trie 0305 * @param data a pointer to 32-bit-aligned memory to be filled with the trie data; 0306 * can be NULL if capacity==0 0307 * @param capacity the number of bytes available at data, or 0 for pure preflighting 0308 * @param pErrorCode an in/out ICU UErrorCode; 0309 * U_BUFFER_OVERFLOW_ERROR if the capacity is too small 0310 * @return the number of bytes written or (if buffer overflow) needed for the trie 0311 * 0312 * @see ucptrie_openFromBinary() 0313 * @stable ICU 63 0314 */ 0315 U_CAPI int32_t U_EXPORT2 0316 ucptrie_toBinary(const UCPTrie *trie, void *data, int32_t capacity, UErrorCode *pErrorCode); 0317 0318 /** 0319 * Macro parameter value for a trie with 16-bit data values. 0320 * Use the name of this macro as a "dataAccess" parameter in other macros. 0321 * Do not use this macro in any other way. 0322 * 0323 * @see UCPTRIE_VALUE_BITS_16 0324 * @stable ICU 63 0325 */ 0326 #define UCPTRIE_16(trie, i) ((trie)->data.ptr16[i]) 0327 0328 /** 0329 * Macro parameter value for a trie with 32-bit data values. 0330 * Use the name of this macro as a "dataAccess" parameter in other macros. 0331 * Do not use this macro in any other way. 0332 * 0333 * @see UCPTRIE_VALUE_BITS_32 0334 * @stable ICU 63 0335 */ 0336 #define UCPTRIE_32(trie, i) ((trie)->data.ptr32[i]) 0337 0338 /** 0339 * Macro parameter value for a trie with 8-bit data values. 0340 * Use the name of this macro as a "dataAccess" parameter in other macros. 0341 * Do not use this macro in any other way. 0342 * 0343 * @see UCPTRIE_VALUE_BITS_8 0344 * @stable ICU 63 0345 */ 0346 #define UCPTRIE_8(trie, i) ((trie)->data.ptr8[i]) 0347 0348 /** 0349 * Returns a trie value for a code point, with range checking. 0350 * Returns the trie error value if c is not in the range 0..U+10FFFF. 0351 * 0352 * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 0353 * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 0354 * @param c (UChar32, in) the input code point 0355 * @return The code point's trie value. 0356 * @stable ICU 63 0357 */ 0358 #define UCPTRIE_FAST_GET(trie, dataAccess, c) dataAccess(trie, _UCPTRIE_CP_INDEX(trie, 0xffff, c)) 0359 0360 /** 0361 * Returns a 16-bit trie value for a code point, with range checking. 0362 * Returns the trie error value if c is not in the range U+0000..U+10FFFF. 0363 * 0364 * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_SMALL 0365 * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 0366 * @param c (UChar32, in) the input code point 0367 * @return The code point's trie value. 0368 * @stable ICU 63 0369 */ 0370 #define UCPTRIE_SMALL_GET(trie, dataAccess, c) \ 0371 dataAccess(trie, _UCPTRIE_CP_INDEX(trie, UCPTRIE_SMALL_MAX, c)) 0372 0373 /** 0374 * UTF-16: Reads the next code point (UChar32 c, out), post-increments src, 0375 * and gets a value from the trie. 0376 * Sets the trie error value if c is an unpaired surrogate. 0377 * 0378 * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 0379 * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 0380 * @param src (const UChar *, in/out) the source text pointer 0381 * @param limit (const UChar *, in) the limit pointer for the text, or NULL if NUL-terminated 0382 * @param c (UChar32, out) variable for the code point 0383 * @param result (out) variable for the trie lookup result 0384 * @stable ICU 63 0385 */ 0386 #define UCPTRIE_FAST_U16_NEXT(trie, dataAccess, src, limit, c, result) UPRV_BLOCK_MACRO_BEGIN { \ 0387 (c) = *(src)++; \ 0388 int32_t __index; \ 0389 if (!U16_IS_SURROGATE(c)) { \ 0390 __index = _UCPTRIE_FAST_INDEX(trie, c); \ 0391 } else { \ 0392 uint16_t __c2; \ 0393 if (U16_IS_SURROGATE_LEAD(c) && (src) != (limit) && U16_IS_TRAIL(__c2 = *(src))) { \ 0394 ++(src); \ 0395 (c) = U16_GET_SUPPLEMENTARY((c), __c2); \ 0396 __index = _UCPTRIE_SMALL_INDEX(trie, c); \ 0397 } else { \ 0398 __index = (trie)->dataLength - UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET; \ 0399 } \ 0400 } \ 0401 (result) = dataAccess(trie, __index); \ 0402 } UPRV_BLOCK_MACRO_END 0403 0404 /** 0405 * UTF-16: Reads the previous code point (UChar32 c, out), pre-decrements src, 0406 * and gets a value from the trie. 0407 * Sets the trie error value if c is an unpaired surrogate. 0408 * 0409 * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 0410 * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 0411 * @param start (const UChar *, in) the start pointer for the text 0412 * @param src (const UChar *, in/out) the source text pointer 0413 * @param c (UChar32, out) variable for the code point 0414 * @param result (out) variable for the trie lookup result 0415 * @stable ICU 63 0416 */ 0417 #define UCPTRIE_FAST_U16_PREV(trie, dataAccess, start, src, c, result) UPRV_BLOCK_MACRO_BEGIN { \ 0418 (c) = *--(src); \ 0419 int32_t __index; \ 0420 if (!U16_IS_SURROGATE(c)) { \ 0421 __index = _UCPTRIE_FAST_INDEX(trie, c); \ 0422 } else { \ 0423 uint16_t __c2; \ 0424 if (U16_IS_SURROGATE_TRAIL(c) && (src) != (start) && U16_IS_LEAD(__c2 = *((src) - 1))) { \ 0425 --(src); \ 0426 (c) = U16_GET_SUPPLEMENTARY(__c2, (c)); \ 0427 __index = _UCPTRIE_SMALL_INDEX(trie, c); \ 0428 } else { \ 0429 __index = (trie)->dataLength - UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET; \ 0430 } \ 0431 } \ 0432 (result) = dataAccess(trie, __index); \ 0433 } UPRV_BLOCK_MACRO_END 0434 0435 /** 0436 * UTF-8: Post-increments src and gets a value from the trie. 0437 * Sets the trie error value for an ill-formed byte sequence. 0438 * 0439 * Unlike UCPTRIE_FAST_U16_NEXT() this UTF-8 macro does not provide the code point 0440 * because it would be more work to do so and is often not needed. 0441 * If the trie value differs from the error value, then the byte sequence is well-formed, 0442 * and the code point can be assembled without revalidation. 0443 * 0444 * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 0445 * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 0446 * @param src (const char *, in/out) the source text pointer 0447 * @param limit (const char *, in) the limit pointer for the text (must not be NULL) 0448 * @param result (out) variable for the trie lookup result 0449 * @stable ICU 63 0450 */ 0451 #define UCPTRIE_FAST_U8_NEXT(trie, dataAccess, src, limit, result) UPRV_BLOCK_MACRO_BEGIN { \ 0452 int32_t __lead = (uint8_t)*(src)++; \ 0453 if (!U8_IS_SINGLE(__lead)) { \ 0454 uint8_t __t1, __t2, __t3; \ 0455 if ((src) != (limit) && \ 0456 (__lead >= 0xe0 ? \ 0457 __lead < 0xf0 ? /* U+0800..U+FFFF except surrogates */ \ 0458 U8_LEAD3_T1_BITS[__lead &= 0xf] & (1 << ((__t1 = *(src)) >> 5)) && \ 0459 ++(src) != (limit) && (__t2 = *(src) - 0x80) <= 0x3f && \ 0460 (__lead = ((int32_t)(trie)->index[(__lead << 6) + (__t1 & 0x3f)]) + __t2, 1) \ 0461 : /* U+10000..U+10FFFF */ \ 0462 (__lead -= 0xf0) <= 4 && \ 0463 U8_LEAD4_T1_BITS[(__t1 = *(src)) >> 4] & (1 << __lead) && \ 0464 (__lead = (__lead << 6) | (__t1 & 0x3f), ++(src) != (limit)) && \ 0465 (__t2 = *(src) - 0x80) <= 0x3f && \ 0466 ++(src) != (limit) && (__t3 = *(src) - 0x80) <= 0x3f && \ 0467 (__lead = __lead >= (trie)->shifted12HighStart ? \ 0468 (trie)->dataLength - UCPTRIE_HIGH_VALUE_NEG_DATA_OFFSET : \ 0469 ucptrie_internalSmallU8Index((trie), __lead, __t2, __t3), 1) \ 0470 : /* U+0080..U+07FF */ \ 0471 __lead >= 0xc2 && (__t1 = *(src) - 0x80) <= 0x3f && \ 0472 (__lead = (int32_t)(trie)->index[__lead & 0x1f] + __t1, 1))) { \ 0473 ++(src); \ 0474 } else { \ 0475 __lead = (trie)->dataLength - UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET; /* ill-formed*/ \ 0476 } \ 0477 } \ 0478 (result) = dataAccess(trie, __lead); \ 0479 } UPRV_BLOCK_MACRO_END 0480 0481 /** 0482 * UTF-8: Pre-decrements src and gets a value from the trie. 0483 * Sets the trie error value for an ill-formed byte sequence. 0484 * 0485 * Unlike UCPTRIE_FAST_U16_PREV() this UTF-8 macro does not provide the code point 0486 * because it would be more work to do so and is often not needed. 0487 * If the trie value differs from the error value, then the byte sequence is well-formed, 0488 * and the code point can be assembled without revalidation. 0489 * 0490 * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 0491 * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 0492 * @param start (const char *, in) the start pointer for the text 0493 * @param src (const char *, in/out) the source text pointer 0494 * @param result (out) variable for the trie lookup result 0495 * @stable ICU 63 0496 */ 0497 #define UCPTRIE_FAST_U8_PREV(trie, dataAccess, start, src, result) UPRV_BLOCK_MACRO_BEGIN { \ 0498 int32_t __index = (uint8_t)*--(src); \ 0499 if (!U8_IS_SINGLE(__index)) { \ 0500 __index = ucptrie_internalU8PrevIndex((trie), __index, (const uint8_t *)(start), \ 0501 (const uint8_t *)(src)); \ 0502 (src) -= __index & 7; \ 0503 __index >>= 3; \ 0504 } \ 0505 (result) = dataAccess(trie, __index); \ 0506 } UPRV_BLOCK_MACRO_END 0507 0508 /** 0509 * Returns a trie value for an ASCII code point, without range checking. 0510 * 0511 * @param trie (const UCPTrie *, in) the trie (of either fast or small type) 0512 * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 0513 * @param c (UChar32, in) the input code point; must be U+0000..U+007F 0514 * @return The ASCII code point's trie value. 0515 * @stable ICU 63 0516 */ 0517 #define UCPTRIE_ASCII_GET(trie, dataAccess, c) dataAccess(trie, c) 0518 0519 /** 0520 * Returns a trie value for a BMP code point (U+0000..U+FFFF), without range checking. 0521 * Can be used to look up a value for a UTF-16 code unit if other parts of 0522 * the string processing check for surrogates. 0523 * 0524 * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 0525 * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 0526 * @param c (UChar32, in) the input code point, must be U+0000..U+FFFF 0527 * @return The BMP code point's trie value. 0528 * @stable ICU 63 0529 */ 0530 #define UCPTRIE_FAST_BMP_GET(trie, dataAccess, c) dataAccess(trie, _UCPTRIE_FAST_INDEX(trie, c)) 0531 0532 /** 0533 * Returns a trie value for a supplementary code point (U+10000..U+10FFFF), 0534 * without range checking. 0535 * 0536 * @param trie (const UCPTrie *, in) the trie; must have type UCPTRIE_TYPE_FAST 0537 * @param dataAccess UCPTRIE_16, UCPTRIE_32, or UCPTRIE_8 according to the trie’s value width 0538 * @param c (UChar32, in) the input code point, must be U+10000..U+10FFFF 0539 * @return The supplementary code point's trie value. 0540 * @stable ICU 63 0541 */ 0542 #define UCPTRIE_FAST_SUPP_GET(trie, dataAccess, c) dataAccess(trie, _UCPTRIE_SMALL_INDEX(trie, c)) 0543 0544 /* Internal definitions ----------------------------------------------------- */ 0545 0546 #ifndef U_IN_DOXYGEN 0547 0548 /** 0549 * Internal implementation constants. 0550 * These are needed for the API macros, but users should not use these directly. 0551 * @internal 0552 */ 0553 enum { 0554 /** @internal */ 0555 UCPTRIE_FAST_SHIFT = 6, 0556 0557 /** Number of entries in a data block for code points below the fast limit. 64=0x40 @internal */ 0558 UCPTRIE_FAST_DATA_BLOCK_LENGTH = 1 << UCPTRIE_FAST_SHIFT, 0559 0560 /** Mask for getting the lower bits for the in-fast-data-block offset. @internal */ 0561 UCPTRIE_FAST_DATA_MASK = UCPTRIE_FAST_DATA_BLOCK_LENGTH - 1, 0562 0563 /** @internal */ 0564 UCPTRIE_SMALL_MAX = 0xfff, 0565 0566 /** 0567 * Offset from dataLength (to be subtracted) for fetching the 0568 * value returned for out-of-range code points and ill-formed UTF-8/16. 0569 * @internal 0570 */ 0571 UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET = 1, 0572 /** 0573 * Offset from dataLength (to be subtracted) for fetching the 0574 * value returned for code points highStart..U+10FFFF. 0575 * @internal 0576 */ 0577 UCPTRIE_HIGH_VALUE_NEG_DATA_OFFSET = 2 0578 }; 0579 0580 /* Internal functions and macros -------------------------------------------- */ 0581 // Do not conditionalize with #ifndef U_HIDE_INTERNAL_API, needed for public API 0582 0583 /** @internal */ 0584 U_CAPI int32_t U_EXPORT2 0585 ucptrie_internalSmallIndex(const UCPTrie *trie, UChar32 c); 0586 0587 /** @internal */ 0588 U_CAPI int32_t U_EXPORT2 0589 ucptrie_internalSmallU8Index(const UCPTrie *trie, int32_t lt1, uint8_t t2, uint8_t t3); 0590 0591 /** 0592 * Internal function for part of the UCPTRIE_FAST_U8_PREVxx() macro implementations. 0593 * Do not call directly. 0594 * @internal 0595 */ 0596 U_CAPI int32_t U_EXPORT2 0597 ucptrie_internalU8PrevIndex(const UCPTrie *trie, UChar32 c, 0598 const uint8_t *start, const uint8_t *src); 0599 0600 /** Internal trie getter for a code point below the fast limit. Returns the data index. @internal */ 0601 #define _UCPTRIE_FAST_INDEX(trie, c) \ 0602 ((int32_t)(trie)->index[(c) >> UCPTRIE_FAST_SHIFT] + ((c) & UCPTRIE_FAST_DATA_MASK)) 0603 0604 /** Internal trie getter for a code point at or above the fast limit. Returns the data index. @internal */ 0605 #define _UCPTRIE_SMALL_INDEX(trie, c) \ 0606 ((c) >= (trie)->highStart ? \ 0607 (trie)->dataLength - UCPTRIE_HIGH_VALUE_NEG_DATA_OFFSET : \ 0608 ucptrie_internalSmallIndex(trie, c)) 0609 0610 /** 0611 * Internal trie getter for a code point, with checking that c is in U+0000..10FFFF. 0612 * Returns the data index. 0613 * @internal 0614 */ 0615 #define _UCPTRIE_CP_INDEX(trie, fastMax, c) \ 0616 ((uint32_t)(c) <= (uint32_t)(fastMax) ? \ 0617 _UCPTRIE_FAST_INDEX(trie, c) : \ 0618 (uint32_t)(c) <= 0x10ffff ? \ 0619 _UCPTRIE_SMALL_INDEX(trie, c) : \ 0620 (trie)->dataLength - UCPTRIE_ERROR_VALUE_NEG_DATA_OFFSET) 0621 0622 U_CDECL_END 0623 0624 #endif // U_IN_DOXYGEN 0625 0626 #if U_SHOW_CPLUSPLUS_API 0627 0628 U_NAMESPACE_BEGIN 0629 0630 /** 0631 * \class LocalUCPTriePointer 0632 * "Smart pointer" class, closes a UCPTrie via ucptrie_close(). 0633 * For most methods see the LocalPointerBase base class. 0634 * 0635 * @see LocalPointerBase 0636 * @see LocalPointer 0637 * @stable ICU 63 0638 */ 0639 U_DEFINE_LOCAL_OPEN_POINTER(LocalUCPTriePointer, UCPTrie, ucptrie_close); 0640 0641 U_NAMESPACE_END 0642 0643 #endif // U_SHOW_CPLUSPLUS_API 0644 0645 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |