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