"Fossies" - the Fresh Open Source Software Archive

Member "htmlrecode-1.3.1/htmlrecode.hh" (21 Jul 2009, 2371 Bytes) of package /linux/www/old/htmlrecode-1.3.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "htmlrecode.hh" see the Fossies "Dox" file reference documentation.

    1 #define __ENABLE_WSTRING 1
    2 #include <cstdio>   // FILE
    3 #include <string>   // string,wstring
    4 #include <iconv.h>  // iconv_t
    5 #include <vector>   // vector
    6 
    7 #include "autoptr"
    8 
    9 using namespace std;
   10 
   11 //#define wstring ucs4string
   12 typedef wchar_t ucs4;
   13 //typedef unsigned int ucs4;
   14 //typedef basic_string<ucs4> wstring;
   15 
   16 // Note: address of ilseq must be available
   17 // Thus don't make this #define
   18 static const ucs4 ilseq = 0xFFFD;
   19 static const ucs4 ucsig = 0xFEFF;
   20 
   21 #if 1
   22 /* libstdc++ 2 way */
   23 static const wstring emptywstring;
   24 #define CLEARSTR(x) x=emptywstring
   25 #else
   26 /* libstdc++ 3 way */
   27 #define CLEARSTR(x) x.clear()
   28 #endif
   29 
   30 class Page
   31 {
   32     class Dumper
   33     {
   34         mutable iconv_t converter;
   35         mutable iconv_t tester;
   36         
   37         bool OpenConv(iconv_t &conv, const char *set1, const char *set2);
   38     public:
   39         string charset;
   40         
   41         Dumper();
   42         ~Dumper();
   43         void SetSet(const char *setname);
   44         
   45         void putc(ucs4 p) const;
   46         void puts(const wstring &s) const;
   47         
   48         bool isok(ucs4 p) const;
   49     } Dumper;
   50     
   51     bool CanDump(ucs4 p) const
   52     {
   53         return Dumper.isok(p);
   54     }
   55     
   56     mutable char underquote;
   57 
   58     wstring htmlencode(const wstring &s) const;
   59     wstring htmldecode(const wstring &s) const;
   60     
   61     void Putc(ucs4 p) const
   62     {
   63         Dumper.putc(p);
   64     }
   65     void Dump(const wstring &s) const
   66     {
   67         Dumper.puts(s);
   68     }
   69     void DumpHTML(const wstring &s) const
   70     {
   71         Dump(htmlencode(s));
   72     }
   73     void DumpHTML(const wstring &s, char quotetype) const
   74     {
   75         underquote = quotetype;
   76         DumpHTML(s);
   77         underquote = 0;
   78     }
   79     
   80     struct Tag;
   81     struct PI;
   82     
   83     void DumpTag(const Tag &) const;
   84     void DumpPI(const PI &) const;
   85     void DumpRaw(const wstring &) const;
   86     
   87     class Element : public ptrable
   88     {
   89     public:
   90         Element() {}
   91         virtual ~Element() {}
   92     };
   93     
   94     class ElemBody;
   95     class ElemTag;
   96     class ElemRaw;
   97     class ElemPI;
   98 
   99     vector<autoptr<Element> > Structure;
  100 
  101     void push_back(Element *e) { Structure.push_back(e); }
  102 
  103 public:
  104     void Dump() const;
  105     
  106     void SetOut(const char *midset);
  107 
  108     void FilterText(wstring (*proc)(const wstring &));
  109     void ParseUCS4(FILE *fp);
  110     void Parse(FILE *fp, const char *charset = "iso-8859-1");
  111     
  112     Page(): underquote(0) {}
  113 };