55 #elif defined(U_STATIC_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION)
80 #define U8_COUNT_TRAIL_BYTES(leadByte) \
81 ((uint8_t)(leadByte)<0xf0 ? \
82 ((uint8_t)(leadByte)>=0xc0)+((uint8_t)(leadByte)>=0xe0) : \
83 (uint8_t)(leadByte)<0xfe ? 3+((uint8_t)(leadByte)>=0xf8)+((uint8_t)(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); \
281 #define U8_GET_OR_FFFD(s, start, i, length, c) { \
282 int32_t _u8_get_index=(i); \
283 U8_SET_CP_START(s, start, _u8_get_index); \
284 U8_NEXT_OR_FFFD(s, _u8_get_index, length, c); \
306 #define U8_NEXT_UNSAFE(s, i, c) { \
307 (c)=(uint8_t)(s)[(i)++]; \
310 (c)=(((c)&0x1f)<<6)|((s)[(i)++]&0x3f); \
311 } else if((c)<0xf0) { \
313 (c)=(UChar)(((c)<<12)|(((s)[i]&0x3f)<<6)|((s)[(i)+1]&0x3f)); \
316 (c)=(((c)&7)<<18)|(((s)[i]&0x3f)<<12)|(((s)[(i)+1]&0x3f)<<6)|((s)[(i)+2]&0x3f); \
342 #define U8_NEXT(s, i, length, c) { \
343 (c)=(uint8_t)(s)[(i)++]; \
345 uint8_t __t1, __t2; \
347 (0xe0<(c) && (c)<=0xec) && \
348 (((i)+1)<(length) || (length)<0) && \
349 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f && \
350 (__t2=(uint8_t)((s)[(i)+1]-0x80))<= 0x3f \
353 (c)=(UChar)(((c)<<12)|(__t1<<6)|__t2); \
356 ((c)<0xe0 && (c)>=0xc2) && \
358 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f \
360 (c)=(((c)&0x1f)<<6)|__t1; \
364 (c)=utf8_nextCharSafeBody((const uint8_t *)s, &(i), (length), c, -1); \
393 #define U8_NEXT_OR_FFFD(s, i, length, c) { \
394 (c)=(uint8_t)(s)[(i)++]; \
396 uint8_t __t1, __t2; \
398 (0xe0<(c) && (c)<=0xec) && \
399 (((i)+1)<(length) || (length)<0) && \
400 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f && \
401 (__t2=(uint8_t)((s)[(i)+1]-0x80))<= 0x3f \
404 (c)=(UChar)(((c)<<12)|(__t1<<6)|__t2); \
407 ((c)<0xe0 && (c)>=0xc2) && \
409 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f \
411 (c)=(((c)&0x1f)<<6)|__t1; \
415 (c)=utf8_nextCharSafeBody((const uint8_t *)s, &(i), (length), c, -3); \
433 #define U8_APPEND_UNSAFE(s, i, c) { \
434 if((uint32_t)(c)<=0x7f) { \
435 (s)[(i)++]=(uint8_t)(c); \
437 if((uint32_t)(c)<=0x7ff) { \
438 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \
440 if((uint32_t)(c)<=0xffff) { \
441 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \
443 (s)[(i)++]=(uint8_t)(((c)>>18)|0xf0); \
444 (s)[(i)++]=(uint8_t)((((c)>>12)&0x3f)|0x80); \
446 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \
448 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
469 #define U8_APPEND(s, i, capacity, c, isError) { \
470 if((uint32_t)(c)<=0x7f) { \
471 (s)[(i)++]=(uint8_t)(c); \
472 } else if((uint32_t)(c)<=0x7ff && (i)+1<(capacity)) { \
473 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \
474 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
475 } else if((uint32_t)(c)<=0xd7ff && (i)+2<(capacity)) { \
476 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \
477 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \
478 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
480 (i)=utf8_appendCharSafeBody(s, (i), (capacity), c, &(isError)); \
494 #define U8_FWD_1_UNSAFE(s, i) { \
495 (i)+=1+U8_COUNT_TRAIL_BYTES_UNSAFE((uint8_t)(s)[i]); \
511 #define U8_FWD_1(s, i, length) { \
512 uint8_t __b=(uint8_t)(s)[(i)++]; \
513 if(U8_IS_LEAD(__b)) { \
514 uint8_t __count=U8_COUNT_TRAIL_BYTES(__b); \
515 if((i)+__count>(length) && (length)>=0) { \
516 __count=(uint8_t)((length)-(i)); \
518 while(__count>0 && U8_IS_TRAIL((s)[i])) { \
537 #define U8_FWD_N_UNSAFE(s, i, n) { \
540 U8_FWD_1_UNSAFE(s, i); \
560 #define U8_FWD_N(s, i, length, n) { \
562 while(__N>0 && ((i)<(length) || ((length)<0 && (s)[i]!=0))) { \
563 U8_FWD_1(s, i, length); \
581 #define U8_SET_CP_START_UNSAFE(s, i) { \
582 while(U8_IS_TRAIL((s)[i])) { --(i); } \
599 #define U8_SET_CP_START(s, start, i) { \
600 if(U8_IS_TRAIL((s)[(i)])) { \
601 (i)=utf8_back1SafeBody(s, start, (i)); \
626 #define U8_PREV_UNSAFE(s, i, c) { \
627 (c)=(uint8_t)(s)[--(i)]; \
628 if(U8_IS_TRAIL(c)) { \
629 uint8_t __b, __count=1, __shift=6; \
634 __b=(uint8_t)(s)[--(i)]; \
636 U8_MASK_LEAD_BYTE(__b, __count); \
637 (c)|=(UChar32)__b<<__shift; \
640 (c)|=(UChar32)(__b&0x3f)<<__shift; \
668 #define U8_PREV(s, start, i, c) { \
669 (c)=(uint8_t)(s)[--(i)]; \
671 (c)=utf8_prevCharSafeBody((const uint8_t *)s, start, &(i), c, -1); \
699 #define U8_PREV_OR_FFFD(s, start, i, c) { \
700 (c)=(uint8_t)(s)[--(i)]; \
702 (c)=utf8_prevCharSafeBody((const uint8_t *)s, start, &(i), c, -3); \
717 #define U8_BACK_1_UNSAFE(s, i) { \
718 while(U8_IS_TRAIL((s)[--(i)])) {} \
733 #define U8_BACK_1(s, start, i) { \
734 if(U8_IS_TRAIL((s)[--(i)])) { \
735 (i)=utf8_back1SafeBody(s, start, (i)); \
752 #define U8_BACK_N_UNSAFE(s, i, n) { \
755 U8_BACK_1_UNSAFE(s, i); \
774 #define U8_BACK_N(s, start, i, n) { \
776 while(__N>0 && (i)>(start)) { \
777 U8_BACK_1(s, start, i); \
795 #define U8_SET_CP_LIMIT_UNSAFE(s, i) { \
796 U8_BACK_1_UNSAFE(s, i); \
797 U8_FWD_1_UNSAFE(s, i); \
817 #define U8_SET_CP_LIMIT(s, start, i, length) { \
818 if((start)<(i) && ((i)<(length) || (length)<0)) { \
819 U8_BACK_1(s, start, i); \
820 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.