52 #elif defined(U_STATIC_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION)
63 #define U8_COUNT_TRAIL_BYTES(leadByte) (utf8_countTrailBytes[(uint8_t)leadByte])
69 #define U8_MASK_LEAD_BYTE(leadByte, countTrailBytes) ((leadByte)&=(1<<(6-(countTrailBytes)))-1)
107 #define U8_IS_SINGLE(c) (((c)&0x80)==0)
115 #define U8_IS_LEAD(c) ((uint8_t)((c)-0xc0)<0x3e)
123 #define U8_IS_TRAIL(c) (((c)&0xc0)==0x80)
132 #define U8_LENGTH(c) \
133 ((uint32_t)(c)<=0x7f ? 1 : \
134 ((uint32_t)(c)<=0x7ff ? 2 : \
135 ((uint32_t)(c)<=0xd7ff ? 3 : \
136 ((uint32_t)(c)<=0xdfff || (uint32_t)(c)>0x10ffff ? 0 : \
137 ((uint32_t)(c)<=0xffff ? 3 : 4)\
148 #define U8_MAX_LENGTH 4
166 #define U8_GET_UNSAFE(s, i, c) { \
167 int32_t _u8_get_unsafe_index=(int32_t)(i); \
168 U8_SET_CP_START_UNSAFE(s, _u8_get_unsafe_index); \
169 U8_NEXT_UNSAFE(s, _u8_get_unsafe_index, c); \
190 #define U8_GET(s, start, i, length, c) { \
191 int32_t _u8_get_index=(int32_t)(i); \
192 U8_SET_CP_START(s, start, _u8_get_index); \
193 U8_NEXT(s, _u8_get_index, length, c); \
215 #define U8_NEXT_UNSAFE(s, i, c) { \
216 (c)=(uint8_t)(s)[(i)++]; \
217 if((uint8_t)((c)-0xc0)<0x35) { \
218 uint8_t __count=U8_COUNT_TRAIL_BYTES(c); \
219 U8_MASK_LEAD_BYTE(c, __count); \
223 (c)=((c)<<6)|((s)[(i)++]&0x3f); \
225 (c)=((c)<<6)|((s)[(i)++]&0x3f); \
227 (c)=((c)<<6)|((s)[(i)++]&0x3f); \
252 #define U8_NEXT(s, i, length, c) { \
253 (c)=(uint8_t)(s)[(i)++]; \
255 uint8_t __t1, __t2; \
257 (0xe0<(c) && (c)<=0xec) && \
258 (((i)+1)<(length)) && \
259 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f && \
260 (__t2=(uint8_t)((s)[(i)+1]-0x80))<= 0x3f \
263 (c)=(UChar)(((c)<<12)|(__t1<<6)|__t2); \
266 ((c)<0xe0 && (c)>=0xc2) && \
268 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f \
270 (c)=(UChar)((((c)&0x1f)<<6)|__t1); \
272 } else if(U8_IS_LEAD(c)) { \
274 (c)=utf8_nextCharSafeBody((const uint8_t *)s, &(i), (int32_t)(length), c, -1); \
294 #define U8_APPEND_UNSAFE(s, i, c) { \
295 if((uint32_t)(c)<=0x7f) { \
296 (s)[(i)++]=(uint8_t)(c); \
298 if((uint32_t)(c)<=0x7ff) { \
299 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \
301 if((uint32_t)(c)<=0xffff) { \
302 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \
304 (s)[(i)++]=(uint8_t)(((c)>>18)|0xf0); \
305 (s)[(i)++]=(uint8_t)((((c)>>12)&0x3f)|0x80); \
307 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \
309 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
330 #define U8_APPEND(s, i, capacity, c, isError) { \
331 if((uint32_t)(c)<=0x7f) { \
332 (s)[(i)++]=(uint8_t)(c); \
333 } else if((uint32_t)(c)<=0x7ff && (i)+1<(capacity)) { \
334 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \
335 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
336 } else if((uint32_t)(c)<=0xd7ff && (i)+2<(capacity)) { \
337 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \
338 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \
339 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
341 (i)=utf8_appendCharSafeBody(s, (int32_t)(i), (int32_t)(capacity), c, &(isError)); \
355 #define U8_FWD_1_UNSAFE(s, i) { \
356 (i)+=1+U8_COUNT_TRAIL_BYTES((s)[i]); \
370 #define U8_FWD_1(s, i, length) { \
371 uint8_t __b=(uint8_t)(s)[(i)++]; \
372 if(U8_IS_LEAD(__b)) { \
373 uint8_t __count=U8_COUNT_TRAIL_BYTES(__b); \
374 if((i)+__count>(length)) { \
375 __count=(uint8_t)((length)-(i)); \
377 while(__count>0 && U8_IS_TRAIL((s)[i])) { \
396 #define U8_FWD_N_UNSAFE(s, i, n) { \
399 U8_FWD_1_UNSAFE(s, i); \
417 #define U8_FWD_N(s, i, length, n) { \
419 while(__N>0 && (i)<(length)) { \
420 U8_FWD_1(s, i, length); \
438 #define U8_SET_CP_START_UNSAFE(s, i) { \
439 while(U8_IS_TRAIL((s)[i])) { --(i); } \
456 #define U8_SET_CP_START(s, start, i) { \
457 if(U8_IS_TRAIL((s)[(i)])) { \
458 (i)=utf8_back1SafeBody(s, start, (int32_t)(i)); \
483 #define U8_PREV_UNSAFE(s, i, c) { \
484 (c)=(uint8_t)(s)[--(i)]; \
485 if(U8_IS_TRAIL(c)) { \
486 uint8_t __b, __count=1, __shift=6; \
491 __b=(uint8_t)(s)[--(i)]; \
493 U8_MASK_LEAD_BYTE(__b, __count); \
494 (c)|=(UChar32)__b<<__shift; \
497 (c)|=(UChar32)(__b&0x3f)<<__shift; \
525 #define U8_PREV(s, start, i, c) { \
526 (c)=(uint8_t)(s)[--(i)]; \
529 (c)=utf8_prevCharSafeBody((const uint8_t *)s, start, &(i), c, -1); \
547 #define U8_BACK_1_UNSAFE(s, i) { \
548 while(U8_IS_TRAIL((s)[--(i)])) {} \
563 #define U8_BACK_1(s, start, i) { \
564 if(U8_IS_TRAIL((s)[--(i)])) { \
565 (i)=utf8_back1SafeBody(s, start, (int32_t)(i)); \
582 #define U8_BACK_N_UNSAFE(s, i, n) { \
585 U8_BACK_1_UNSAFE(s, i); \
604 #define U8_BACK_N(s, start, i, n) { \
606 while(__N>0 && (i)>(start)) { \
607 U8_BACK_1(s, start, i); \
625 #define U8_SET_CP_LIMIT_UNSAFE(s, i) { \
626 U8_BACK_1_UNSAFE(s, i); \
627 U8_FWD_1_UNSAFE(s, i); \
645 #define U8_SET_CP_LIMIT(s, start, i, length) { \
646 if((start)<(i) && (i)<(length)) { \
647 U8_BACK_1(s, start, i); \
648 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.
#define U_INTERNAL
This is used to declare a function as an internal ICU C API.
unsigned char uint8_t
Define 64 bit limits.
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.
signed int int32_t
Define 64 bit limits.
int8_t UBool
The ICU boolean type.