ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Iffy/Iffy.cpp
(Generate patch)

Comparing Iffy/Iffy.cpp (file contents):
Revision 279 by Douglas Thrift, 2004-11-13T16:14:50-08:00 vs.
Revision 295 by douglas, 2004-12-11T01:01:55-08:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 < #include "Tag.hpp"
7 > #include "Cleaner.hpp"
8   #include "Matcher.hpp"
9  
10   #include <menes-api/exename.hpp>
# Line 52 | Line 52 | struct IffyCommand : public app::Applica
52  
53   Iffy::Iffy(const ext::String& in, const ext::String& out)
54   {
55 <        if (in == "-" && out == "-")
56 <        {
57 <                iffy(api::Cin, api::Cout);
58 <        }
59 <        else if (in == "-")
60 <        {
61 <                api::FileWriter fout(out);
62 <
63 <                iffy(api::Cin, fout);
64 <        }
65 <        else if (out == "-")
66 <        {
67 <                api::FileReader fin(in);
55 >        _H<ios::Reader> rin;
56 >        _H<ios::Writer> rout;
57  
58 <                iffy(fin, api::Cout);
59 <        }
71 <        else
72 <        {
73 <                api::FileReader fin(in);
74 <                api::FileWriter fout(out);
58 >        if (in == "-") rin = &api::Cin; else rin = new api::FileReader(in);
59 >        if (out == "-") rout = &api::Cout; else rout = new api::FileWriter(out);
60  
61 <                iffy(fin, fout);
77 <        }
61 >        iffy(*rin, *rout);
62   }
63  
64   ext::String Iffy::program;
# Line 82 | Line 66 | bool Iffy::debug(false);
66  
67   void Iffy::iffy(ios::Reader& in, ios::Writer& out)
68   {
69 <        ios::FormatWriter fout(out);
70 <
71 <        fout << "<html>";
69 >        ext::Buffer segment;
70 >        bool text(false);
71 >        Cleaner cleaner;
72  
73 <        ext::String segment;
90 <        bool text(true);
91 <        ext::Stack<ext::String> opens;
92 <
93 <        while (read(in, segment, text)) if (text)
73 >        while (read(in, segment, (text = !text))) if (text)
74          {
75 <                fout << segment;
96 <
97 <                text = false;
75 >                if (!segment.IsEmpty()) cleaner.insert(segment);
76          }
77          else
78          {
79 <                Tag tag(segment);
79 >                Matcher matcher;
80  
81 <                if (tag == "br") tag = STANDALONE;
104 <
105 <                switch (tag)
81 >                if (segment == matcher("^!--( \\(\\d{1,2}:\\d{2}:\\d{2} [AP]M\\))--$"))
82                  {
83 <                case OPEN:
108 <                        opens.Push(tag);
83 >                        cleaner.insert(matcher[1]);
84  
85 <                        break;
111 <                case CLOSE:
112 <                        if (tag != opens.Top()) tag = opens.Top();
113 <
114 <                        opens.Pop();
115 <
116 <                        break;
117 <                default:
118 <                        break;
85 >                        continue;
86                  }
87  
88 <                fout << tag;
88 >                Tag tag(segment);
89  
90 <                text = true;
90 >                if (tag == "br") tag = STANDALONE;
91 >
92 >                cleaner.insert(tag);
93          }
94  
95 <        fout << "</html>\n";
95 >        cleaner.clean();
96 >
97 >        ios::FormatWriter fout(out);
98 >
99 >        fout << cleaner << ios::NewLine;
100   }
101  
102 < bool Iffy::read(ios::Reader& in, ext::String& segment, bool text)
102 > bool Iffy::read(ios::Reader& in, ext::Buffer& segment, bool text)
103   {
104          segment.Clear();
105  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines