| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 1999-2004, International Business Machines Corporation and oth
ers. All Rights Reserved. | |
| 3 * | |
| 4 */ | |
| 5 | |
| 6 #ifndef UnicodeMacrosFromICU_h | |
| 7 #define UnicodeMacrosFromICU_h | |
| 8 | |
| 9 // some defines from ICU | |
| 10 | |
| 11 #define U_IS_BMP(c) ((UChar32)(c)<=0xffff) | |
| 12 #define U16_IS_LEAD(c) (((c)&0xfffffc00)==0xd800) | |
| 13 #define U16_IS_TRAIL(c) (((c)&0xfffffc00)==0xdc00) | |
| 14 #define U16_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000) | |
| 15 #define U16_GET_SUPPLEMENTARY(lead, trail) \ | |
| 16 (((UChar32)(lead)<<10UL)+(UChar32)(trail)-U16_SURROGATE_OFFSET) | |
| 17 | |
| 18 #define U16_LEAD(supplementary) (UChar)(((supplementary)>>10)+0xd7c0) | |
| 19 #define U16_TRAIL(supplementary) (UChar)(((supplementary)&0x3ff)|0xdc00) | |
| 20 #define U16_LENGTH(c) ((uint32_t)(c) <= 0xffff ? 1 : 2) | |
| 21 | |
| 22 #define U_IS_SUPPLEMENTARY(c) ((UChar32)((c)-0x10000)<=0xfffff) | |
| 23 #define U_IS_SURROGATE(c) (((c)&0xfffff800)==0xd800) | |
| 24 #define U16_IS_SINGLE(c) !U_IS_SURROGATE(c) | |
| 25 #define U16_IS_SURROGATE(c) U_IS_SURROGATE(c) | |
| 26 #define U16_IS_SURROGATE_LEAD(c) (((c)&0x400)==0) | |
| 27 | |
| 28 #define U16_GET(s, start, i, length, c) { \ | |
| 29 (c)=(s)[i]; \ | |
| 30 if(U16_IS_SURROGATE(c)) { \ | |
| 31 uint16_t __c2; \ | |
| 32 if(U16_IS_SURROGATE_LEAD(c)) { \ | |
| 33 if((i)+1<(length) && U16_IS_TRAIL(__c2=(s)[(i)+1])) { \ | |
| 34 (c)=U16_GET_SUPPLEMENTARY((c), __c2); \ | |
| 35 } \ | |
| 36 } else { \ | |
| 37 if((i)-1>=(start) && U16_IS_LEAD(__c2=(s)[(i)-1])) { \ | |
| 38 (c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \ | |
| 39 } \ | |
| 40 } \ | |
| 41 } \ | |
| 42 } | |
| 43 | |
| 44 #define U16_PREV(s, start, i, c) { \ | |
| 45 (c)=(s)[--(i)]; \ | |
| 46 if(U16_IS_TRAIL(c)) { \ | |
| 47 uint16_t __c2; \ | |
| 48 if((i)>(start) && U16_IS_LEAD(__c2=(s)[(i)-1])) { \ | |
| 49 --(i); \ | |
| 50 (c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \ | |
| 51 } \ | |
| 52 } \ | |
| 53 } | |
| 54 | |
| 55 #define U16_BACK_1(s, start, i) { \ | |
| 56 if(U16_IS_TRAIL((s)[--(i)]) && (i)>(start) && U16_IS_LEAD((s)[(i)-1])) { \ | |
| 57 --(i); \ | |
| 58 } \ | |
| 59 } | |
| 60 | |
| 61 #define U16_NEXT(s, i, length, c) { \ | |
| 62 (c)=(s)[(i)++]; \ | |
| 63 if(U16_IS_LEAD(c)) { \ | |
| 64 uint16_t __c2; \ | |
| 65 if((i)<(length) && U16_IS_TRAIL(__c2=(s)[(i)])) { \ | |
| 66 ++(i); \ | |
| 67 (c)=U16_GET_SUPPLEMENTARY((c), __c2); \ | |
| 68 } \ | |
| 69 } \ | |
| 70 } | |
| 71 | |
| 72 #define U16_FWD_1(s, i, length) { \ | |
| 73 if(U16_IS_LEAD((s)[(i)++]) && (i)<(length) && U16_IS_TRAIL((s)[i])) { \ | |
| 74 ++(i); \ | |
| 75 } \ | |
| 76 } | |
| 77 | |
| 78 #define U_MASK(x) ((uint32_t)1<<(x)) | |
| 79 | |
| 80 #define U8_MAX_LENGTH 4 | |
| 81 | |
| 82 #define U8_APPEND_UNSAFE(s, i, c) { \ | |
| 83 if((uint32_t)(c)<=0x7f) { \ | |
| 84 (s)[(i)++]=(uint8_t)(c); \ | |
| 85 } else { \ | |
| 86 if((uint32_t)(c)<=0x7ff) { \ | |
| 87 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \ | |
| 88 } else { \ | |
| 89 if((uint32_t)(c)<=0xffff) { \ | |
| 90 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \ | |
| 91 } else { \ | |
| 92 (s)[(i)++]=(uint8_t)(((c)>>18)|0xf0); \ | |
| 93 (s)[(i)++]=(uint8_t)((((c)>>12)&0x3f)|0x80); \ | |
| 94 } \ | |
| 95 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \ | |
| 96 } \ | |
| 97 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \ | |
| 98 } \ | |
| 99 } | |
| 100 #endif | |
| OLD | NEW |