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 @@ -6,59 +6,47 @@ class CFilter : public CCharacterSource { friend class CFilterChain; protected: CCharacterSource* parent; public: CFilter() : parent(NULL) {} void setparent(CCharacterSource* p) { parent = p; } virtual ~CFilter() {}; }; -class vanilla : public CFilter -{ -public: - vanilla() {} - virtual ~vanilla() {} -#ifdef _UNICODE - virtual tchar getch() -#else - virtual int getch() -#endif - { - return parent->getch(); - } -}; - class CFilterChain { CExpander* expander; CEncoding* encoder; CFilter* first; CCharacterSource* front; public: CFilterChain(CEncoding* _e) : encoder(_e), first(NULL), front(_e) {}; ~CFilterChain() { CCharacterSource* p = front; while (p != encoder) { CFilter* pnext = (CFilter*)p; p = ((CFilter*)p)->parent; delete pnext; } delete encoder; } - int getch() { return front->getch(); } + void getch(tchar& ch, CStyle& sty) + { + front->getch(ch, sty); + } void addfilter(CFilter* p) { if (first == NULL) { front = first = p; p->setparent(encoder); } else { p->setparent(front); front = p; } @@ -73,282 +61,209 @@ class CFilterChain delete encoder; encoder = p; first->setparent(p); encoder->setparent(expander); } }; class stripcr : public CFilter { public: stripcr() {} virtual ~stripcr() {} -#ifdef _UNICODE - virtual tchar getch() - { - tchar ch; - do - { - ch = parent->getch(); - } - while (ch == 13); - return ch; - } -#else - virtual int getch() + virtual void getch(tchar& ch, CStyle& sty) { - int ch; do { - ch = parent->getch(); + parent->getch(ch, sty); } while (ch == 13); - return ch; } -#endif }; class dehyphen : public CFilter { bool m_bCharWaiting; tchar m_nextChar; + CStyle m_nextSty; public: dehyphen() : m_bCharWaiting(false) {} virtual ~dehyphen() {} - virtual tchar getch() + virtual void getch(tchar& ch, CStyle& sty) { if (m_bCharWaiting) { m_bCharWaiting = false; - return m_nextChar; + ch = m_nextChar; + sty = m_nextSty; + return; } - tchar ch = parent->getch(); - if (ch != '-') return ch; - m_nextChar = parent->getch(); + parent->getch(ch, sty); + if (ch != '-') return; + parent->getch(m_nextChar, m_nextSty); if (m_nextChar != 10) { m_bCharWaiting = true; - return '-'; + ch = '-'; + return; } - return parent->getch(); + parent->getch(ch, sty); } }; class striphtml : public CFilter { + CStyle currentstyle; + unsigned short skip_ws(); + unsigned short skip_ws_end(); + unsigned short parse_m(); + void mygetch(tchar& ch, CStyle& sty); public: striphtml() {} virtual ~striphtml() {} -#ifdef _UNICODE - virtual tchar getch() - { - tchar ch; - ch = parent->getch(); - while (ch == '<') - { - while (ch != '>') - { - ch = parent->getch(); - } - ch = parent->getch(); - } - if (ch == '&') - { - ch = parent->getch(); - if (ch == '#') - { - int id = 0; - while ((ch = parent->getch()) != ';') id = 10*id+ch-'0'; - ch = id; - } - } - return ch; - } -#else - virtual int getch() - { - int ch; - ch = parent->getch(); - while (ch == '<') - { - while (ch != '>') - { - ch = parent->getch(); - } - ch = parent->getch(); - } - if (ch == '&') - { - ch = parent->getch(); - if (ch == '#') - { - int id = 0; - while ((ch = parent->getch()) != ';') id = 10*id+ch-'0'; - ch = id; - } - } - return ch; - } -#endif + virtual void getch(tchar& ch, CStyle& sty); }; class unindent : public CFilter { tchar lc; public: unindent() : lc(0) {} virtual ~unindent() {} -#ifdef _UNICODE - virtual tchar getch() + virtual void getch(tchar& ch, CStyle& sty) { - tchar ch; if (lc == 10) { - while ((ch = parent->getch()) == ' '); - } - else ch = parent->getch(); - lc = ch; - return ch; - } -#else - virtual int getch() - { - int ch; - if (lc == 10) + do { - while ((ch = parent->getch()) == ' '); + parent->getch(ch, sty); + } + while (ch == ' '); } - else ch = parent->getch(); + else parent->getch(ch, sty); lc = ch; - return ch; + return; } -#endif }; -#ifdef _UNICODE class repara : public CFilter { tchar tch; public: repara() : tch(0) {} virtual ~repara() {} - virtual tchar getch() - { - tchar ch = parent->getch(); - if (ch == 10) - { - if (tch == 10) - { - return ch; - } - else - { - tch = ch; - return ' '; - } - } - tch = ch; - return ch; - } -}; -#else -class repara : public CFilter -{ - int tch; -public: - repara() : tch(0) {} - virtual ~repara() {} - virtual int getch() + virtual void getch(tchar& ch, CStyle& sty) { - int ch = parent->getch(); + parent->getch(ch, sty); if (ch == 10) { if (tch == 10) { - return ch; + return; } else { tch = ch; - return ' '; + ch = ' '; + return; } } tch = ch; - return ch; + return; } }; -#endif class indenter : public CFilter { int amnt; int indent; + CStyle lsty; public: indenter(int _a=5) : amnt(_a), indent(0) {} virtual ~indenter() {} -#ifdef _UNICODE - virtual tchar getch() - { - if (indent > 0) - { - indent--; - return ' '; - } - tchar ch = parent->getch(); - if (ch == 10) - { - indent = amnt; - } - return ch; - } -#else - virtual int getch() + virtual void getch(tchar& ch, CStyle& sty) { if (indent > 0) { indent--; - return ' '; + ch = ' '; + sty = lsty; + return; } - int ch = parent->getch(); + parent->getch(ch, sty); if (ch == 10) { indent = amnt; + lsty = sty; } - return ch; + return; } -#endif }; class dblspce : public CFilter { bool lastlf; + CStyle lsty; public: dblspce() : lastlf(false) {} virtual ~dblspce() {} -#ifdef _UNICODE - virtual tchar getch() + virtual void getch(tchar& ch, CStyle& sty) { if (lastlf) { lastlf = false; - return 10; + ch = 10; + sty = lsty; + return; + } + parent->getch(ch, sty); + if (lastlf = (ch == 10)) + { + lsty = sty; } - tchar ch = parent->getch(); - lastlf = (ch == 10); - return ch; + return; } -#else - virtual int getch() +}; + +class textfmt : public CFilter { - if (lastlf) + CStyle currentstyle; + tchar lastchar; + bool uselast; + void mygetch(tchar&, CStyle&); + public: + textfmt() : lastchar(0), uselast(false) {} + virtual ~textfmt() {} + virtual void getch(tchar& ch, CStyle& sty); +}; + +class embolden : public CFilter { - lastlf = false; - return 10; - } - int ch = parent->getch(); - lastlf = (ch == 10); - return ch; + public: + embolden() {} + virtual ~embolden() {} + virtual void getch(tchar& ch, CStyle& sty) + { + parent->getch(ch, sty); + sty.setBold(); } -#endif }; +class remap : public CFilter +{ + tchar q[3]; + int offset; + CStyle currentstyle; + public: + remap() : offset(0) { q[0] = 0; } + virtual ~remap() {} + virtual void getch(tchar& ch, CStyle& sty); +}; + +class PeanutFormatter : public CFilter +{ + CStyle currentstyle; + public: + virtual ~PeanutFormatter() {} + virtual void getch(tchar& ch, CStyle& sty); +}; #endif |