author | llornkcor <llornkcor> | 2002-09-14 02:19:09 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-09-14 02:19:09 (UTC) |
commit | 2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975 (patch) (unidiff) | |
tree | eeed16b5f80dd5883991a7a06133f5f7a6936256 /noncore/apps/opie-reader/CFilter.h | |
parent | 5a95ed6a000a56849b8f093deea500214856c626 (diff) | |
download | opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.zip opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.tar.gz opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.tar.bz2 |
update by Tim
Diffstat (limited to 'noncore/apps/opie-reader/CFilter.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/CFilter.h | 407 |
1 files changed, 161 insertions, 246 deletions
diff --git a/noncore/apps/opie-reader/CFilter.h b/noncore/apps/opie-reader/CFilter.h index 4f609dc..8cfd7eb 100644 --- a/noncore/apps/opie-reader/CFilter.h +++ b/noncore/apps/opie-reader/CFilter.h | |||
@@ -6,28 +6,13 @@ | |||
6 | 6 | ||
7 | class CFilter : public CCharacterSource | 7 | class CFilter : public CCharacterSource |
8 | { | 8 | { |
9 | friend class CFilterChain; | 9 | friend class CFilterChain; |
10 | protected: | 10 | protected: |
11 | CCharacterSource* parent; | 11 | CCharacterSource* parent; |
12 | public: | 12 | public: |
13 | CFilter() : parent(NULL) {} | 13 | CFilter() : parent(NULL) {} |
14 | void setparent(CCharacterSource* p) { parent = p; } | 14 | void setparent(CCharacterSource* p) { parent = p; } |
15 | virtual ~CFilter() {}; | 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 | }; | 16 | }; |
32 | 17 | ||
33 | class CFilterChain | 18 | class CFilterChain |
@@ -49,7 +34,10 @@ class CFilterChain | |||
49 | } | 34 | } |
50 | delete encoder; | 35 | delete encoder; |
51 | } | 36 | } |
52 | int getch() { return front->getch(); } | 37 | void getch(tchar& ch, CStyle& sty) |
38 | { | ||
39 | front->getch(ch, sty); | ||
40 | } | ||
53 | void addfilter(CFilter* p) | 41 | void addfilter(CFilter* p) |
54 | { | 42 | { |
55 | if (first == NULL) | 43 | if (first == NULL) |
@@ -79,276 +67,203 @@ class CFilterChain | |||
79 | 67 | ||
80 | class stripcr : public CFilter | 68 | class stripcr : public CFilter |
81 | { | 69 | { |
82 | public: | 70 | public: |
83 | stripcr() {} | 71 | stripcr() {} |
84 | virtual ~stripcr() {} | 72 | virtual ~stripcr() {} |
85 | #ifdef _UNICODE | 73 | virtual void getch(tchar& ch, CStyle& sty) |
86 | virtual tchar getch() | 74 | { |
87 | { | 75 | do |
88 | tchar ch; | 76 | { |
89 | do | 77 | parent->getch(ch, sty); |
90 | { | 78 | } |
91 | ch = parent->getch(); | 79 | while (ch == 13); |
92 | } | 80 | } |
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 | }; | 81 | }; |
109 | 82 | ||
110 | class dehyphen : public CFilter | 83 | class dehyphen : public CFilter |
111 | { | 84 | { |
112 | bool m_bCharWaiting; | 85 | bool m_bCharWaiting; |
113 | tchar m_nextChar; | 86 | tchar m_nextChar; |
87 | CStyle m_nextSty; | ||
114 | public: | 88 | public: |
115 | dehyphen() : m_bCharWaiting(false) {} | 89 | dehyphen() : m_bCharWaiting(false) {} |
116 | virtual ~dehyphen() {} | 90 | virtual ~dehyphen() {} |
117 | virtual tchar getch() | 91 | virtual void getch(tchar& ch, CStyle& sty) |
118 | { | 92 | { |
119 | if (m_bCharWaiting) | 93 | if (m_bCharWaiting) |
120 | { | 94 | { |
121 | m_bCharWaiting = false; | 95 | m_bCharWaiting = false; |
122 | return m_nextChar; | 96 | ch = m_nextChar; |
97 | sty = m_nextSty; | ||
98 | return; | ||
123 | } | 99 | } |
124 | tchar ch = parent->getch(); | 100 | parent->getch(ch, sty); |
125 | if (ch != '-') return ch; | 101 | if (ch != '-') return; |
126 | m_nextChar = parent->getch(); | 102 | parent->getch(m_nextChar, m_nextSty); |
127 | if (m_nextChar != 10) | 103 | if (m_nextChar != 10) |
128 | { | 104 | { |
129 | m_bCharWaiting = true; | 105 | m_bCharWaiting = true; |
130 | return '-'; | 106 | ch = '-'; |
107 | return; | ||
131 | } | 108 | } |
132 | return parent->getch(); | 109 | parent->getch(ch, sty); |
133 | } | 110 | } |
134 | }; | 111 | }; |
135 | 112 | ||
136 | class striphtml : public CFilter | 113 | class striphtml : public CFilter |
137 | { | 114 | { |
138 | public: | 115 | CStyle currentstyle; |
139 | striphtml() {} | 116 | unsigned short skip_ws(); |
140 | virtual ~striphtml() {} | 117 | unsigned short skip_ws_end(); |
141 | #ifdef _UNICODE | 118 | unsigned short parse_m(); |
142 | virtual tchar getch() | 119 | void mygetch(tchar& ch, CStyle& sty); |
143 | { | 120 | public: |
144 | tchar ch; | 121 | striphtml() {} |
145 | ch = parent->getch(); | 122 | virtual ~striphtml() {} |
146 | while (ch == '<') | 123 | virtual void getch(tchar& ch, CStyle& sty); |
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 | }; | 124 | }; |
193 | 125 | ||
194 | class unindent : public CFilter | 126 | class unindent : public CFilter |
195 | { | 127 | { |
196 | tchar lc; | 128 | tchar lc; |
197 | public: | 129 | public: |
198 | unindent() : lc(0) {} | 130 | unindent() : lc(0) {} |
199 | virtual ~unindent() {} | 131 | virtual ~unindent() {} |
200 | #ifdef _UNICODE | 132 | virtual void getch(tchar& ch, CStyle& sty) |
201 | virtual tchar getch() | 133 | { |
202 | { | 134 | if (lc == 10) |
203 | tchar ch; | 135 | { |
204 | if (lc == 10) | 136 | do |
205 | { | 137 | { |
206 | while ((ch = parent->getch()) == ' '); | 138 | parent->getch(ch, sty); |
207 | } | 139 | } |
208 | else ch = parent->getch(); | 140 | while (ch == ' '); |
209 | lc = ch; | 141 | } |
210 | return ch; | 142 | else parent->getch(ch, sty); |
211 | } | 143 | lc = ch; |
212 | #else | 144 | return; |
213 | virtual int getch() | 145 | } |
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 | }; | 146 | }; |
226 | 147 | ||
227 | #ifdef _UNICODE | ||
228 | class repara : public CFilter | 148 | class repara : public CFilter |
229 | { | 149 | { |
230 | tchar tch; | 150 | tchar tch; |
231 | public: | 151 | public: |
232 | repara() : tch(0) {} | 152 | repara() : tch(0) {} |
233 | virtual ~repara() {} | 153 | virtual ~repara() {} |
234 | virtual tchar getch() | 154 | virtual void getch(tchar& ch, CStyle& sty) |
235 | { | 155 | { |
236 | tchar ch = parent->getch(); | 156 | parent->getch(ch, sty); |
237 | if (ch == 10) | 157 | if (ch == 10) |
238 | { | 158 | { |
239 | if (tch == 10) | 159 | if (tch == 10) |
240 | { | 160 | { |
241 | return ch; | 161 | return; |
242 | } | 162 | } |
243 | else | 163 | else |
244 | { | 164 | { |
245 | tch = ch; | 165 | tch = ch; |
246 | return ' '; | 166 | ch = ' '; |
247 | } | 167 | return; |
248 | } | 168 | } |
249 | tch = ch; | 169 | } |
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; | 170 | tch = ch; |
272 | return ' '; | 171 | return; |
273 | } | 172 | } |
274 | } | ||
275 | tch = ch; | ||
276 | return ch; | ||
277 | } | ||
278 | }; | 173 | }; |
279 | #endif | ||
280 | 174 | ||
281 | class indenter : public CFilter | 175 | class indenter : public CFilter |
282 | { | 176 | { |
283 | int amnt; | 177 | int amnt; |
284 | int indent; | 178 | int indent; |
285 | public: | 179 | CStyle lsty; |
286 | indenter(int _a=5) : amnt(_a), indent(0) {} | 180 | public: |
287 | virtual ~indenter() {} | 181 | indenter(int _a=5) : amnt(_a), indent(0) {} |
288 | #ifdef _UNICODE | 182 | virtual ~indenter() {} |
289 | virtual tchar getch() | 183 | virtual void getch(tchar& ch, CStyle& sty) |
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 | { | 184 | { |
314 | indent = amnt; | 185 | if (indent > 0) |
186 | { | ||
187 | indent--; | ||
188 | ch = ' '; | ||
189 | sty = lsty; | ||
190 | return; | ||
191 | } | ||
192 | parent->getch(ch, sty); | ||
193 | if (ch == 10) | ||
194 | { | ||
195 | indent = amnt; | ||
196 | lsty = sty; | ||
197 | } | ||
198 | return; | ||
315 | } | 199 | } |
316 | return ch; | ||
317 | } | ||
318 | #endif | ||
319 | }; | 200 | }; |
320 | 201 | ||
321 | class dblspce : public CFilter | 202 | class dblspce : public CFilter |
322 | { | 203 | { |
323 | bool lastlf; | 204 | bool lastlf; |
324 | public: | 205 | CStyle lsty; |
325 | dblspce() : lastlf(false) {} | 206 | public: |
326 | virtual ~dblspce() {} | 207 | dblspce() : lastlf(false) {} |
327 | #ifdef _UNICODE | 208 | virtual ~dblspce() {} |
328 | virtual tchar getch() | 209 | virtual void getch(tchar& ch, CStyle& sty) |
329 | { | ||
330 | if (lastlf) | ||
331 | { | 210 | { |
332 | lastlf = false; | 211 | if (lastlf) |
333 | return 10; | 212 | { |
213 | lastlf = false; | ||
214 | ch = 10; | ||
215 | sty = lsty; | ||
216 | return; | ||
217 | } | ||
218 | parent->getch(ch, sty); | ||
219 | if (lastlf = (ch == 10)) | ||
220 | { | ||
221 | lsty = sty; | ||
222 | } | ||
223 | return; | ||
334 | } | 224 | } |
335 | tchar ch = parent->getch(); | 225 | }; |
336 | lastlf = (ch == 10); | 226 | |
337 | return ch; | 227 | class textfmt : public CFilter |
338 | } | 228 | { |
339 | #else | 229 | CStyle currentstyle; |
340 | virtual int getch() | 230 | tchar lastchar; |
341 | { | 231 | bool uselast; |
342 | if (lastlf) | 232 | void mygetch(tchar&, CStyle&); |
233 | public: | ||
234 | textfmt() : lastchar(0), uselast(false) {} | ||
235 | virtual ~textfmt() {} | ||
236 | virtual void getch(tchar& ch, CStyle& sty); | ||
237 | }; | ||
238 | |||
239 | class embolden : public CFilter | ||
240 | { | ||
241 | public: | ||
242 | embolden() {} | ||
243 | virtual ~embolden() {} | ||
244 | virtual void getch(tchar& ch, CStyle& sty) | ||
343 | { | 245 | { |
344 | lastlf = false; | 246 | parent->getch(ch, sty); |
345 | return 10; | 247 | sty.setBold(); |
346 | } | 248 | } |
347 | int ch = parent->getch(); | ||
348 | lastlf = (ch == 10); | ||
349 | return ch; | ||
350 | } | ||
351 | #endif | ||
352 | }; | 249 | }; |
353 | 250 | ||
251 | class remap : public CFilter | ||
252 | { | ||
253 | tchar q[3]; | ||
254 | int offset; | ||
255 | CStyle currentstyle; | ||
256 | public: | ||
257 | remap() : offset(0) { q[0] = 0; } | ||
258 | virtual ~remap() {} | ||
259 | virtual void getch(tchar& ch, CStyle& sty); | ||
260 | }; | ||
261 | |||
262 | class PeanutFormatter : public CFilter | ||
263 | { | ||
264 | CStyle currentstyle; | ||
265 | public: | ||
266 | virtual ~PeanutFormatter() {} | ||
267 | virtual void getch(tchar& ch, CStyle& sty); | ||
268 | }; | ||
354 | #endif | 269 | #endif |