57 #elif defined(U_STATIC_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION)
71 #define U8_COUNT_TRAIL_BYTES(leadByte) (utf8_countTrailBytes[(uint8_t)leadByte])
80 #define U8_MASK_LEAD_BYTE(leadByte, countTrailBytes) ((leadByte)&=(1<<(6-(countTrailBytes)))-1)
138 #define U8_IS_SINGLE(c) (((c)&0x80)==0)
146 #define U8_IS_LEAD(c) ((uint8_t)((c)-0xc0)<0x3e)
154 #define U8_IS_TRAIL(c) (((c)&0xc0)==0x80)
163 #define U8_LENGTH(c) \
164 ((uint32_t)(c)<=0x7f ? 1 : \
165 ((uint32_t)(c)<=0x7ff ? 2 : \
166 ((uint32_t)(c)<=0xd7ff ? 3 : \
167 ((uint32_t)(c)<=0xdfff || (uint32_t)(c)>0x10ffff ? 0 : \
168 ((uint32_t)(c)<=0xffff ? 3 : 4)\
179 #define U8_MAX_LENGTH 4
197 #define U8_GET_UNSAFE(s, i, c) { \
198 int32_t _u8_get_unsafe_index=(int32_t)(i); \
199 U8_SET_CP_START_UNSAFE(s, _u8_get_unsafe_index); \
200 U8_NEXT_UNSAFE(s, _u8_get_unsafe_index, c); \
221 #define U8_GET(s, start, i, length, c) { \
222 int32_t _u8_get_index=(int32_t)(i); \
223 U8_SET_CP_START(s, start, _u8_get_index); \
224 U8_NEXT(s, _u8_get_index, length, c); \
246 #define U8_NEXT_UNSAFE(s, i, c) { \
247 (c)=(uint8_t)(s)[(i)++]; \
248 if((uint8_t)((c)-0xc0)<0x35) { \
249 uint8_t __count=U8_COUNT_TRAIL_BYTES(c); \
250 U8_MASK_LEAD_BYTE(c, __count); \
254 (c)=((c)<<6)|((s)[(i)++]&0x3f); \
256 (c)=((c)<<6)|((s)[(i)++]&0x3f); \
258 (c)=((c)<<6)|((s)[(i)++]&0x3f); \
283 #define U8_NEXT(s, i, length, c) { \
284 (c)=(uint8_t)(s)[(i)++]; \
286 uint8_t __t1, __t2; \
288 (0xe0<(c) && (c)<=0xec) && \
289 (((i)+1)<(length)) && \
290 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f && \
291 (__t2=(uint8_t)((s)[(i)+1]-0x80))<= 0x3f \
294 (c)=(UChar)(((c)<<12)|(__t1<<6)|__t2); \
297 ((c)<0xe0 && (c)>=0xc2) && \
299 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f \
301 (c)=(UChar)((((c)&0x1f)<<6)|__t1); \
303 } else if(U8_IS_LEAD(c)) { \
305 (c)=utf8_nextCharSafeBody((const uint8_t *)s, &(i), (int32_t)(length), c, -1); \
325 #define U8_APPEND_UNSAFE(s, i, c) { \
326 if((uint32_t)(c)<=0x7f) { \
327 (s)[(i)++]=(uint8_t)(c); \
329 if((uint32_t)(c)<=0x7ff) { \
330 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \
332 if((uint32_t)(c)<=0xffff) { \
333 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \
335 (s)[(i)++]=(uint8_t)(((c)>>18)|0xf0); \
336 (s)[(i)++]=(uint8_t)((((c)>>12)&0x3f)|0x80); \
338 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \
340 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
361 #define U8_APPEND(s, i, capacity, c, isError) { \
362 if((uint32_t)(c)<=0x7f) { \
363 (s)[(i)++]=(uint8_t)(c); \
364 } else if((uint32_t)(c)<=0x7ff && (i)+1<(capacity)) { \
365 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \
366 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
367 } else if((uint32_t)(c)<=0xd7ff && (i)+2<(capacity)) { \
368 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \
369 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \
370 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
372 (i)=utf8_appendCharSafeBody(s, (int32_t)(i), (int32_t)(capacity), c, &(isError)); \
386 #define U8_FWD_1_UNSAFE(s, i) { \
387 (i)+=1+U8_COUNT_TRAIL_BYTES((s)[i]); \
401 #define U8_FWD_1(s, i, length) { \
402 uint8_t __b=(uint8_t)(s)[(i)++]; \
403 if(U8_IS_LEAD(__b)) { \
404 uint8_t __count=U8_COUNT_TRAIL_BYTES(__b); \
405 if((i)+__count>(length)) { \
406 __count=(uint8_t)((length)-(i)); \
408 while(__count>0 && U8_IS_TRAIL((s)[i])) { \
427 #define U8_FWD_N_UNSAFE(s, i, n) { \
430 U8_FWD_1_UNSAFE(s, i); \
448 #define U8_FWD_N(s, i, length, n) { \
450 while(__N>0 && (i)<(length)) { \
451 U8_FWD_1(s, i, length); \
469 #define U8_SET_CP_START_UNSAFE(s, i) { \
470 while(U8_IS_TRAIL((s)[i])) { --(i); } \
487 #define U8_SET_CP_START(s, start, i) { \
488 if(U8_IS_TRAIL((s)[(i)])) { \
489 (i)=utf8_back1SafeBody(s, start, (int32_t)(i)); \
514 #define U8_PREV_UNSAFE(s, i, c) { \
515 (c)=(uint8_t)(s)[--(i)]; \
516 if(U8_IS_TRAIL(c)) { \
517 uint8_t __b, __count=1, __shift=6; \
522 __b=(uint8_t)(s)[--(i)]; \
524 U8_MASK_LEAD_BYTE(__b, __count); \
525 (c)|=(UChar32)__b<<__shift; \
528 (c)|=(UChar32)(__b&0x3f)<<__shift; \
556 #define U8_PREV(s, start, i, c) { \
557 (c)=(uint8_t)(s)[--(i)]; \
560 (c)=utf8_prevCharSafeBody((const uint8_t *)s, start, &(i), c, -1); \
578 #define U8_BACK_1_UNSAFE(s, i) { \
579 while(U8_IS_TRAIL((s)[--(i)])) {} \
594 #define U8_BACK_1(s, start, i) { \
595 if(U8_IS_TRAIL((s)[--(i)])) { \
596 (i)=utf8_back1SafeBody(s, start, (int32_t)(i)); \
613 #define U8_BACK_N_UNSAFE(s, i, n) { \
616 U8_BACK_1_UNSAFE(s, i); \
635 #define U8_BACK_N(s, start, i, n) { \
637 while(__N>0 && (i)>(start)) { \
638 U8_BACK_1(s, start, i); \
656 #define U8_SET_CP_LIMIT_UNSAFE(s, i) { \
657 U8_BACK_1_UNSAFE(s, i); \
658 U8_FWD_1_UNSAFE(s, i); \
676 #define U8_SET_CP_LIMIT(s, start, i, length) { \
677 if((start)<(i) && (i)<(length)) { \
678 U8_BACK_1(s, start, i); \
679 U8_FWD_1(s, i, length); \