Diffstat (limited to 'noncore/apps/opie-reader/CRegExp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/CRegExp.cpp | 170 |
1 files changed, 85 insertions, 85 deletions
diff --git a/noncore/apps/opie-reader/CRegExp.cpp b/noncore/apps/opie-reader/CRegExp.cpp index 77dc2dc..6318d28 100644 --- a/noncore/apps/opie-reader/CRegExp.cpp +++ b/noncore/apps/opie-reader/CRegExp.cpp | |||
@@ -48,291 +48,291 @@ void CRegExpFilt::regchar(tchar c, bool insens) | |||
48 | { | 48 | { |
49 | tchar t = upper(c); | 49 | tchar t = upper(c); |
50 | CV[t] = 0; | 50 | CV[t] = 0; |
51 | t = lower(c); | 51 | t = lower(c); |
52 | CV[t] = 0; | 52 | CV[t] = 0; |
53 | } | 53 | } |
54 | else | 54 | else |
55 | { | 55 | { |
56 | CV[c] = 0; | 56 | CV[c] = 0; |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | void CRegExpFilt::prepreprocessing(const QString& pat, bool insens) | 60 | void CRegExpFilt::prepreprocessing(const QString& pat, bool insens) |
61 | { | 61 | { |
62 | for (unsigned int p = 0; p < pat.length(); p++) | 62 | for (unsigned int p = 0; p < pat.length(); p++) |
63 | { | 63 | { |
64 | #ifdef _WINDOWS | 64 | #ifdef _WINDOWS |
65 | switch (pat.at(p).unicode()) | 65 | switch (pat.at(p).unicode()) |
66 | #else | 66 | #else |
67 | switch (pat[p].unicode()) | 67 | switch (pat[p].unicode()) |
68 | #endif | 68 | #endif |
69 | { | 69 | { |
70 | case '{': | 70 | case '{': |
71 | { | 71 | { |
72 | break; | 72 | break; |
73 | } | 73 | } |
74 | case '}': | 74 | case '}': |
75 | { | 75 | { |
76 | break; | 76 | break; |
77 | } | 77 | } |
78 | case '^': | 78 | case '^': |
79 | { | 79 | { |
80 | break; | 80 | break; |
81 | } | 81 | } |
82 | case '.' : | 82 | case '.' : |
83 | { | 83 | { |
84 | break; | 84 | break; |
85 | } | 85 | } |
86 | case '#': | 86 | case '#': |
87 | { | 87 | { |
88 | p++; | 88 | p++; |
89 | #ifdef _WINDOWS | 89 | #ifdef _WINDOWS |
90 | while ('0' <= pat.at(p).unicode() && pat.at(p).unicode() <= '9') | 90 | while ('0' <= pat.at(p).unicode() && pat.at(p).unicode() <= '9') |
91 | #else | 91 | #else |
92 | while ('0' <= pat[p].unicode() && pat[p].unicode() <= '9') | 92 | while ('0' <= pat[p].unicode() && pat[p].unicode() <= '9') |
93 | #endif | 93 | #endif |
94 | { | 94 | { |
95 | } | 95 | } |
96 | p--; | 96 | p--; |
97 | break; | 97 | break; |
98 | } | 98 | } |
99 | case '\\' : | 99 | case '\\' : |
100 | { | 100 | { |
101 | #ifdef _WINDOWS | 101 | #ifdef _WINDOWS |
102 | tchar c = escapedchar(pat.at(++p).unicode()); | 102 | tchar c = escapedchar(pat.at(++p).unicode()); |
103 | #else | 103 | #else |
104 | tchar c = escapedchar(pat[++p].unicode()); | 104 | tchar c = escapedchar(pat[++p].unicode()); |
105 | #endif | 105 | #endif |
106 | regchar(c, insens); | 106 | regchar(c, insens); |
107 | break; | 107 | break; |
108 | } | 108 | } |
109 | 109 | ||
110 | case '[' : | 110 | case '[' : |
111 | { | 111 | { |
112 | tchar clast; | 112 | tchar clast; |
113 | bool invert = false; | 113 | bool invert = false; |
114 | tchar c; | 114 | tchar c; |
115 | #ifdef _WINDOWS | 115 | #ifdef _WINDOWS |
116 | if (pat.at(p+1).unicode() == '^') | 116 | if (pat.at(p+1).unicode() == '^') |
117 | #else | 117 | #else |
118 | if (pat[p+1].unicode() == '^') | 118 | if (pat[p+1].unicode() == '^') |
119 | #endif | 119 | #endif |
120 | { | 120 | { |
121 | p++; | 121 | p++; |
122 | invert = true; | 122 | invert = true; |
123 | } | 123 | } |
124 | #ifdef _WINDOWS | 124 | #ifdef _WINDOWS |
125 | while ((c = pat.at(++p).unicode()) != ']') | 125 | while ((c = pat.at(++p).unicode()) != ']') |
126 | #else | 126 | #else |
127 | while ((c = pat[++p].unicode()) != ']') | 127 | while ((c = pat[++p].unicode()) != ']') |
128 | #endif | 128 | #endif |
129 | { | 129 | { |
130 | if (c == '\\') | 130 | if (c == '\\') |
131 | { | 131 | { |
132 | #ifdef _WINDOWS | 132 | #ifdef _WINDOWS |
133 | c = escapedchar(pat.at(++p).unicode()); | 133 | c = escapedchar(pat.at(++p).unicode()); |
134 | #else | 134 | #else |
135 | c = escapedchar(pat[++p].unicode()); | 135 | c = escapedchar(pat[++p].unicode()); |
136 | #endif | 136 | #endif |
137 | if (c == ']') break; | 137 | if (c == ']') break; |
138 | } | 138 | } |
139 | if (c == '-') | 139 | if (c == '-') |
140 | { | 140 | { |
141 | #ifdef _WINDOWS | 141 | #ifdef _WINDOWS |
142 | c = pat.at(++p).unicode(); | 142 | c = pat.at(++p).unicode(); |
143 | #else | 143 | #else |
144 | c = pat[++p].unicode(); | 144 | c = pat[++p].unicode(); |
145 | #endif | 145 | #endif |
146 | for (tchar j = clast; j <= c; j++) | 146 | for (tchar j = clast; j <= c; j++) |
147 | { | 147 | { |
148 | regchar(j, insens); | 148 | regchar(j, insens); |
149 | } | 149 | } |
150 | } | 150 | } |
151 | else | 151 | else |
152 | { | 152 | { |
153 | regchar(c, insens); | 153 | regchar(c, insens); |
154 | } | 154 | } |
155 | clast = c; | 155 | clast = c; |
156 | } | 156 | } |
157 | break; | 157 | break; |
158 | } | 158 | } |
159 | default : | 159 | default : |
160 | { | 160 | { |
161 | #ifdef _WINDOWS | 161 | #ifdef _WINDOWS |
162 | regchar(pat.at(p).unicode(), insens); | 162 | regchar(pat.at(p).unicode(), insens); |
163 | #else | 163 | #else |
164 | regchar(pat[p].unicode(), insens); | 164 | regchar(pat[p].unicode(), insens); |
165 | #endif | 165 | #endif |
166 | break; | 166 | break; |
167 | } | 167 | } |
168 | } | 168 | } |
169 | } | 169 | } |
170 | /* | 170 | /* |
171 | for (iter i = CV.begin(); i != CV.end(); ++i) | 171 | for (iter i = CV.begin(); i != CV.end(); ++i) |
172 | { | 172 | { |
173 | printf("Pre: [%u]\n", i.first()); | 173 | printf("Pre: [%u]\n", i.first()); |
174 | } | 174 | } |
175 | */ | 175 | */ |
176 | CV[0] = 0; | 176 | CV[0] = 0; |
177 | } | 177 | } |
178 | 178 | ||
179 | unsigned int CRegExpFilt::preprocessing(const QString& pat, bool insens) | 179 | unsigned int CRegExpFilt::preprocessing(const QString& pat, bool insens) |
180 | { | 180 | { |
181 | prepreprocessing(pat, insens); | 181 | prepreprocessing(pat, insens); |
182 | qDebug("PrePreProcessing done"); | 182 | qDebug("PrePreProcessing done"); |
183 | unsigned int p, m; | 183 | unsigned int p, m; |
184 | bool inkeep = false; | 184 | bool inkeep = false; |
185 | keep = 0; | 185 | keep = 0; |
186 | replace = 0; | 186 | replace = 0; |
187 | for (unsigned int j = 0; j < WORD_SIZE; j++) | 187 | for (unsigned int j = 0; j < WORD_SIZE; j++) |
188 | { | 188 | { |
189 | bit[j] = (1 << (WORD_SIZE -j -1)); | 189 | bit[j] = (1 << (WORD_SIZE -j -1)); |
190 | lfcnt[j] = 0; | 190 | lfcnt[j] = 0; |
191 | } | 191 | } |
192 | 192 | ||
193 | for (p = 0, m = 0; p < pat.length(); p++) | 193 | for (p = 0, m = 0; p < pat.length(); p++) |
194 | { | 194 | { |
195 | qDebug("m is %u", m); | 195 | qDebug("m is %u", m); |
196 | if (inkeep) keep |= bit[m]; | 196 | if (inkeep) keep |= bit[m]; |
197 | #ifdef _WINDOWS | 197 | #ifdef _WINDOWS |
198 | switch (pat.at(p).unicode()) | 198 | switch (pat.at(p).unicode()) |
199 | #else | 199 | #else |
200 | switch (pat[p].unicode()) | 200 | switch (pat[p].unicode()) |
201 | #endif | 201 | #endif |
202 | { | 202 | { |
203 | case '{': | 203 | case '{': |
204 | { | 204 | { |
205 | inkeep = true; | 205 | inkeep = true; |
206 | break; | 206 | break; |
207 | } | 207 | } |
208 | case '}': | 208 | case '}': |
209 | { | 209 | { |
210 | keep ^= bit[m]; | 210 | keep ^= bit[m]; |
211 | inkeep = false; | 211 | inkeep = false; |
212 | break; | 212 | break; |
213 | } | 213 | } |
214 | case '^': | 214 | case '^': |
215 | { | 215 | { |
216 | replace |= bit[m]; | 216 | replace |= bit[m]; |
217 | lfcnt[m]++; | 217 | lfcnt[m]++; |
218 | break; | 218 | break; |
219 | } | 219 | } |
220 | case '.' : | 220 | case '.' : |
221 | { | 221 | { |
222 | for (iter j = CV.begin(); j != CV.end(); ++j) CV[j.first()] |= bit[m]; | 222 | for (iter j = CV.begin(); j != CV.end(); ++j) CV[j.first()] |= bit[m]; |
223 | m++; | 223 | m++; |
224 | break; | 224 | break; |
225 | } | 225 | } |
226 | case '#': | 226 | case '#': |
227 | { | 227 | { |
228 | if (m > 0) | 228 | if (m > 0) |
229 | { | 229 | { |
230 | p++; | 230 | p++; |
231 | int count = 0; | 231 | int count = 0; |
232 | #ifdef _WINDOWS | 232 | #ifdef _WINDOWS |
233 | while ('0' <= pat.at(p).unicode() && pat.at(p).unicode() <= '9') | 233 | while ('0' <= pat.at(p).unicode() && pat.at(p).unicode() <= '9') |
234 | #else | 234 | #else |
235 | while ('0' <= pat[p].unicode() && pat[p].unicode() <= '9') | 235 | while ('0' <= pat[p].unicode() && pat[p].unicode() <= '9') |
236 | #endif | 236 | #endif |
237 | { | 237 | { |
238 | #ifdef _WINDOWS | 238 | #ifdef _WINDOWS |
239 | count = 10*count + pat.at(p++).unicode() - '0'; | 239 | count = 10*count + pat.at(p++).unicode() - '0'; |
240 | #else | 240 | #else |
241 | count = 10*count + pat[p++].unicode() - '0'; | 241 | count = 10*count + pat[p++].unicode() - '0'; |
242 | #endif | 242 | #endif |
243 | } | 243 | } |
244 | p--; | 244 | p--; |
245 | count = count-1; | 245 | count = count-1; |
246 | unsigned int mask = 0; | 246 | unsigned int mask = 0; |
247 | for (unsigned int i = m; i < m+count; i++) | 247 | for (unsigned int i = m; i < m+count; i++) |
248 | { | 248 | { |
249 | mask |= bit[i]; | 249 | mask |= bit[i]; |
250 | } | 250 | } |
251 | 251 | ||
252 | for (iter it = CV.begin(); it != CV.end(); ++it) | 252 | for (iter it = CV.begin(); it != CV.end(); ++it) |
253 | { | 253 | { |
254 | if (CV[it.first()] & bit[m-1]) | 254 | if (CV[it.first()] & bit[m-1]) |
255 | { | 255 | { |
256 | CV[it.first()] |= mask; | 256 | CV[it.first()] |= mask; |
257 | } | 257 | } |
258 | } | 258 | } |
259 | if (keep & bit[m-1]) keep |= mask; | 259 | if (keep & bit[m-1]) keep |= mask; |
260 | m += count; | 260 | m += count; |
261 | } | 261 | } |
262 | else | 262 | else |
263 | { | 263 | { |
264 | p++; | 264 | p++; |
265 | } | 265 | } |
266 | break; | 266 | break; |
267 | } | 267 | } |
268 | case '\\' : | 268 | case '\\' : |
269 | { | 269 | { |
270 | #ifdef _WINDOWS | 270 | #ifdef _WINDOWS |
271 | tchar c = escapedchar(pat.at(++p).unicode()); | 271 | tchar c = escapedchar(pat.at(++p).unicode()); |
272 | #else | 272 | #else |
273 | tchar c = escapedchar(pat[++p].unicode()); | 273 | tchar c = escapedchar(pat[++p].unicode()); |
274 | #endif | 274 | #endif |
275 | if (insens) | 275 | if (insens) |
276 | { | 276 | { |
277 | CV[upper(c)] |= bit[m]; | 277 | CV[upper(c)] |= bit[m]; |
278 | CV[lower(c)] |= bit[m]; | 278 | CV[lower(c)] |= bit[m]; |
279 | } | 279 | } |
280 | else | 280 | else |
281 | { | 281 | { |
282 | CV[c] |= bit[m]; | 282 | CV[c] |= bit[m]; |
283 | } | 283 | } |
284 | m++; | 284 | m++; |
285 | break; | 285 | break; |
286 | } | 286 | } |
287 | 287 | ||
288 | case '[' : | 288 | case '[' : |
289 | { | 289 | { |
290 | tchar c, clast; | 290 | tchar c, clast; |
291 | bool invert = false; | 291 | bool invert = false; |
292 | #ifdef _WINDOWS | 292 | #ifdef _WINDOWS |
293 | if (pat.at(p+1).unicode() == '^') | 293 | if (pat.at(p+1).unicode() == '^') |
294 | #else | 294 | #else |
295 | if (pat[p+1].unicode() == '^') | 295 | if (pat[p+1].unicode() == '^') |
296 | #endif | 296 | #endif |
297 | { | 297 | { |
298 | p++; | 298 | p++; |
299 | invert = true; | 299 | invert = true; |
300 | } | 300 | } |
301 | #ifdef _WINDOWS | 301 | #ifdef _WINDOWS |
302 | while ((c = pat.at(++p).unicode()) != ']') | 302 | while ((c = pat.at(++p).unicode()) != ']') |
303 | #else | 303 | #else |
304 | while ((c = pat[++p].unicode()) != ']') | 304 | while ((c = pat[++p].unicode()) != ']') |
305 | #endif | 305 | #endif |
306 | { | 306 | { |
307 | if (c == '\\') | 307 | if (c == '\\') |
308 | { | 308 | { |
309 | #ifdef _WINDOWS | 309 | #ifdef _WINDOWS |
310 | c = escapedchar(pat.at(++p).unicode()); | 310 | c = escapedchar(pat.at(++p).unicode()); |
311 | #else | 311 | #else |
312 | c = escapedchar(pat[++p].unicode()); | 312 | c = escapedchar(pat[++p].unicode()); |
313 | #endif | 313 | #endif |
314 | if (c == ']') break; | 314 | if (c == ']') break; |
315 | } | 315 | } |
316 | if (c == '-') | 316 | if (c == '-') |
317 | { | 317 | { |
318 | #ifdef _WINDOWS | 318 | #ifdef _WINDOWS |
319 | c = pat.at(++p).unicode(); | 319 | c = pat.at(++p).unicode(); |
320 | #else | 320 | #else |
321 | c = pat[++p].unicode(); | 321 | c = pat[++p].unicode(); |
322 | #endif | 322 | #endif |
323 | for (tchar j = clast; j <= c; j++) | 323 | for (tchar j = clast; j <= c; j++) |
324 | { | 324 | { |
325 | if (insens) | 325 | if (insens) |
326 | { | 326 | { |
327 | iter it; | 327 | iter it; |
328 | if ((it = CV.find(upper(j))) != CV.end()) | 328 | if ((it = CV.find(upper(j))) != CV.end()) |
329 | CV[it] |= bit[m]; | 329 | CV[it] |= bit[m]; |
330 | else | 330 | else |
331 | CV[0] |= bit[m]; | 331 | CV[0] |= bit[m]; |
332 | if ((it = CV.find(lower(j))) != CV.end()) | 332 | if ((it = CV.find(lower(j))) != CV.end()) |
333 | CV[it] |= bit[m]; | 333 | CV[it] |= bit[m]; |
334 | else | 334 | else |
335 | CV[0] |= bit[m]; | 335 | CV[0] |= bit[m]; |
336 | } | 336 | } |
337 | else | 337 | else |
338 | { | 338 | { |
@@ -369,38 +369,38 @@ unsigned int CRegExpFilt::preprocessing(const QString& pat, bool insens) | |||
369 | CV[0] |= bit[m]; | 369 | CV[0] |= bit[m]; |
370 | } | 370 | } |
371 | } | 371 | } |
372 | clast = c; | 372 | clast = c; |
373 | } | 373 | } |
374 | if (invert) | 374 | if (invert) |
375 | { | 375 | { |
376 | for (iter i = CV.begin(); i != CV.end(); ++i) | 376 | for (iter i = CV.begin(); i != CV.end(); ++i) |
377 | { | 377 | { |
378 | CV[i.first()] ^= bit[m]; | 378 | CV[i.first()] ^= bit[m]; |
379 | } | 379 | } |
380 | } | 380 | } |
381 | m++; | 381 | m++; |
382 | break; | 382 | break; |
383 | } | 383 | } |
384 | default : | 384 | default : |
385 | { | 385 | { |
386 | #ifdef _WINDOWS | 386 | #ifdef _WINDOWS |
387 | tchar c = pat.at(p).unicode(); | 387 | tchar c = pat.at(p).unicode(); |
388 | #else | 388 | #else |
389 | tchar c = pat[p].unicode(); | 389 | tchar c = pat[p].unicode(); |
390 | #endif | 390 | #endif |
391 | if (insens) | 391 | if (insens) |
392 | { | 392 | { |
393 | CV[upper(c)] |= bit[m]; | 393 | CV[upper(c)] |= bit[m]; |
394 | CV[lower(c)] |= bit[m]; | 394 | CV[lower(c)] |= bit[m]; |
395 | } | 395 | } |
396 | else CV[c] |= bit[m]; | 396 | else CV[c] |= bit[m]; |
397 | m++; | 397 | m++; |
398 | break; | 398 | break; |
399 | } | 399 | } |
400 | } | 400 | } |
401 | } | 401 | } |
402 | qDebug("Returning:%u",m); | 402 | qDebug("Returning:%u",m); |
403 | return m; | 403 | return m; |
404 | } | 404 | } |
405 | 405 | ||
406 | bool CRegExpFilt::empty() | 406 | bool CRegExpFilt::empty() |