64 #define U8_COUNT_TRAIL_BYTES(leadByte) \ 65 ((uint8_t)(leadByte)<0xf0 ? \ 66 ((uint8_t)(leadByte)>=0xc0)+((uint8_t)(leadByte)>=0xe0) : \ 67 (uint8_t)(leadByte)<0xfe ? 3+((uint8_t)(leadByte)>=0xf8)+((uint8_t)(leadByte)>=0xfc) : 0) 80 #define U8_COUNT_TRAIL_BYTES_UNSAFE(leadByte) \ 81 (((leadByte)>=0xc0)+((leadByte)>=0xe0)+((leadByte)>=0xf0)) 90 #define U8_MASK_LEAD_BYTE(leadByte, countTrailBytes) ((leadByte)&=(1<<(6-(countTrailBytes)))-1) 148 #define U8_IS_SINGLE(c) (((c)&0x80)==0) 156 #define U8_IS_LEAD(c) ((uint8_t)((c)-0xc0)<0x3e) 164 #define U8_IS_TRAIL(c) (((c)&0xc0)==0x80) 173 #define U8_LENGTH(c) \ 174 ((uint32_t)(c)<=0x7f ? 1 : \ 175 ((uint32_t)(c)<=0x7ff ? 2 : \ 176 ((uint32_t)(c)<=0xd7ff ? 3 : \ 177 ((uint32_t)(c)<=0xdfff || (uint32_t)(c)>0x10ffff ? 0 : \ 178 ((uint32_t)(c)<=0xffff ? 3 : 4)\ 189 #define U8_MAX_LENGTH 4 207 #define U8_GET_UNSAFE(s, i, c) { \ 208 int32_t _u8_get_unsafe_index=(int32_t)(i); \ 209 U8_SET_CP_START_UNSAFE(s, _u8_get_unsafe_index); \ 210 U8_NEXT_UNSAFE(s, _u8_get_unsafe_index, c); \ 234 #define U8_GET(s, start, i, length, c) { \ 235 int32_t _u8_get_index=(i); \ 236 U8_SET_CP_START(s, start, _u8_get_index); \ 237 U8_NEXT(s, _u8_get_index, length, c); \ 265 #define U8_GET_OR_FFFD(s, start, i, length, c) { \ 266 int32_t _u8_get_index=(i); \ 267 U8_SET_CP_START(s, start, _u8_get_index); \ 268 U8_NEXT_OR_FFFD(s, _u8_get_index, length, c); \ 290 #define U8_NEXT_UNSAFE(s, i, c) { \ 291 (c)=(uint8_t)(s)[(i)++]; \ 294 (c)=(((c)&0x1f)<<6)|((s)[(i)++]&0x3f); \ 295 } else if((c)<0xf0) { \ 297 (c)=(UChar)(((c)<<12)|(((s)[i]&0x3f)<<6)|((s)[(i)+1]&0x3f)); \ 300 (c)=(((c)&7)<<18)|(((s)[i]&0x3f)<<12)|(((s)[(i)+1]&0x3f)<<6)|((s)[(i)+2]&0x3f); \ 326 #define U8_NEXT(s, i, length, c) { \ 327 (c)=(uint8_t)(s)[(i)++]; \ 329 uint8_t __t1, __t2; \ 331 (0xe0<(c) && (c)<=0xec) && \ 332 (((i)+1)<(length) || (length)<0) && \ 333 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f && \ 334 (__t2=(uint8_t)((s)[(i)+1]-0x80))<= 0x3f \ 337 (c)=(UChar)(((c)<<12)|(__t1<<6)|__t2); \ 340 ((c)<0xe0 && (c)>=0xc2) && \ 342 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f \ 344 (c)=(((c)&0x1f)<<6)|__t1; \ 348 (c)=utf8_nextCharSafeBody((const uint8_t *)s, &(i), (length), c, -1); \ 377 #define U8_NEXT_OR_FFFD(s, i, length, c) { \ 378 (c)=(uint8_t)(s)[(i)++]; \ 380 uint8_t __t1, __t2; \ 382 (0xe0<(c) && (c)<=0xec) && \ 383 (((i)+1)<(length) || (length)<0) && \ 384 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f && \ 385 (__t2=(uint8_t)((s)[(i)+1]-0x80))<= 0x3f \ 388 (c)=(UChar)(((c)<<12)|(__t1<<6)|__t2); \ 391 ((c)<0xe0 && (c)>=0xc2) && \ 393 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f \ 395 (c)=(((c)&0x1f)<<6)|__t1; \ 399 (c)=utf8_nextCharSafeBody((const uint8_t *)s, &(i), (length), c, -3); \ 417 #define U8_APPEND_UNSAFE(s, i, c) { \ 418 if((uint32_t)(c)<=0x7f) { \ 419 (s)[(i)++]=(uint8_t)(c); \ 421 if((uint32_t)(c)<=0x7ff) { \ 422 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \ 424 if((uint32_t)(c)<=0xffff) { \ 425 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \ 427 (s)[(i)++]=(uint8_t)(((c)>>18)|0xf0); \ 428 (s)[(i)++]=(uint8_t)((((c)>>12)&0x3f)|0x80); \ 430 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \ 432 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \ 453 #define U8_APPEND(s, i, capacity, c, isError) { \ 454 if((uint32_t)(c)<=0x7f) { \ 455 (s)[(i)++]=(uint8_t)(c); \ 456 } else if((uint32_t)(c)<=0x7ff && (i)+1<(capacity)) { \ 457 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \ 458 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \ 459 } else if((uint32_t)(c)<=0xd7ff && (i)+2<(capacity)) { \ 460 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \ 461 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \ 462 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \ 464 (i)=utf8_appendCharSafeBody(s, (i), (capacity), c, &(isError)); \ 478 #define U8_FWD_1_UNSAFE(s, i) { \ 479 (i)+=1+U8_COUNT_TRAIL_BYTES_UNSAFE((uint8_t)(s)[i]); \ 495 #define U8_FWD_1(s, i, length) { \ 496 uint8_t __b=(uint8_t)(s)[(i)++]; \ 497 if(U8_IS_LEAD(__b)) { \ 498 uint8_t __count=U8_COUNT_TRAIL_BYTES(__b); \ 499 if((i)+__count>(length) && (length)>=0) { \ 500 __count=(uint8_t)((length)-(i)); \ 502 while(__count>0 && U8_IS_TRAIL((s)[i])) { \ 521 #define U8_FWD_N_UNSAFE(s, i, n) { \ 524 U8_FWD_1_UNSAFE(s, i); \ 544 #define U8_FWD_N(s, i, length, n) { \ 546 while(__N>0 && ((i)<(length) || ((length)<0 && (s)[i]!=0))) { \ 547 U8_FWD_1(s, i, length); \ 565 #define U8_SET_CP_START_UNSAFE(s, i) { \ 566 while(U8_IS_TRAIL((s)[i])) { --(i); } \ 583 #define U8_SET_CP_START(s, start, i) { \ 584 if(U8_IS_TRAIL((s)[(i)])) { \ 585 (i)=utf8_back1SafeBody(s, start, (i)); \ 610 #define U8_PREV_UNSAFE(s, i, c) { \ 611 (c)=(uint8_t)(s)[--(i)]; \ 612 if(U8_IS_TRAIL(c)) { \ 613 uint8_t __b, __count=1, __shift=6; \ 618 __b=(uint8_t)(s)[--(i)]; \ 620 U8_MASK_LEAD_BYTE(__b, __count); \ 621 (c)|=(UChar32)__b<<__shift; \ 624 (c)|=(UChar32)(__b&0x3f)<<__shift; \ 652 #define U8_PREV(s, start, i, c) { \ 653 (c)=(uint8_t)(s)[--(i)]; \ 655 (c)=utf8_prevCharSafeBody((const uint8_t *)s, start, &(i), c, -1); \ 683 #define U8_PREV_OR_FFFD(s, start, i, c) { \ 684 (c)=(uint8_t)(s)[--(i)]; \ 686 (c)=utf8_prevCharSafeBody((const uint8_t *)s, start, &(i), c, -3); \ 701 #define U8_BACK_1_UNSAFE(s, i) { \ 702 while(U8_IS_TRAIL((s)[--(i)])) {} \ 717 #define U8_BACK_1(s, start, i) { \ 718 if(U8_IS_TRAIL((s)[--(i)])) { \ 719 (i)=utf8_back1SafeBody(s, start, (i)); \ 736 #define U8_BACK_N_UNSAFE(s, i, n) { \ 739 U8_BACK_1_UNSAFE(s, i); \ 758 #define U8_BACK_N(s, start, i, n) { \ 760 while(__N>0 && (i)>(start)) { \ 761 U8_BACK_1(s, start, i); \ 779 #define U8_SET_CP_LIMIT_UNSAFE(s, i) { \ 780 U8_BACK_1_UNSAFE(s, i); \ 781 U8_FWD_1_UNSAFE(s, i); \ 801 #define U8_SET_CP_LIMIT(s, start, i, length) { \ 802 if((start)<(i) && ((i)<(length) || (length)<0)) { \ 803 U8_BACK_1(s, start, i); \ 804 U8_FWD_1(s, i, length); \ 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.
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.