00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00030 #ifndef __UTF32_H__
00031 #define __UTF32_H__
00032
00033
00034
00035 #define UTF32_IS_SAFE(c, strict) \
00036 ((uint32_t)(c)<=0x10ffff && \
00037 (!(strict) || !UTF_IS_SURROGATE(c) && ((c)&0xfffe)!=0xfffe))
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #define UTF32_IS_SINGLE(uchar) 1
00049 #define UTF32_IS_LEAD(uchar) 0
00050 #define UTF32_IS_TRAIL(uchar) 0
00051
00052
00053 #define UTF32_NEED_MULTIPLE_UCHAR(c) 0
00054 #define UTF32_CHAR_LENGTH(c) 1
00055 #define UTF32_MAX_CHAR_LENGTH 1
00056
00057
00058 #define UTF32_ARRAY_SIZE(size) (size)
00059
00060 #define UTF32_GET_CHAR_UNSAFE(s, i, c) { \
00061 (c)=(s)[i]; \
00062 }
00063
00064 #define UTF32_GET_CHAR_SAFE(s, start, i, length, c, strict) { \
00065 (c)=(s)[i]; \
00066 if(!UTF32_IS_SAFE(c, strict)) { \
00067 (c)=UTF_ERROR_VALUE; \
00068 } \
00069 }
00070
00071
00072
00073 #define UTF32_NEXT_CHAR_UNSAFE(s, i, c) { \
00074 (c)=(s)[(i)++]; \
00075 }
00076
00077 #define UTF32_APPEND_CHAR_UNSAFE(s, i, c) { \
00078 (s)[(i)++]=(c); \
00079 }
00080
00081 #define UTF32_FWD_1_UNSAFE(s, i) { \
00082 ++(i); \
00083 }
00084
00085 #define UTF32_FWD_N_UNSAFE(s, i, n) { \
00086 (i)+=(n); \
00087 }
00088
00089 #define UTF32_SET_CHAR_START_UNSAFE(s, i) { \
00090 }
00091
00092 #define UTF32_NEXT_CHAR_SAFE(s, i, length, c, strict) { \
00093 (c)=(s)[(i)++]; \
00094 if(!UTF32_IS_SAFE(c, strict)) { \
00095 (c)=UTF_ERROR_VALUE; \
00096 } \
00097 }
00098
00099 #define UTF32_APPEND_CHAR_SAFE(s, i, length, c) { \
00100 if((uint32_t)(c)<=0x10ffff) { \
00101 (s)[(i)++]=(c); \
00102 } else { \
00103 (s)[(i)++]=0xfffd; \
00104 } \
00105 }
00106
00107 #define UTF32_FWD_1_SAFE(s, i, length) { \
00108 ++(i); \
00109 }
00110
00111 #define UTF32_FWD_N_SAFE(s, i, length, n) { \
00112 if(((i)+=(n))>(length)) { \
00113 (i)=(length); \
00114 } \
00115 }
00116
00117 #define UTF32_SET_CHAR_START_SAFE(s, start, i) { \
00118 }
00119
00120
00121
00122 #define UTF32_PREV_CHAR_UNSAFE(s, i, c) { \
00123 (c)=(s)[--(i)]; \
00124 }
00125
00126 #define UTF32_BACK_1_UNSAFE(s, i) { \
00127 --(i); \
00128 }
00129
00130 #define UTF32_BACK_N_UNSAFE(s, i, n) { \
00131 (i)-=(n); \
00132 }
00133
00134 #define UTF32_SET_CHAR_LIMIT_UNSAFE(s, i) { \
00135 }
00136
00137 #define UTF32_PREV_CHAR_SAFE(s, start, i, c, strict) { \
00138 (c)=(s)[--(i)]; \
00139 if(!UTF32_IS_SAFE(c, strict)) { \
00140 (c)=UTF_ERROR_VALUE; \
00141 } \
00142 }
00143
00144 #define UTF32_BACK_1_SAFE(s, start, i) { \
00145 --(i); \
00146 }
00147
00148 #define UTF32_BACK_N_SAFE(s, start, i, n) { \
00149 (i)-=(n); \
00150 if((i)<(start)) { \
00151 (i)=(start); \
00152 } \
00153 }
00154
00155 #define UTF32_SET_CHAR_LIMIT_SAFE(s, i, length) { \
00156 }
00157
00158 #endif