57 #elif defined(U_STATIC_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) 82 #define U8_COUNT_TRAIL_BYTES(leadByte) \ 83 ((uint8_t)(leadByte)<0xf0 ? \ 84 ((uint8_t)(leadByte)>=0xc0)+((uint8_t)(leadByte)>=0xe0) : \ 85 (uint8_t)(leadByte)<0xfe ? 3+((uint8_t)(leadByte)>=0xf8)+((uint8_t)(leadByte)>=0xfc) : 0) 98 #define U8_COUNT_TRAIL_BYTES_UNSAFE(leadByte) \ 99 (((leadByte)>=0xc0)+((leadByte)>=0xe0)+((leadByte)>=0xf0)) 108 #define U8_MASK_LEAD_BYTE(leadByte, countTrailBytes) ((leadByte)&=(1<<(6-(countTrailBytes)))-1) 166 #define U8_IS_SINGLE(c) (((c)&0x80)==0) 174 #define U8_IS_LEAD(c) ((uint8_t)((c)-0xc0)<0x3e) 182 #define U8_IS_TRAIL(c) (((c)&0xc0)==0x80) 191 #define U8_LENGTH(c) \ 192 ((uint32_t)(c)<=0x7f ? 1 : \ 193 ((uint32_t)(c)<=0x7ff ? 2 : \ 194 ((uint32_t)(c)<=0xd7ff ? 3 : \ 195 ((uint32_t)(c)<=0xdfff || (uint32_t)(c)>0x10ffff ? 0 : \ 196 ((uint32_t)(c)<=0xffff ? 3 : 4)\ 207 #define U8_MAX_LENGTH 4 225 #define U8_GET_UNSAFE(s, i, c) { \ 226 int32_t _u8_get_unsafe_index=(int32_t)(i); \ 227 U8_SET_CP_START_UNSAFE(s, _u8_get_unsafe_index); \ 228 U8_NEXT_UNSAFE(s, _u8_get_unsafe_index, c); \ 252 #define U8_GET(s, start, i, length, c) { \ 253 int32_t _u8_get_index=(i); \ 254 U8_SET_CP_START(s, start, _u8_get_index); \ 255 U8_NEXT(s, _u8_get_index, length, c); \ 283 #define U8_GET_OR_FFFD(s, start, i, length, c) { \ 284 int32_t _u8_get_index=(i); \ 285 U8_SET_CP_START(s, start, _u8_get_index); \ 286 U8_NEXT_OR_FFFD(s, _u8_get_index, length, c); \ 308 #define U8_NEXT_UNSAFE(s, i, c) { \ 309 (c)=(uint8_t)(s)[(i)++]; \ 312 (c)=(((c)&0x1f)<<6)|((s)[(i)++]&0x3f); \ 313 } else if((c)<0xf0) { \ 315 (c)=(UChar)(((c)<<12)|(((s)[i]&0x3f)<<6)|((s)[(i)+1]&0x3f)); \ 318 (c)=(((c)&7)<<18)|(((s)[i]&0x3f)<<12)|(((s)[(i)+1]&0x3f)<<6)|((s)[(i)+2]&0x3f); \ 344 #define U8_NEXT(s, i, length, c) { \ 345 (c)=(uint8_t)(s)[(i)++]; \ 347 uint8_t __t1, __t2; \ 349 (0xe0<(c) && (c)<=0xec) && \ 350 (((i)+1)<(length) || (length)<0) && \ 351 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f && \ 352 (__t2=(uint8_t)((s)[(i)+1]-0x80))<= 0x3f \ 355 (c)=(UChar)(((c)<<12)|(__t1<<6)|__t2); \ 358 ((c)<0xe0 && (c)>=0xc2) && \ 360 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f \ 362 (c)=(((c)&0x1f)<<6)|__t1; \ 366 (c)=utf8_nextCharSafeBody((const uint8_t *)s, &(i), (length), c, -1); \ 395 #define U8_NEXT_OR_FFFD(s, i, length, c) { \ 396 (c)=(uint8_t)(s)[(i)++]; \ 398 uint8_t __t1, __t2; \ 400 (0xe0<(c) && (c)<=0xec) && \ 401 (((i)+1)<(length) || (length)<0) && \ 402 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f && \ 403 (__t2=(uint8_t)((s)[(i)+1]-0x80))<= 0x3f \ 406 (c)=(UChar)(((c)<<12)|(__t1<<6)|__t2); \ 409 ((c)<0xe0 && (c)>=0xc2) && \ 411 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f \ 413 (c)=(((c)&0x1f)<<6)|__t1; \ 417 (c)=utf8_nextCharSafeBody((const uint8_t *)s, &(i), (length), c, -3); \ 435 #define U8_APPEND_UNSAFE(s, i, c) { \ 436 if((uint32_t)(c)<=0x7f) { \ 437 (s)[(i)++]=(uint8_t)(c); \ 439 if((uint32_t)(c)<=0x7ff) { \ 440 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \ 442 if((uint32_t)(c)<=0xffff) { \ 443 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \ 445 (s)[(i)++]=(uint8_t)(((c)>>18)|0xf0); \ 446 (s)[(i)++]=(uint8_t)((((c)>>12)&0x3f)|0x80); \ 448 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \ 450 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \ 471 #define U8_APPEND(s, i, capacity, c, isError) { \ 472 if((uint32_t)(c)<=0x7f) { \ 473 (s)[(i)++]=(uint8_t)(c); \ 474 } else if((uint32_t)(c)<=0x7ff && (i)+1<(capacity)) { \ 475 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \ 476 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \ 477 } else if((uint32_t)(c)<=0xd7ff && (i)+2<(capacity)) { \ 478 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \ 479 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \ 480 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \ 482 (i)=utf8_appendCharSafeBody(s, (i), (capacity), c, &(isError)); \ 496 #define U8_FWD_1_UNSAFE(s, i) { \ 497 (i)+=1+U8_COUNT_TRAIL_BYTES_UNSAFE((uint8_t)(s)[i]); \ 513 #define U8_FWD_1(s, i, length) { \ 514 uint8_t __b=(uint8_t)(s)[(i)++]; \ 515 if(U8_IS_LEAD(__b)) { \ 516 uint8_t __count=U8_COUNT_TRAIL_BYTES(__b); \ 517 if((i)+__count>(length) && (length)>=0) { \ 518 __count=(uint8_t)((length)-(i)); \ 520 while(__count>0 && U8_IS_TRAIL((s)[i])) { \ 539 #define U8_FWD_N_UNSAFE(s, i, n) { \ 542 U8_FWD_1_UNSAFE(s, i); \ 562 #define U8_FWD_N(s, i, length, n) { \ 564 while(__N>0 && ((i)<(length) || ((length)<0 && (s)[i]!=0))) { \ 565 U8_FWD_1(s, i, length); \ 583 #define U8_SET_CP_START_UNSAFE(s, i) { \ 584 while(U8_IS_TRAIL((s)[i])) { --(i); } \ 601 #define U8_SET_CP_START(s, start, i) { \ 602 if(U8_IS_TRAIL((s)[(i)])) { \ 603 (i)=utf8_back1SafeBody(s, start, (i)); \ 628 #define U8_PREV_UNSAFE(s, i, c) { \ 629 (c)=(uint8_t)(s)[--(i)]; \ 630 if(U8_IS_TRAIL(c)) { \ 631 uint8_t __b, __count=1, __shift=6; \ 636 __b=(uint8_t)(s)[--(i)]; \ 638 U8_MASK_LEAD_BYTE(__b, __count); \ 639 (c)|=(UChar32)__b<<__shift; \ 642 (c)|=(UChar32)(__b&0x3f)<<__shift; \ 670 #define U8_PREV(s, start, i, c) { \ 671 (c)=(uint8_t)(s)[--(i)]; \ 673 (c)=utf8_prevCharSafeBody((const uint8_t *)s, start, &(i), c, -1); \ 701 #define U8_PREV_OR_FFFD(s, start, i, c) { \ 702 (c)=(uint8_t)(s)[--(i)]; \ 704 (c)=utf8_prevCharSafeBody((const uint8_t *)s, start, &(i), c, -3); \ 719 #define U8_BACK_1_UNSAFE(s, i) { \ 720 while(U8_IS_TRAIL((s)[--(i)])) {} \ 735 #define U8_BACK_1(s, start, i) { \ 736 if(U8_IS_TRAIL((s)[--(i)])) { \ 737 (i)=utf8_back1SafeBody(s, start, (i)); \ 754 #define U8_BACK_N_UNSAFE(s, i, n) { \ 757 U8_BACK_1_UNSAFE(s, i); \ 776 #define U8_BACK_N(s, start, i, n) { \ 778 while(__N>0 && (i)>(start)) { \ 779 U8_BACK_1(s, start, i); \ 797 #define U8_SET_CP_LIMIT_UNSAFE(s, i) { \ 798 U8_BACK_1_UNSAFE(s, i); \ 799 U8_FWD_1_UNSAFE(s, i); \ 819 #define U8_SET_CP_LIMIT(s, start, i, length) { \ 820 if((start)<(i) && ((i)<(length) || (length)<0)) { \ 821 U8_BACK_1(s, start, i); \ 822 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.