Diffstat (limited to 'noncore/apps/opie-reader/CFilter.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/CFilter.h | 273 |
1 files changed, 94 insertions, 179 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 | |||
@@ -15,21 +15,6 @@ public: | |||
15 | virtual ~CFilter() {}; | 15 | virtual ~CFilter() {}; |
16 | }; | 16 | }; |
17 | 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 | 18 | class CFilterChain |
34 | { | 19 | { |
35 | CExpander* expander; | 20 | CExpander* expander; |
@@ -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) |
@@ -82,113 +70,57 @@ class stripcr : public CFilter | |||
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() | ||
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 | { | 74 | { |
99 | int ch; | ||
100 | do | 75 | do |
101 | { | 76 | { |
102 | ch = parent->getch(); | 77 | parent->getch(ch, sty); |
103 | } | 78 | } |
104 | while (ch == 13); | 79 | while (ch == 13); |
105 | return ch; | ||
106 | } | 80 | } |
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 | { |
115 | CStyle currentstyle; | ||
116 | unsigned short skip_ws(); | ||
117 | unsigned short skip_ws_end(); | ||
118 | unsigned short parse_m(); | ||
119 | void mygetch(tchar& ch, CStyle& sty); | ||
138 | public: | 120 | public: |
139 | striphtml() {} | 121 | striphtml() {} |
140 | virtual ~striphtml() {} | 122 | virtual ~striphtml() {} |
141 | #ifdef _UNICODE | 123 | virtual void getch(tchar& ch, CStyle& sty); |
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 | }; | 124 | }; |
193 | 125 | ||
194 | class unindent : public CFilter | 126 | class unindent : public CFilter |
@@ -197,158 +129,141 @@ class unindent : public CFilter | |||
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() | ||
202 | { | 133 | { |
203 | tchar ch; | ||
204 | if (lc == 10) | 134 | if (lc == 10) |
205 | { | 135 | { |
206 | while ((ch = parent->getch()) == ' '); | 136 | do |
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 | { | 137 | { |
218 | while ((ch = parent->getch()) == ' '); | 138 | parent->getch(ch, sty); |
139 | } | ||
140 | while (ch == ' '); | ||
219 | } | 141 | } |
220 | else ch = parent->getch(); | 142 | else parent->getch(ch, sty); |
221 | lc = ch; | 143 | lc = ch; |
222 | return ch; | 144 | return; |
223 | } | 145 | } |
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 | { | ||
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 | { | 155 | { |
262 | int ch = parent->getch(); | 156 | parent->getch(ch, sty); |
263 | if (ch == 10) | 157 | if (ch == 10) |
264 | { | 158 | { |
265 | if (tch == 10) | 159 | if (tch == 10) |
266 | { | 160 | { |
267 | return ch; | 161 | return; |
268 | } | 162 | } |
269 | else | 163 | else |
270 | { | 164 | { |
271 | tch = ch; | 165 | tch = ch; |
272 | return ' '; | 166 | ch = ' '; |
167 | return; | ||
273 | } | 168 | } |
274 | } | 169 | } |
275 | tch = ch; | 170 | tch = ch; |
276 | return ch; | 171 | return; |
277 | } | 172 | } |
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; |
179 | CStyle lsty; | ||
285 | public: | 180 | public: |
286 | indenter(int _a=5) : amnt(_a), indent(0) {} | 181 | indenter(int _a=5) : amnt(_a), indent(0) {} |
287 | virtual ~indenter() {} | 182 | virtual ~indenter() {} |
288 | #ifdef _UNICODE | 183 | virtual void getch(tchar& ch, CStyle& sty) |
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 | { | 184 | { |
306 | if (indent > 0) | 185 | if (indent > 0) |
307 | { | 186 | { |
308 | indent--; | 187 | indent--; |
309 | return ' '; | 188 | ch = ' '; |
189 | sty = lsty; | ||
190 | return; | ||
310 | } | 191 | } |
311 | int ch = parent->getch(); | 192 | parent->getch(ch, sty); |
312 | if (ch == 10) | 193 | if (ch == 10) |
313 | { | 194 | { |
314 | indent = amnt; | 195 | indent = amnt; |
196 | lsty = sty; | ||
315 | } | 197 | } |
316 | return ch; | 198 | return; |
317 | } | 199 | } |
318 | #endif | ||
319 | }; | 200 | }; |
320 | 201 | ||
321 | class dblspce : public CFilter | 202 | class dblspce : public CFilter |
322 | { | 203 | { |
323 | bool lastlf; | 204 | bool lastlf; |
205 | CStyle lsty; | ||
324 | public: | 206 | public: |
325 | dblspce() : lastlf(false) {} | 207 | dblspce() : lastlf(false) {} |
326 | virtual ~dblspce() {} | 208 | virtual ~dblspce() {} |
327 | #ifdef _UNICODE | 209 | virtual void getch(tchar& ch, CStyle& sty) |
328 | virtual tchar getch() | ||
329 | { | 210 | { |
330 | if (lastlf) | 211 | if (lastlf) |
331 | { | 212 | { |
332 | lastlf = false; | 213 | lastlf = false; |
333 | return 10; | 214 | ch = 10; |
215 | sty = lsty; | ||
216 | return; | ||
217 | } | ||
218 | parent->getch(ch, sty); | ||
219 | if (lastlf = (ch == 10)) | ||
220 | { | ||
221 | lsty = sty; | ||
334 | } | 222 | } |
335 | tchar ch = parent->getch(); | 223 | return; |
336 | lastlf = (ch == 10); | ||
337 | return ch; | ||
338 | } | 224 | } |
339 | #else | 225 | }; |
340 | virtual int getch() | 226 | |
227 | class textfmt : public CFilter | ||
341 | { | 228 | { |
342 | if (lastlf) | 229 | CStyle currentstyle; |
230 | tchar lastchar; | ||
231 | bool uselast; | ||
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 | ||
343 | { | 240 | { |
344 | lastlf = false; | 241 | public: |
345 | return 10; | 242 | embolden() {} |
346 | } | 243 | virtual ~embolden() {} |
347 | int ch = parent->getch(); | 244 | virtual void getch(tchar& ch, CStyle& sty) |
348 | lastlf = (ch == 10); | 245 | { |
349 | return ch; | 246 | parent->getch(ch, sty); |
247 | sty.setBold(); | ||
350 | } | 248 | } |
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 |