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); \
250 #define U8_GET(s, start, i, length, c) { \
251 int32_t _u8_get_index=(i); \
252 U8_SET_CP_START(s, start, _u8_get_index); \
253 U8_NEXT(s, _u8_get_index, length, c); \
256 #ifndef U_HIDE_DRAFT_API
282 #define U8_GET_OR_FFFD(s, start, i, length, c) { \
283 int32_t _u8_get_index=(i); \
284 U8_SET_CP_START(s, start, _u8_get_index); \
285 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); \
371 #ifndef U_HIDE_DRAFT_API
396 #define U8_NEXT_OR_FFFD(s, i, length, c) { \
397 (c)=(uint8_t)(s)[(i)++]; \
399 uint8_t __t1, __t2; \
401 (0xe0<(c) && (c)<=0xec) && \
402 (((i)+1)<(length) || (length)<0) && \
403 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f && \
404 (__t2=(uint8_t)((s)[(i)+1]-0x80))<= 0x3f \
407 (c)=(UChar)(((c)<<12)|(__t1<<6)|__t2); \
410 ((c)<0xe0 && (c)>=0xc2) && \
412 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f \
414 (c)=(((c)&0x1f)<<6)|__t1; \
418 (c)=utf8_nextCharSafeBody((const uint8_t *)s, &(i), (length), c, -3); \
437 #define U8_APPEND_UNSAFE(s, i, c) { \
438 if((uint32_t)(c)<=0x7f) { \
439 (s)[(i)++]=(uint8_t)(c); \
441 if((uint32_t)(c)<=0x7ff) { \
442 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \
444 if((uint32_t)(c)<=0xffff) { \
445 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \
447 (s)[(i)++]=(uint8_t)(((c)>>18)|0xf0); \
448 (s)[(i)++]=(uint8_t)((((c)>>12)&0x3f)|0x80); \
450 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \
452 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
473 #define U8_APPEND(s, i, capacity, c, isError) { \
474 if((uint32_t)(c)<=0x7f) { \
475 (s)[(i)++]=(uint8_t)(c); \
476 } else if((uint32_t)(c)<=0x7ff && (i)+1<(capacity)) { \
477 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \
478 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
479 } else if((uint32_t)(c)<=0xd7ff && (i)+2<(capacity)) { \
480 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \
481 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \
482 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
484 (i)=utf8_appendCharSafeBody(s, (i), (capacity), c, &(isError)); \
498 #define U8_FWD_1_UNSAFE(s, i) { \
499 (i)+=1+U8_COUNT_TRAIL_BYTES_UNSAFE((uint8_t)(s)[i]); \
515 #define U8_FWD_1(s, i, length) { \
516 uint8_t __b=(uint8_t)(s)[(i)++]; \
517 if(U8_IS_LEAD(__b)) { \
518 uint8_t __count=U8_COUNT_TRAIL_BYTES(__b); \
519 if((i)+__count>(length) && (length)>=0) { \
520 __count=(uint8_t)((length)-(i)); \
522 while(__count>0 && U8_IS_TRAIL((s)[i])) { \
541 #define U8_FWD_N_UNSAFE(s, i, n) { \
544 U8_FWD_1_UNSAFE(s, i); \
564 #define U8_FWD_N(s, i, length, n) { \
566 while(__N>0 && ((i)<(length) || ((length)<0 && (s)[i]!=0))) { \
567 U8_FWD_1(s, i, length); \
585 #define U8_SET_CP_START_UNSAFE(s, i) { \
586 while(U8_IS_TRAIL((s)[i])) { --(i); } \
603 #define U8_SET_CP_START(s, start, i) { \
604 if(U8_IS_TRAIL((s)[(i)])) { \
605 (i)=utf8_back1SafeBody(s, start, (i)); \
630 #define U8_PREV_UNSAFE(s, i, c) { \
631 (c)=(uint8_t)(s)[--(i)]; \
632 if(U8_IS_TRAIL(c)) { \
633 uint8_t __b, __count=1, __shift=6; \
638 __b=(uint8_t)(s)[--(i)]; \
640 U8_MASK_LEAD_BYTE(__b, __count); \
641 (c)|=(UChar32)__b<<__shift; \
644 (c)|=(UChar32)(__b&0x3f)<<__shift; \
672 #define U8_PREV(s, start, i, c) { \
673 (c)=(uint8_t)(s)[--(i)]; \
675 (c)=utf8_prevCharSafeBody((const uint8_t *)s, start, &(i), c, -1); \
679 #ifndef U_HIDE_DRAFT_API
704 #define U8_PREV_OR_FFFD(s, start, i, c) { \
705 (c)=(uint8_t)(s)[--(i)]; \
707 (c)=utf8_prevCharSafeBody((const uint8_t *)s, start, &(i), c, -3); \
723 #define U8_BACK_1_UNSAFE(s, i) { \
724 while(U8_IS_TRAIL((s)[--(i)])) {} \
739 #define U8_BACK_1(s, start, i) { \
740 if(U8_IS_TRAIL((s)[--(i)])) { \
741 (i)=utf8_back1SafeBody(s, start, (i)); \
758 #define U8_BACK_N_UNSAFE(s, i, n) { \
761 U8_BACK_1_UNSAFE(s, i); \
780 #define U8_BACK_N(s, start, i, n) { \
782 while(__N>0 && (i)>(start)) { \
783 U8_BACK_1(s, start, i); \
801 #define U8_SET_CP_LIMIT_UNSAFE(s, i) { \
802 U8_BACK_1_UNSAFE(s, i); \
803 U8_FWD_1_UNSAFE(s, i); \
823 #define U8_SET_CP_LIMIT(s, start, i, length) { \
824 if((start)<(i) && ((i)<(length) || ((length)<0 && (s)[i]!=0))) { \
825 U8_BACK_1(s, start, i); \
826 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.