55 #elif defined(U_STATIC_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) 80 #define U8_COUNT_TRAIL_BYTES(leadByte) \ 82 ((leadByte)>=0xc0)+((leadByte)>=0xe0) : \ 83 (leadByte)<0xfe ? 3+((leadByte)>=0xf8)+((leadByte)>=0xfc) : 0) 96 #define U8_COUNT_TRAIL_BYTES_UNSAFE(leadByte) \ 97 (((leadByte)>=0xc0)+((leadByte)>=0xe0)+((leadByte)>=0xf0)) 106 #define U8_MASK_LEAD_BYTE(leadByte, countTrailBytes) ((leadByte)&=(1<<(6-(countTrailBytes)))-1) 164 #define U8_IS_SINGLE(c) (((c)&0x80)==0) 172 #define U8_IS_LEAD(c) ((uint8_t)((c)-0xc0)<0x3e) 180 #define U8_IS_TRAIL(c) (((c)&0xc0)==0x80) 189 #define U8_LENGTH(c) \ 190 ((uint32_t)(c)<=0x7f ? 1 : \ 191 ((uint32_t)(c)<=0x7ff ? 2 : \ 192 ((uint32_t)(c)<=0xd7ff ? 3 : \ 193 ((uint32_t)(c)<=0xdfff || (uint32_t)(c)>0x10ffff ? 0 : \ 194 ((uint32_t)(c)<=0xffff ? 3 : 4)\ 205 #define U8_MAX_LENGTH 4 223 #define U8_GET_UNSAFE(s, i, c) { \ 224 int32_t _u8_get_unsafe_index=(int32_t)(i); \ 225 U8_SET_CP_START_UNSAFE(s, _u8_get_unsafe_index); \ 226 U8_NEXT_UNSAFE(s, _u8_get_unsafe_index, c); \ 247 #define U8_GET(s, start, i, length, c) { \ 248 int32_t _u8_get_index=(int32_t)(i); \ 249 U8_SET_CP_START(s, start, _u8_get_index); \ 250 U8_NEXT(s, _u8_get_index, length, c); \ 272 #define U8_NEXT_UNSAFE(s, i, c) { \ 273 (c)=(uint8_t)(s)[(i)++]; \ 276 (c)=(((c)&0x1f)<<6)|((s)[(i)++]&0x3f); \ 277 } else if((c)<0xf0) { \ 279 (c)=(UChar)(((c)<<12)|(((s)[i]&0x3f)<<6)|((s)[(i)+1]&0x3f)); \ 282 (c)=(((c)&7)<<18)|(((s)[i]&0x3f)<<12)|(((s)[(i)+1]&0x3f)<<6)|((s)[(i)+2]&0x3f); \ 306 #define U8_NEXT(s, i, length, c) { \ 307 (c)=(uint8_t)(s)[(i)++]; \ 309 uint8_t __t1, __t2; \ 311 (0xe0<(c) && (c)<=0xec) && \ 312 (((i)+1)<(length)) && \ 313 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f && \ 314 (__t2=(uint8_t)((s)[(i)+1]-0x80))<= 0x3f \ 317 (c)=(UChar)(((c)<<12)|(__t1<<6)|__t2); \ 320 ((c)<0xe0 && (c)>=0xc2) && \ 322 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f \ 324 (c)=(UChar)((((c)&0x1f)<<6)|__t1); \ 326 } else if(U8_IS_LEAD(c)) { \ 328 (c)=utf8_nextCharSafeBody((const uint8_t *)s, &(i), (int32_t)(length), c, -1); \ 348 #define U8_APPEND_UNSAFE(s, i, c) { \ 349 if((uint32_t)(c)<=0x7f) { \ 350 (s)[(i)++]=(uint8_t)(c); \ 352 if((uint32_t)(c)<=0x7ff) { \ 353 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \ 355 if((uint32_t)(c)<=0xffff) { \ 356 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \ 358 (s)[(i)++]=(uint8_t)(((c)>>18)|0xf0); \ 359 (s)[(i)++]=(uint8_t)((((c)>>12)&0x3f)|0x80); \ 361 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \ 363 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \ 384 #define U8_APPEND(s, i, capacity, c, isError) { \ 385 if((uint32_t)(c)<=0x7f) { \ 386 (s)[(i)++]=(uint8_t)(c); \ 387 } else if((uint32_t)(c)<=0x7ff && (i)+1<(capacity)) { \ 388 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \ 389 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \ 390 } else if((uint32_t)(c)<=0xd7ff && (i)+2<(capacity)) { \ 391 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \ 392 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \ 393 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \ 395 (i)=utf8_appendCharSafeBody(s, (int32_t)(i), (int32_t)(capacity), c, &(isError)); \ 409 #define U8_FWD_1_UNSAFE(s, i) { \ 410 (i)+=1+U8_COUNT_TRAIL_BYTES_UNSAFE((uint8_t)(s)[i]); \ 424 #define U8_FWD_1(s, i, length) { \ 425 uint8_t __b=(uint8_t)(s)[(i)++]; \ 426 if(U8_IS_LEAD(__b)) { \ 427 uint8_t __count=U8_COUNT_TRAIL_BYTES(__b); \ 428 if((i)+__count>(length)) { \ 429 __count=(uint8_t)((length)-(i)); \ 431 while(__count>0 && U8_IS_TRAIL((s)[i])) { \ 450 #define U8_FWD_N_UNSAFE(s, i, n) { \ 453 U8_FWD_1_UNSAFE(s, i); \ 471 #define U8_FWD_N(s, i, length, n) { \ 473 while(__N>0 && (i)<(length)) { \ 474 U8_FWD_1(s, i, length); \ 492 #define U8_SET_CP_START_UNSAFE(s, i) { \ 493 while(U8_IS_TRAIL((s)[i])) { --(i); } \ 510 #define U8_SET_CP_START(s, start, i) { \ 511 if(U8_IS_TRAIL((s)[(i)])) { \ 512 (i)=utf8_back1SafeBody(s, start, (int32_t)(i)); \ 537 #define U8_PREV_UNSAFE(s, i, c) { \ 538 (c)=(uint8_t)(s)[--(i)]; \ 539 if(U8_IS_TRAIL(c)) { \ 540 uint8_t __b, __count=1, __shift=6; \ 545 __b=(uint8_t)(s)[--(i)]; \ 547 U8_MASK_LEAD_BYTE(__b, __count); \ 548 (c)|=(UChar32)__b<<__shift; \ 551 (c)|=(UChar32)(__b&0x3f)<<__shift; \ 579 #define U8_PREV(s, start, i, c) { \ 580 (c)=(uint8_t)(s)[--(i)]; \ 583 (c)=utf8_prevCharSafeBody((const uint8_t *)s, start, &(i), c, -1); \ 601 #define U8_BACK_1_UNSAFE(s, i) { \ 602 while(U8_IS_TRAIL((s)[--(i)])) {} \ 617 #define U8_BACK_1(s, start, i) { \ 618 if(U8_IS_TRAIL((s)[--(i)])) { \ 619 (i)=utf8_back1SafeBody(s, start, (int32_t)(i)); \ 636 #define U8_BACK_N_UNSAFE(s, i, n) { \ 639 U8_BACK_1_UNSAFE(s, i); \ 658 #define U8_BACK_N(s, start, i, n) { \ 660 while(__N>0 && (i)>(start)) { \ 661 U8_BACK_1(s, start, i); \ 679 #define U8_SET_CP_LIMIT_UNSAFE(s, i) { \ 680 U8_BACK_1_UNSAFE(s, i); \ 681 U8_FWD_1_UNSAFE(s, i); \ 699 #define U8_SET_CP_LIMIT(s, start, i, length) { \ 700 if((start)<(i) && (i)<(length)) { \ 701 U8_BACK_1(s, start, i); \ 702 U8_FWD_1(s, i, length); \ U_CFUNC U_IMPORT const uint8_t utf8_countTrailBytes[256]
Internal array with numbers of trail bytes for any given byte used in lead byte position.
UChar32 utf8_nextCharSafeBody(const uint8_t *s, int32_t *pi, int32_t length, UChar32 c, UBool strict)
Function for handling "next code point" with error-checking.
Basic types and constants for UTF.
C API: Code point macros.
#define U_CFUNC
This is used in a declaration of a library private ICU C function.
UChar32 utf8_prevCharSafeBody(const uint8_t *s, int32_t start, int32_t *pi, UChar32 c, UBool strict)
Function for handling "previous code point" with error-checking.
int32_t utf8_back1SafeBody(const uint8_t *s, int32_t start, int32_t i)
Function for handling "skip backward one code point" with error-checking.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
int32_t utf8_appendCharSafeBody(uint8_t *s, int32_t i, int32_t length, UChar32 c, UBool *pIsError)
Function for handling "append code point" with error-checking.
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
int8_t UBool
The ICU boolean type.