00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "uscanset.h"
00020
00021
00022 UBool
00023 u_scanf_scanset_add(u_scanf_scanset *scanset,
00024 UChar c)
00025 {
00026 if(scanset->single_count == U_SCANF_MAX_SCANSET_SIZE - 1)
00027 return FALSE;
00028
00029 scanset->singles[ scanset->single_count ] = c;
00030 (scanset->single_count)++;
00031
00032 return TRUE;
00033 }
00034
00035 UBool
00036 u_scanf_scanset_addrange(u_scanf_scanset *scanset,
00037 UChar start,
00038 UChar end)
00039 {
00040 if(scanset->pair_count == U_SCANF_MAX_SCANSET_SIZE - 1)
00041 return FALSE;
00042
00043 scanset->pairs[ scanset->pair_count ].start = start;
00044 scanset->pairs[ scanset->pair_count ].end = end;
00045
00046 (scanset->pair_count)++;
00047
00048 return TRUE;
00049 }
00050
00051 UBool
00052 u_scanf_scanset_init(u_scanf_scanset *scanset,
00053 const UChar *s,
00054 int32_t *len)
00055 {
00056 UChar c;
00057 const UChar *limit;
00058 int32_t count;
00059 UBool result;
00060
00061
00062
00063 limit = s + *len;
00064 count = 0;
00065
00066
00067 scanset->single_count = 0;
00068 scanset->pair_count = 0;
00069 scanset->is_inclusive = TRUE;
00070
00071
00072 if(*s == 0x005E) {
00073 scanset->is_inclusive = FALSE;
00074
00075
00076 ++s;
00077 ++count;
00078 }
00079
00080
00081 else if(*s == 0x005D) {
00082 result = u_scanf_scanset_add(scanset, *s++);
00083
00084
00085 ++count;
00086 }
00087
00088
00089 if( ! scanset->is_inclusive && *s == 0x005D) {
00090 result = u_scanf_scanset_add(scanset, *s++);
00091
00092
00093 ++count;
00094 }
00095
00096
00097 while(s < limit) {
00098
00099
00100 c = *s++;
00101
00102
00103 if(c == 0x005D)
00104 break;
00105
00106
00107 if(*s == 0x002D && *(s+1) != 0x005D) {
00108 result = u_scanf_scanset_addrange(scanset, c, *(s+1));
00109
00110
00111 s += 2;
00112 count += 2;
00113 }
00114
00115
00116 else {
00117 result = u_scanf_scanset_add(scanset, c);
00118 }
00119
00120
00121 ++count;
00122 }
00123
00124
00125 *len = count;
00126 return result;
00127 }
00128
00129 UBool
00130 u_scanf_scanset_in(u_scanf_scanset *scanset,
00131 UChar c)
00132 {
00133 int i;
00134
00135
00136 if(scanset->is_inclusive) {
00137
00138
00139 for(i = 0; i < scanset->single_count; ++i) {
00140 if(c == scanset->singles[i])
00141 return TRUE;
00142 }
00143
00144
00145 for(i = 0; i < scanset->pair_count; ++i) {
00146 if(c >= scanset->pairs[i].start && c <= scanset->pairs[i].end)
00147 return TRUE;
00148 }
00149
00150
00151 return FALSE;
00152 }
00153
00154
00155 else {
00156
00157
00158 for(i = 0; i < scanset->single_count; ++i) {
00159 if(c == scanset->singles[i])
00160 return FALSE;
00161 }
00162
00163
00164 for(i = 0; i < scanset->pair_count; ++i) {
00165 if(c >= scanset->pairs[i].start && c <= scanset->pairs[i].end)
00166 return FALSE;
00167 }
00168
00169
00170 return TRUE;
00171 }
00172 }
00173
00174
00175
00176
00177
00178
00179
00180