55 #elif defined(U_STATIC_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION)
69 #define U8_COUNT_TRAIL_BYTES(leadByte) (utf8_countTrailBytes[(uint8_t)leadByte])
78 #define U8_MASK_LEAD_BYTE(leadByte, countTrailBytes) ((leadByte)&=(1<<(6-(countTrailBytes)))-1)
136 #define U8_IS_SINGLE(c) (((c)&0x80)==0)
144 #define U8_IS_LEAD(c) ((uint8_t)((c)-0xc0)<0x3e)
152 #define U8_IS_TRAIL(c) (((c)&0xc0)==0x80)
161 #define U8_LENGTH(c) \
162 ((uint32_t)(c)<=0x7f ? 1 : \
163 ((uint32_t)(c)<=0x7ff ? 2 : \
164 ((uint32_t)(c)<=0xd7ff ? 3 : \
165 ((uint32_t)(c)<=0xdfff || (uint32_t)(c)>0x10ffff ? 0 : \
166 ((uint32_t)(c)<=0xffff ? 3 : 4)\
177 #define U8_MAX_LENGTH 4
195 #define U8_GET_UNSAFE(s, i, c) { \
196 int32_t _u8_get_unsafe_index=(int32_t)(i); \
197 U8_SET_CP_START_UNSAFE(s, _u8_get_unsafe_index); \
198 U8_NEXT_UNSAFE(s, _u8_get_unsafe_index, c); \
219 #define U8_GET(s, start, i, length, c) { \
220 int32_t _u8_get_index=(int32_t)(i); \
221 U8_SET_CP_START(s, start, _u8_get_index); \
222 U8_NEXT(s, _u8_get_index, length, c); \
244 #define U8_NEXT_UNSAFE(s, i, c) { \
245 (c)=(uint8_t)(s)[(i)++]; \
246 if((uint8_t)((c)-0xc0)<0x35) { \
247 uint8_t __count=U8_COUNT_TRAIL_BYTES(c); \
248 U8_MASK_LEAD_BYTE(c, __count); \
252 (c)=((c)<<6)|((s)[(i)++]&0x3f); \
254 (c)=((c)<<6)|((s)[(i)++]&0x3f); \
256 (c)=((c)<<6)|((s)[(i)++]&0x3f); \
281 #define U8_NEXT(s, i, length, c) { \
282 (c)=(uint8_t)(s)[(i)++]; \
284 uint8_t __t1, __t2; \
286 (0xe0<(c) && (c)<=0xec) && \
287 (((i)+1)<(length)) && \
288 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f && \
289 (__t2=(uint8_t)((s)[(i)+1]-0x80))<= 0x3f \
292 (c)=(UChar)(((c)<<12)|(__t1<<6)|__t2); \
295 ((c)<0xe0 && (c)>=0xc2) && \
297 (__t1=(uint8_t)((s)[i]-0x80))<=0x3f \
299 (c)=(UChar)((((c)&0x1f)<<6)|__t1); \
301 } else if(U8_IS_LEAD(c)) { \
303 (c)=utf8_nextCharSafeBody((const uint8_t *)s, &(i), (int32_t)(length), c, -1); \
323 #define U8_APPEND_UNSAFE(s, i, c) { \
324 if((uint32_t)(c)<=0x7f) { \
325 (s)[(i)++]=(uint8_t)(c); \
327 if((uint32_t)(c)<=0x7ff) { \
328 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \
330 if((uint32_t)(c)<=0xffff) { \
331 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \
333 (s)[(i)++]=(uint8_t)(((c)>>18)|0xf0); \
334 (s)[(i)++]=(uint8_t)((((c)>>12)&0x3f)|0x80); \
336 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \
338 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
359 #define U8_APPEND(s, i, capacity, c, isError) { \
360 if((uint32_t)(c)<=0x7f) { \
361 (s)[(i)++]=(uint8_t)(c); \
362 } else if((uint32_t)(c)<=0x7ff && (i)+1<(capacity)) { \
363 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \
364 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
365 } else if((uint32_t)(c)<=0xd7ff && (i)+2<(capacity)) { \
366 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \
367 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \
368 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
370 (i)=utf8_appendCharSafeBody(s, (int32_t)(i), (int32_t)(capacity), c, &(isError)); \
384 #define U8_FWD_1_UNSAFE(s, i) { \
385 (i)+=1+U8_COUNT_TRAIL_BYTES((s)[i]); \
399 #define U8_FWD_1(s, i, length) { \
400 uint8_t __b=(uint8_t)(s)[(i)++]; \
401 if(U8_IS_LEAD(__b)) { \
402 uint8_t __count=U8_COUNT_TRAIL_BYTES(__b); \
403 if((i)+__count>(length)) { \
404 __count=(uint8_t)((length)-(i)); \
406 while(__count>0 && U8_IS_TRAIL((s)[i])) { \
425 #define U8_FWD_N_UNSAFE(s, i, n) { \
428 U8_FWD_1_UNSAFE(s, i); \
446 #define U8_FWD_N(s, i, length, n) { \
448 while(__N>0 && (i)<(length)) { \
449 U8_FWD_1(s, i, length); \
467 #define U8_SET_CP_START_UNSAFE(s, i) { \
468 while(U8_IS_TRAIL((s)[i])) { --(i); } \
485 #define U8_SET_CP_START(s, start, i) { \
486 if(U8_IS_TRAIL((s)[(i)])) { \
487 (i)=utf8_back1SafeBody(s, start, (int32_t)(i)); \
512 #define U8_PREV_UNSAFE(s, i, c) { \
513 (c)=(uint8_t)(s)[--(i)]; \
514 if(U8_IS_TRAIL(c)) { \
515 uint8_t __b, __count=1, __shift=6; \
520 __b=(uint8_t)(s)[--(i)]; \
522 U8_MASK_LEAD_BYTE(__b, __count); \
523 (c)|=(UChar32)__b<<__shift; \
526 (c)|=(UChar32)(__b&0x3f)<<__shift; \
554 #define U8_PREV(s, start, i, c) { \
555 (c)=(uint8_t)(s)[--(i)]; \
558 (c)=utf8_prevCharSafeBody((const uint8_t *)s, start, &(i), c, -1); \
576 #define U8_BACK_1_UNSAFE(s, i) { \
577 while(U8_IS_TRAIL((s)[--(i)])) {} \
592 #define U8_BACK_1(s, start, i) { \
593 if(U8_IS_TRAIL((s)[--(i)])) { \
594 (i)=utf8_back1SafeBody(s, start, (int32_t)(i)); \
611 #define U8_BACK_N_UNSAFE(s, i, n) { \
614 U8_BACK_1_UNSAFE(s, i); \
633 #define U8_BACK_N(s, start, i, n) { \
635 while(__N>0 && (i)>(start)) { \
636 U8_BACK_1(s, start, i); \
654 #define U8_SET_CP_LIMIT_UNSAFE(s, i) { \
655 U8_BACK_1_UNSAFE(s, i); \
656 U8_FWD_1_UNSAFE(s, i); \
674 #define U8_SET_CP_LIMIT(s, start, i, length) { \
675 if((start)<(i) && (i)<(length)) { \
676 U8_BACK_1(s, start, i); \
677 U8_FWD_1(s, i, length); \