author | llornkcor <llornkcor> | 2002-07-01 23:24:08 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-07-01 23:24:08 (UTC) |
commit | 59222a752fa4c8a1e8c2a00ee2f9e22855f12bb2 (patch) (unidiff) | |
tree | f148d4858859dac3b413e675c760acfdab24b8e6 /noncore/apps/opie-reader/CFilter.h | |
parent | c08be8ae22dcc1bfb83cfdec807149b161d770f5 (diff) | |
download | opie-59222a752fa4c8a1e8c2a00ee2f9e22855f12bb2.zip opie-59222a752fa4c8a1e8c2a00ee2f9e22855f12bb2.tar.gz opie-59222a752fa4c8a1e8c2a00ee2f9e22855f12bb2.tar.bz2 |
initial
Diffstat (limited to 'noncore/apps/opie-reader/CFilter.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/CFilter.h | 354 |
1 files changed, 354 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/CFilter.h b/noncore/apps/opie-reader/CFilter.h new file mode 100644 index 0000000..4f609dc --- a/dev/null +++ b/noncore/apps/opie-reader/CFilter.h | |||
@@ -0,0 +1,354 @@ | |||
1 | #ifndef __CFILTER_H | ||
2 | #define __CFILTER_H | ||
3 | |||
4 | #include "CExpander.h" | ||
5 | #include "CEncoding.h" | ||
6 | |||
7 | class CFilter : public CCharacterSource | ||
8 | { | ||
9 | friend class CFilterChain; | ||
10 | protected: | ||
11 | CCharacterSource* parent; | ||
12 | public: | ||
13 | CFilter() : parent(NULL) {} | ||
14 | void setparent(CCharacterSource* p) { parent = p; } | ||
15 | virtual ~CFilter() {}; | ||
16 | }; | ||
17 | |||
18 | class vanilla : public CFilter | ||
19 | { | ||
20 | public: | ||
21 | vanilla() {} | ||
22 | virtual ~vanilla() {} | ||
23 | #ifdef _UNICODE | ||
24 | virtual tchar getch() | ||
25 | #else | ||
26 | virtual int getch() | ||
27 | #endif | ||
28 | { | ||
29 | return parent->getch(); | ||
30 | } | ||
31 | }; | ||
32 | |||
33 | class CFilterChain | ||
34 | { | ||
35 | CExpander* expander; | ||
36 | CEncoding* encoder; | ||
37 | CFilter* first; | ||
38 | CCharacterSource* front; | ||
39 | public: | ||
40 | CFilterChain(CEncoding* _e) : encoder(_e), first(NULL), front(_e) {}; | ||
41 | ~CFilterChain() | ||
42 | { | ||
43 | CCharacterSource* p = front; | ||
44 | while (p != encoder) | ||
45 | { | ||
46 | CFilter* pnext = (CFilter*)p; | ||
47 | p = ((CFilter*)p)->parent; | ||
48 | delete pnext; | ||
49 | } | ||
50 | delete encoder; | ||
51 | } | ||
52 | int getch() { return front->getch(); } | ||
53 | void addfilter(CFilter* p) | ||
54 | { | ||
55 | if (first == NULL) | ||
56 | { | ||
57 | front = first = p; | ||
58 | p->setparent(encoder); | ||
59 | } | ||
60 | else | ||
61 | { | ||
62 | p->setparent(front); | ||
63 | front = p; | ||
64 | } | ||
65 | } | ||
66 | void setsource(CExpander* p) | ||
67 | { | ||
68 | expander = p; | ||
69 | encoder->setparent(p); | ||
70 | } | ||
71 | void setencoder(CEncoding* p) | ||
72 | { | ||
73 | delete encoder; | ||
74 | encoder = p; | ||
75 | first->setparent(p); | ||
76 | encoder->setparent(expander); | ||
77 | } | ||
78 | }; | ||
79 | |||
80 | class stripcr : public CFilter | ||
81 | { | ||
82 | public: | ||
83 | stripcr() {} | ||
84 | virtual ~stripcr() {} | ||
85 | #ifdef _UNICODE | ||
86 | virtual tchar getch() | ||
87 | { | ||
88 | tchar ch; | ||
89 | do | ||
90 | { | ||
91 | ch = parent->getch(); | ||
92 | } | ||
93 | while (ch == 13); | ||
94 | return ch; | ||
95 | } | ||
96 | #else | ||
97 | virtual int getch() | ||
98 | { | ||
99 | int ch; | ||
100 | do | ||
101 | { | ||
102 | ch = parent->getch(); | ||
103 | } | ||
104 | while (ch == 13); | ||
105 | return ch; | ||
106 | } | ||
107 | #endif | ||
108 | }; | ||
109 | |||
110 | class dehyphen : public CFilter | ||
111 | { | ||
112 | bool m_bCharWaiting; | ||
113 | tchar m_nextChar; | ||
114 | public: | ||
115 | dehyphen() : m_bCharWaiting(false) {} | ||
116 | virtual ~dehyphen() {} | ||
117 | virtual tchar getch() | ||
118 | { | ||
119 | if (m_bCharWaiting) | ||
120 | { | ||
121 | m_bCharWaiting = false; | ||
122 | return m_nextChar; | ||
123 | } | ||
124 | tchar ch = parent->getch(); | ||
125 | if (ch != '-') return ch; | ||
126 | m_nextChar = parent->getch(); | ||
127 | if (m_nextChar != 10) | ||
128 | { | ||
129 | m_bCharWaiting = true; | ||
130 | return '-'; | ||
131 | } | ||
132 | return parent->getch(); | ||
133 | } | ||
134 | }; | ||
135 | |||
136 | class striphtml : public CFilter | ||
137 | { | ||
138 | public: | ||
139 | striphtml() {} | ||
140 | virtual ~striphtml() {} | ||
141 | #ifdef _UNICODE | ||
142 | virtual tchar getch() | ||
143 | { | ||
144 | tchar ch; | ||
145 | ch = parent->getch(); | ||
146 | while (ch == '<') | ||
147 | { | ||
148 | while (ch != '>') | ||
149 | { | ||
150 | ch = parent->getch(); | ||
151 | } | ||
152 | ch = parent->getch(); | ||
153 | } | ||
154 | if (ch == '&') | ||
155 | { | ||
156 | ch = parent->getch(); | ||
157 | if (ch == '#') | ||
158 | { | ||
159 | int id = 0; | ||
160 | while ((ch = parent->getch()) != ';') id = 10*id+ch-'0'; | ||
161 | ch = id; | ||
162 | } | ||
163 | } | ||
164 | return ch; | ||
165 | } | ||
166 | #else | ||
167 | virtual int getch() | ||
168 | { | ||
169 | int ch; | ||
170 | ch = parent->getch(); | ||
171 | while (ch == '<') | ||
172 | { | ||
173 | while (ch != '>') | ||
174 | { | ||
175 | ch = parent->getch(); | ||
176 | } | ||
177 | ch = parent->getch(); | ||
178 | } | ||
179 | if (ch == '&') | ||
180 | { | ||
181 | ch = parent->getch(); | ||
182 | if (ch == '#') | ||
183 | { | ||
184 | int id = 0; | ||
185 | while ((ch = parent->getch()) != ';') id = 10*id+ch-'0'; | ||
186 | ch = id; | ||
187 | } | ||
188 | } | ||
189 | return ch; | ||
190 | } | ||
191 | #endif | ||
192 | }; | ||
193 | |||
194 | class unindent : public CFilter | ||
195 | { | ||
196 | tchar lc; | ||
197 | public: | ||
198 | unindent() : lc(0) {} | ||
199 | virtual ~unindent() {} | ||
200 | #ifdef _UNICODE | ||
201 | virtual tchar getch() | ||
202 | { | ||
203 | tchar ch; | ||
204 | if (lc == 10) | ||
205 | { | ||
206 | while ((ch = parent->getch()) == ' '); | ||
207 | } | ||
208 | else ch = parent->getch(); | ||
209 | lc = ch; | ||
210 | return ch; | ||
211 | } | ||
212 | #else | ||
213 | virtual int getch() | ||
214 | { | ||
215 | int ch; | ||
216 | if (lc == 10) | ||
217 | { | ||
218 | while ((ch = parent->getch()) == ' '); | ||
219 | } | ||
220 | else ch = parent->getch(); | ||
221 | lc = ch; | ||
222 | return ch; | ||
223 | } | ||
224 | #endif | ||
225 | }; | ||
226 | |||
227 | #ifdef _UNICODE | ||
228 | class repara : public CFilter | ||
229 | { | ||
230 | tchar tch; | ||
231 | public: | ||
232 | repara() : tch(0) {} | ||
233 | virtual ~repara() {} | ||
234 | virtual tchar getch() | ||
235 | { | ||
236 | tchar ch = parent->getch(); | ||
237 | if (ch == 10) | ||
238 | { | ||
239 | if (tch == 10) | ||
240 | { | ||
241 | return ch; | ||
242 | } | ||
243 | else | ||
244 | { | ||
245 | tch = ch; | ||
246 | return ' '; | ||
247 | } | ||
248 | } | ||
249 | tch = ch; | ||
250 | return ch; | ||
251 | } | ||
252 | }; | ||
253 | #else | ||
254 | class repara : public CFilter | ||
255 | { | ||
256 | int tch; | ||
257 | public: | ||
258 | repara() : tch(0) {} | ||
259 | virtual ~repara() {} | ||
260 | virtual int getch() | ||
261 | { | ||
262 | int ch = parent->getch(); | ||
263 | if (ch == 10) | ||
264 | { | ||
265 | if (tch == 10) | ||
266 | { | ||
267 | return ch; | ||
268 | } | ||
269 | else | ||
270 | { | ||
271 | tch = ch; | ||
272 | return ' '; | ||
273 | } | ||
274 | } | ||
275 | tch = ch; | ||
276 | return ch; | ||
277 | } | ||
278 | }; | ||
279 | #endif | ||
280 | |||
281 | class indenter : public CFilter | ||
282 | { | ||
283 | int amnt; | ||
284 | int indent; | ||
285 | public: | ||
286 | indenter(int _a=5) : amnt(_a), indent(0) {} | ||
287 | virtual ~indenter() {} | ||
288 | #ifdef _UNICODE | ||
289 | virtual tchar getch() | ||
290 | { | ||
291 | if (indent > 0) | ||
292 | { | ||
293 | indent--; | ||
294 | return ' '; | ||
295 | } | ||
296 | tchar ch = parent->getch(); | ||
297 | if (ch == 10) | ||
298 | { | ||
299 | indent = amnt; | ||
300 | } | ||
301 | return ch; | ||
302 | } | ||
303 | #else | ||
304 | virtual int getch() | ||
305 | { | ||
306 | if (indent > 0) | ||
307 | { | ||
308 | indent--; | ||
309 | return ' '; | ||
310 | } | ||
311 | int ch = parent->getch(); | ||
312 | if (ch == 10) | ||
313 | { | ||
314 | indent = amnt; | ||
315 | } | ||
316 | return ch; | ||
317 | } | ||
318 | #endif | ||
319 | }; | ||
320 | |||
321 | class dblspce : public CFilter | ||
322 | { | ||
323 | bool lastlf; | ||
324 | public: | ||
325 | dblspce() : lastlf(false) {} | ||
326 | virtual ~dblspce() {} | ||
327 | #ifdef _UNICODE | ||
328 | virtual tchar getch() | ||
329 | { | ||
330 | if (lastlf) | ||
331 | { | ||
332 | lastlf = false; | ||
333 | return 10; | ||
334 | } | ||
335 | tchar ch = parent->getch(); | ||
336 | lastlf = (ch == 10); | ||
337 | return ch; | ||
338 | } | ||
339 | #else | ||
340 | virtual int getch() | ||
341 | { | ||
342 | if (lastlf) | ||
343 | { | ||
344 | lastlf = false; | ||
345 | return 10; | ||
346 | } | ||
347 | int ch = parent->getch(); | ||
348 | lastlf = (ch == 10); | ||
349 | return ch; | ||
350 | } | ||
351 | #endif | ||
352 | }; | ||
353 | |||
354 | #endif | ||