tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

icu_utf.h (19154B)


      1 // © 2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html
      3 /*
      4 ******************************************************************************
      5 *
      6 *   Copyright (C) 1999-2015, International Business Machines
      7 *   Corporation and others.  All Rights Reserved.
      8 *
      9 ******************************************************************************
     10 */
     11 
     12 #ifndef BASE_THIRD_PARTY_ICU_ICU_UTF_H_
     13 #define BASE_THIRD_PARTY_ICU_ICU_UTF_H_
     14 
     15 #include <stdint.h>
     16 
     17 namespace base_icu {
     18 
     19 // source/common/unicode/umachine.h
     20 
     21 /** The ICU boolean type @stable ICU 2.0 */
     22 typedef int8_t UBool;
     23 
     24 /**
     25 * Define UChar32 as a type for single Unicode code points.
     26 * UChar32 is a signed 32-bit integer (same as int32_t).
     27 *
     28 * The Unicode code point range is 0..0x10ffff.
     29 * All other values (negative or >=0x110000) are illegal as Unicode code points.
     30 * They may be used as sentinel values to indicate "done", "error"
     31 * or similar non-code point conditions.
     32 *
     33 * Before ICU 2.4 (Jitterbug 2146), UChar32 was defined
     34 * to be wchar_t if that is 32 bits wide (wchar_t may be signed or unsigned)
     35 * or else to be uint32_t.
     36 * That is, the definition of UChar32 was platform-dependent.
     37 *
     38 * @see U_SENTINEL
     39 * @stable ICU 2.4
     40 */
     41 typedef int32_t UChar32;
     42 
     43 /**
     44 * This value is intended for sentinel values for APIs that
     45 * (take or) return single code points (UChar32).
     46 * It is outside of the Unicode code point range 0..0x10ffff.
     47 *
     48 * For example, a "done" or "error" value in a new API
     49 * could be indicated with U_SENTINEL.
     50 *
     51 * ICU APIs designed before ICU 2.4 usually define service-specific "done"
     52 * values, mostly 0xffff.
     53 * Those may need to be distinguished from
     54 * actual U+ffff text contents by calling functions like
     55 * CharacterIterator::hasNext() or UnicodeString::length().
     56 *
     57 * @return -1
     58 * @see UChar32
     59 * @stable ICU 2.4
     60 */
     61 #define CBU_SENTINEL (-1)
     62 
     63 /**
     64 * \def UPRV_BLOCK_MACRO_BEGIN
     65 * Defined as the "do" keyword by default.
     66 * @internal
     67 */
     68 #ifndef CBUPRV_BLOCK_MACRO_BEGIN
     69 #define CBUPRV_BLOCK_MACRO_BEGIN do
     70 #endif
     71 
     72 /**
     73 * \def UPRV_BLOCK_MACRO_END
     74 * Defined as "while (FALSE)" by default.
     75 * @internal
     76 */
     77 #ifndef CBUPRV_BLOCK_MACRO_END
     78 #define CBUPRV_BLOCK_MACRO_END while (0)
     79 #endif
     80 
     81 
     82 // source/common/unicode/utf.h
     83 
     84 /**
     85 * Is this code point a Unicode noncharacter?
     86 * @param c 32-bit code point
     87 * @return TRUE or FALSE
     88 * @stable ICU 2.4
     89 */
     90 #define CBU_IS_UNICODE_NONCHAR(c) \
     91    ((c)>=0xfdd0 && \
     92     ((c)<=0xfdef || ((c)&0xfffe)==0xfffe) && (c)<=0x10ffff)
     93 
     94 /**
     95 * Is c a Unicode code point value (0..U+10ffff)
     96 * that can be assigned a character?
     97 *
     98 * Code points that are not characters include:
     99 * - single surrogate code points (U+d800..U+dfff, 2048 code points)
    100 * - the last two code points on each plane (U+__fffe and U+__ffff, 34 code points)
    101 * - U+fdd0..U+fdef (new with Unicode 3.1, 32 code points)
    102 * - the highest Unicode code point value is U+10ffff
    103 *
    104 * This means that all code points below U+d800 are character code points,
    105 * and that boundary is tested first for performance.
    106 *
    107 * @param c 32-bit code point
    108 * @return TRUE or FALSE
    109 * @stable ICU 2.4
    110 */
    111 #define CBU_IS_UNICODE_CHAR(c) \
    112    ((uint32_t)(c)<0xd800 || \
    113        (0xdfff<(c) && (c)<=0x10ffff && !CBU_IS_UNICODE_NONCHAR(c)))
    114 
    115 /**
    116 * Is this code point a surrogate (U+d800..U+dfff)?
    117 * @param c 32-bit code point
    118 * @return TRUE or FALSE
    119 * @stable ICU 2.4
    120 */
    121 #define CBU_IS_SURROGATE(c) (((uint32_t)(c)&0xfffff800) == 0xd800)
    122 
    123 /**
    124 * Assuming c is a surrogate code point (U_IS_SURROGATE(c)),
    125 * is it a lead surrogate?
    126 * @param c 32-bit code point
    127 * @return TRUE or FALSE
    128 * @stable ICU 2.4
    129 */
    130 #define CBU_IS_SURROGATE_LEAD(c) (((c)&0x400)==0)
    131 
    132 // source/common/unicode/utf8.h
    133 
    134 /**
    135 * Internal bit vector for 3-byte UTF-8 validity check, for use in U8_IS_VALID_LEAD3_AND_T1.
    136 * Each bit indicates whether one lead byte + first trail byte pair starts a valid sequence.
    137 * Lead byte E0..EF bits 3..0 are used as byte index,
    138 * first trail byte bits 7..5 are used as bit index into that byte.
    139 * @see U8_IS_VALID_LEAD3_AND_T1
    140 * @internal
    141 */
    142 #define CBU8_LEAD3_T1_BITS "\x20\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x10\x30\x30"
    143 
    144 /**
    145 * Internal 3-byte UTF-8 validity check.
    146 * Non-zero if lead byte E0..EF and first trail byte 00..FF start a valid sequence.
    147 * @internal
    148 */
    149 #define CBU8_IS_VALID_LEAD3_AND_T1(lead, t1) (CBU8_LEAD3_T1_BITS[(lead)&0xf]&(1<<((uint8_t)(t1)>>5)))
    150 
    151 /**
    152 * Internal bit vector for 4-byte UTF-8 validity check, for use in U8_IS_VALID_LEAD4_AND_T1.
    153 * Each bit indicates whether one lead byte + first trail byte pair starts a valid sequence.
    154 * First trail byte bits 7..4 are used as byte index,
    155 * lead byte F0..F4 bits 2..0 are used as bit index into that byte.
    156 * @see U8_IS_VALID_LEAD4_AND_T1
    157 * @internal
    158 */
    159 #define CBU8_LEAD4_T1_BITS "\x00\x00\x00\x00\x00\x00\x00\x00\x1E\x0F\x0F\x0F\x00\x00\x00\x00"
    160 
    161 /**
    162 * Internal 4-byte UTF-8 validity check.
    163 * Non-zero if lead byte F0..F4 and first trail byte 00..FF start a valid sequence.
    164 * @internal
    165 */
    166 #define CBU8_IS_VALID_LEAD4_AND_T1(lead, t1) (CBU8_LEAD4_T1_BITS[(uint8_t)(t1)>>4]&(1<<((lead)&7)))
    167 
    168 /**
    169 * Does this code unit (byte) encode a code point by itself (US-ASCII 0..0x7f)?
    170 * @param c 8-bit code unit (byte)
    171 * @return TRUE or FALSE
    172 * @stable ICU 2.4
    173 */
    174 #define CBU8_IS_SINGLE(c) (((c)&0x80)==0)
    175 
    176 /**
    177 * Is this code unit (byte) a UTF-8 lead byte? (0xC2..0xF4)
    178 * @param c 8-bit code unit (byte)
    179 * @return TRUE or FALSE
    180 * @stable ICU 2.4
    181 */
    182 #define CBU8_IS_LEAD(c) ((uint8_t)((c)-0xc2)<=0x32)
    183 
    184 /**
    185 * Is this code unit (byte) a UTF-8 trail byte? (0x80..0xBF)
    186 * @param c 8-bit code unit (byte)
    187 * @return TRUE or FALSE
    188 * @stable ICU 2.4
    189 */
    190 #define CBU8_IS_TRAIL(c) ((int8_t)(c)<-0x40)
    191 
    192 /**
    193 * How many code units (bytes) are used for the UTF-8 encoding
    194 * of this Unicode code point?
    195 * @param c 32-bit code point
    196 * @return 1..4, or 0 if c is a surrogate or not a Unicode code point
    197 * @stable ICU 2.4
    198 */
    199 #define CBU8_LENGTH(c) \
    200    ((uint32_t)(c)<=0x7f ? 1 : \
    201        ((uint32_t)(c)<=0x7ff ? 2 : \
    202            ((uint32_t)(c)<=0xd7ff ? 3 : \
    203                ((uint32_t)(c)<=0xdfff || (uint32_t)(c)>0x10ffff ? 0 : \
    204                    ((uint32_t)(c)<=0xffff ? 3 : 4)\
    205                ) \
    206            ) \
    207        ) \
    208    )
    209 
    210 /**
    211 * The maximum number of UTF-8 code units (bytes) per Unicode code point (U+0000..U+10ffff).
    212 * @return 4
    213 * @stable ICU 2.4
    214 */
    215 #define CBU8_MAX_LENGTH 4
    216 
    217 /**
    218 * Get a code point from a string at a code point boundary offset,
    219 * and advance the offset to the next code point boundary.
    220 * (Post-incrementing forward iteration.)
    221 * "Safe" macro, checks for illegal sequences and for string boundaries.
    222 *
    223 * The length can be negative for a NUL-terminated string.
    224 *
    225 * The offset may point to the lead byte of a multi-byte sequence,
    226 * in which case the macro will read the whole sequence.
    227 * If the offset points to a trail byte or an illegal UTF-8 sequence, then
    228 * c is set to a negative value.
    229 *
    230 * @param s const uint8_t * string
    231 * @param i int32_t string offset, must be i<length
    232 * @param length int32_t string length
    233 * @param c output UChar32 variable, set to <0 in case of an error
    234 * @see U8_NEXT_UNSAFE
    235 * @stable ICU 2.4
    236 */
    237 #define CBU8_NEXT(s, i, length, c) CBU8_INTERNAL_NEXT_OR_SUB(s, i, length, c, CBU_SENTINEL)
    238 
    239 /** @internal */
    240 #define CBU8_INTERNAL_NEXT_OR_SUB(s, i, length, c, sub) CBUPRV_BLOCK_MACRO_BEGIN { \
    241    (c)=(uint8_t)(s)[(i)++]; \
    242    if(!CBU8_IS_SINGLE(c)) { \
    243        uint8_t __t = 0; \
    244        if((i)!=(length) && \
    245            /* fetch/validate/assemble all but last trail byte */ \
    246            ((c)>=0xe0 ? \
    247                ((c)<0xf0 ?  /* U+0800..U+FFFF except surrogates */ \
    248                    CBU8_LEAD3_T1_BITS[(c)&=0xf]&(1<<((__t=(s)[i])>>5)) && \
    249                    (__t&=0x3f, 1) \
    250                :  /* U+10000..U+10FFFF */ \
    251                    ((c)-=0xf0)<=4 && \
    252                    CBU8_LEAD4_T1_BITS[(__t=(s)[i])>>4]&(1<<(c)) && \
    253                    ((c)=((c)<<6)|(__t&0x3f), ++(i)!=(length)) && \
    254                    (__t=(s)[i]-0x80)<=0x3f) && \
    255                /* valid second-to-last trail byte */ \
    256                ((c)=((c)<<6)|__t, ++(i)!=(length)) \
    257            :  /* U+0080..U+07FF */ \
    258                (c)>=0xc2 && ((c)&=0x1f, 1)) && \
    259            /* last trail byte */ \
    260            (__t=(s)[i]-0x80)<=0x3f && \
    261            ((c)=((c)<<6)|__t, ++(i), 1)) { \
    262        } else { \
    263            (c)=(sub);  /* ill-formed*/ \
    264        } \
    265    } \
    266 } CBUPRV_BLOCK_MACRO_END
    267 
    268 /**
    269 * Append a code point to a string, overwriting 1 to 4 bytes.
    270 * The offset points to the current end of the string contents
    271 * and is advanced (post-increment).
    272 * "Unsafe" macro, assumes a valid code point and sufficient space in the string.
    273 * Otherwise, the result is undefined.
    274 *
    275 * @param s const uint8_t * string buffer
    276 * @param i string offset
    277 * @param c code point to append
    278 * @see U8_APPEND
    279 * @stable ICU 2.4
    280 */
    281 #define CBU8_APPEND_UNSAFE(s, i, c)                             \
    282  CBUPRV_BLOCK_MACRO_BEGIN {                                    \
    283    uint32_t __uc = (uint32_t)(c);                              \
    284    if (__uc <= 0x7f) {                                         \
    285      (s)[(i)++] = (uint8_t)__uc;                               \
    286    } else {                                                    \
    287      if (__uc <= 0x7ff) {                                      \
    288        (s)[(i)++] = (uint8_t)((__uc >> 6) | 0xc0);             \
    289      } else {                                                  \
    290        if (__uc <= 0xffff) {                                   \
    291          (s)[(i)++] = (uint8_t)((__uc >> 12) | 0xe0);          \
    292        } else {                                                \
    293          (s)[(i)++] = (uint8_t)((__uc >> 18) | 0xf0);          \
    294          (s)[(i)++] = (uint8_t)(((__uc >> 12) & 0x3f) | 0x80); \
    295        }                                                       \
    296        (s)[(i)++] = (uint8_t)(((__uc >> 6) & 0x3f) | 0x80);    \
    297      }                                                         \
    298      (s)[(i)++] = (uint8_t)((__uc & 0x3f) | 0x80);             \
    299    }                                                           \
    300  }                                                             \
    301  CBUPRV_BLOCK_MACRO_END
    302 
    303 // source/common/unicode/utf16.h
    304 
    305 /**
    306 * Does this code unit alone encode a code point (BMP, not a surrogate)?
    307 * @param c 16-bit code unit
    308 * @return TRUE or FALSE
    309 * @stable ICU 2.4
    310 */
    311 #define CBU16_IS_SINGLE(c) !CBU_IS_SURROGATE(c)
    312 
    313 /**
    314 * Is this code unit a lead surrogate (U+d800..U+dbff)?
    315 * @param c 16-bit code unit
    316 * @return TRUE or FALSE
    317 * @stable ICU 2.4
    318 */
    319 #define CBU16_IS_LEAD(c) (((uint32_t)(c)&0xfffffc00) == 0xd800)
    320 
    321 /**
    322 * Is this code unit a trail surrogate (U+dc00..U+dfff)?
    323 * @param c 16-bit code unit
    324 * @return TRUE or FALSE
    325 * @stable ICU 2.4
    326 */
    327 #define CBU16_IS_TRAIL(c) (((uint32_t)(c)&0xfffffc00) == 0xdc00)
    328 
    329 /**
    330 * Is this code unit a surrogate (U+d800..U+dfff)?
    331 * @param c 16-bit code unit
    332 * @return TRUE or FALSE
    333 * @stable ICU 2.4
    334 */
    335 #define CBU16_IS_SURROGATE(c) CBU_IS_SURROGATE(c)
    336 
    337 /**
    338 * Assuming c is a surrogate code point (U16_IS_SURROGATE(c)),
    339 * is it a lead surrogate?
    340 * @param c 16-bit code unit
    341 * @return TRUE or FALSE
    342 * @stable ICU 2.4
    343 */
    344 #define CBU16_IS_SURROGATE_LEAD(c) (((c)&0x400)==0)
    345 
    346 /**
    347 * Helper constant for U16_GET_SUPPLEMENTARY.
    348 * @internal
    349 */
    350 #define CBU16_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000)
    351 
    352 /**
    353 * Get a supplementary code point value (U+10000..U+10ffff)
    354 * from its lead and trail surrogates.
    355 * The result is undefined if the input values are not
    356 * lead and trail surrogates.
    357 *
    358 * @param lead lead surrogate (U+d800..U+dbff)
    359 * @param trail trail surrogate (U+dc00..U+dfff)
    360 * @return supplementary code point (U+10000..U+10ffff)
    361 * @stable ICU 2.4
    362 */
    363 #define CBU16_GET_SUPPLEMENTARY(lead, trail) \
    364    (((::base_icu::UChar32)(lead)<<10UL)+(::base_icu::UChar32)(trail)-CBU16_SURROGATE_OFFSET)
    365 
    366 /**
    367 * Get the lead surrogate (0xd800..0xdbff) for a
    368 * supplementary code point (0x10000..0x10ffff).
    369 * @param supplementary 32-bit code point (U+10000..U+10ffff)
    370 * @return lead surrogate (U+d800..U+dbff) for supplementary
    371 * @stable ICU 2.4
    372 */
    373 #define CBU16_LEAD(supplementary) (::base_icu::UChar)(((supplementary)>>10)+0xd7c0)
    374 
    375 /**
    376 * Get the trail surrogate (0xdc00..0xdfff) for a
    377 * supplementary code point (0x10000..0x10ffff).
    378 * @param supplementary 32-bit code point (U+10000..U+10ffff)
    379 * @return trail surrogate (U+dc00..U+dfff) for supplementary
    380 * @stable ICU 2.4
    381 */
    382 #define CBU16_TRAIL(supplementary) (::base_icu::UChar)(((supplementary)&0x3ff)|0xdc00)
    383 
    384 /**
    385 * How many 16-bit code units are used to encode this Unicode code point? (1 or 2)
    386 * The result is not defined if c is not a Unicode code point (U+0000..U+10ffff).
    387 * @param c 32-bit code point
    388 * @return 1 or 2
    389 * @stable ICU 2.4
    390 */
    391 #define CBU16_LENGTH(c) ((uint32_t)(c)<=0xffff ? 1 : 2)
    392 
    393 /**
    394 * The maximum number of 16-bit code units per Unicode code point (U+0000..U+10ffff).
    395 * @return 2
    396 * @stable ICU 2.4
    397 */
    398 #define CBU16_MAX_LENGTH 2
    399 
    400 /**
    401 * Get a code point from a string at a random-access offset,
    402 * without changing the offset.
    403 * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
    404 *
    405 * The offset may point to either the lead or trail surrogate unit
    406 * for a supplementary code point, in which case the macro will read
    407 * the adjacent matching surrogate as well.
    408 *
    409 * The length can be negative for a NUL-terminated string.
    410 *
    411 * If the offset points to a single, unpaired surrogate, then
    412 * c is set to that unpaired surrogate.
    413 * Iteration through a string is more efficient with U16_NEXT_UNSAFE or U16_NEXT.
    414 *
    415 * @param s const UChar * string
    416 * @param start starting string offset (usually 0)
    417 * @param i string offset, must be start<=i<length
    418 * @param length string length
    419 * @param c output UChar32 variable
    420 * @see U16_GET_UNSAFE
    421 * @stable ICU 2.4
    422 */
    423 #define CBU16_GET(s, start, i, length, c) CBUPRV_BLOCK_MACRO_BEGIN { \
    424    (c)=(s)[i]; \
    425    if(CBU16_IS_SURROGATE(c)) { \
    426        uint16_t __c2; \
    427        if(CBU16_IS_SURROGATE_LEAD(c)) { \
    428            if((i)+1!=(length) && CBU16_IS_TRAIL(__c2=(s)[(i)+1])) { \
    429                (c)=CBU16_GET_SUPPLEMENTARY((c), __c2); \
    430            } \
    431        } else { \
    432            if((i)>(start) && CBU16_IS_LEAD(__c2=(s)[(i)-1])) { \
    433                (c)=CBU16_GET_SUPPLEMENTARY(__c2, (c)); \
    434            } \
    435        } \
    436    } \
    437 } CBUPRV_BLOCK_MACRO_END
    438 
    439 /**
    440 * Get a code point from a string at a code point boundary offset,
    441 * and advance the offset to the next code point boundary.
    442 * (Post-incrementing forward iteration.)
    443 * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
    444 *
    445 * The length can be negative for a NUL-terminated string.
    446 *
    447 * The offset may point to the lead surrogate unit
    448 * for a supplementary code point, in which case the macro will read
    449 * the following trail surrogate as well.
    450 * If the offset points to a trail surrogate or
    451 * to a single, unpaired lead surrogate, then c is set to that unpaired surrogate.
    452 *
    453 * @param s const UChar * string
    454 * @param i string offset, must be i<length
    455 * @param length string length
    456 * @param c output UChar32 variable
    457 * @see U16_NEXT_UNSAFE
    458 * @stable ICU 2.4
    459 */
    460 #define CBU16_NEXT(s, i, length, c) CBUPRV_BLOCK_MACRO_BEGIN { \
    461    (c)=(s)[(i)++]; \
    462    if(CBU16_IS_LEAD(c)) { \
    463        uint16_t __c2; \
    464        if((i)!=(length) && CBU16_IS_TRAIL(__c2=(s)[(i)])) { \
    465            ++(i); \
    466            (c)=CBU16_GET_SUPPLEMENTARY((c), __c2); \
    467        } \
    468    } \
    469 } CBUPRV_BLOCK_MACRO_END
    470 
    471 /**
    472 * Append a code point to a string, overwriting 1 or 2 code units.
    473 * The offset points to the current end of the string contents
    474 * and is advanced (post-increment).
    475 * "Unsafe" macro, assumes a valid code point and sufficient space in the string.
    476 * Otherwise, the result is undefined.
    477 *
    478 * @param s const UChar * string buffer
    479 * @param i string offset
    480 * @param c code point to append
    481 * @see U16_APPEND
    482 * @stable ICU 2.4
    483 */
    484 #define CBU16_APPEND_UNSAFE(s, i, c) CBUPRV_BLOCK_MACRO_BEGIN { \
    485    if((uint32_t)(c)<=0xffff) { \
    486        (s)[(i)++]=(uint16_t)(c); \
    487    } else { \
    488        (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \
    489        (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \
    490    } \
    491 } CBUPRV_BLOCK_MACRO_END
    492 
    493 /**
    494 * Adjust a random-access offset to a code point boundary
    495 * at the start of a code point.
    496 * If the offset points to the trail surrogate of a surrogate pair,
    497 * then the offset is decremented.
    498 * Otherwise, it is not modified.
    499 * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
    500 *
    501 * @param s const UChar * string
    502 * @param start starting string offset (usually 0)
    503 * @param i string offset, must be start<=i
    504 * @see U16_SET_CP_START_UNSAFE
    505 * @stable ICU 2.4
    506 */
    507 #define CBU16_SET_CP_START(s, start, i) CBUPRV_BLOCK_MACRO_BEGIN { \
    508    if(CBU16_IS_TRAIL((s)[i]) && (i)>(start) && CBU16_IS_LEAD((s)[(i)-1])) { \
    509        --(i); \
    510    } \
    511 } CBUPRV_BLOCK_MACRO_END
    512 
    513 /**
    514 * Move the string offset from one code point boundary to the previous one
    515 * and get the code point between them.
    516 * (Pre-decrementing backward iteration.)
    517 * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
    518 *
    519 * The input offset may be the same as the string length.
    520 * If the offset is behind a trail surrogate unit
    521 * for a supplementary code point, then the macro will read
    522 * the preceding lead surrogate as well.
    523 * If the offset is behind a lead surrogate or behind a single, unpaired
    524 * trail surrogate, then c is set to that unpaired surrogate.
    525 *
    526 * @param s const UChar * string
    527 * @param start starting string offset (usually 0)
    528 * @param i string offset, must be start<i
    529 * @param c output UChar32 variable
    530 * @see U16_PREV_UNSAFE
    531 * @stable ICU 2.4
    532 */
    533 #define CBU16_PREV(s, start, i, c) CBUPRV_BLOCK_MACRO_BEGIN { \
    534    (c)=(s)[--(i)]; \
    535    if(CBU16_IS_TRAIL(c)) { \
    536        uint16_t __c2; \
    537        if((i)>(start) && CBU16_IS_LEAD(__c2=(s)[(i)-1])) { \
    538            --(i); \
    539            (c)=CBU16_GET_SUPPLEMENTARY(__c2, (c)); \
    540        } \
    541    } \
    542 } CBUPRV_BLOCK_MACRO_END
    543 
    544 /**
    545 * Adjust a random-access offset to a code point boundary after a code point.
    546 * If the offset is behind the lead surrogate of a surrogate pair,
    547 * then the offset is incremented.
    548 * Otherwise, it is not modified.
    549 * The input offset may be the same as the string length.
    550 * "Safe" macro, handles unpaired surrogates and checks for string boundaries.
    551 *
    552 * The length can be negative for a NUL-terminated string.
    553 *
    554 * @param s const UChar * string
    555 * @param start int32_t starting string offset (usually 0)
    556 * @param i int32_t string offset, start<=i<=length
    557 * @param length int32_t string length
    558 * @see U16_SET_CP_LIMIT_UNSAFE
    559 * @stable ICU 2.4
    560 */
    561 #define CBU16_SET_CP_LIMIT(s, start, i, length) CBUPRV_BLOCK_MACRO_BEGIN { \
    562    if((start)<(i) && ((i)<(length) || (length)<0) && CBU16_IS_LEAD((s)[(i)-1]) && CBU16_IS_TRAIL((s)[i])) { \
    563        ++(i); \
    564    } \
    565 } CBUPRV_BLOCK_MACRO_END
    566 
    567 }  // namesapce base_icu
    568 
    569 #endif  // BASE_THIRD_PARTY_ICU_ICU_UTF_H_