10 |
|
#include <menes-api/exename.hpp> |
11 |
|
#include <menes-api/files.hpp> |
12 |
|
#include <menes-app/application.hpp> |
13 |
+ |
#include <menes-ext/stack.hpp> |
14 |
|
|
15 |
|
struct IffyCommand : public app::Application |
16 |
|
{ |
82 |
|
|
83 |
|
void Iffy::iffy(ios::Reader& in, ios::Writer& out) |
84 |
|
{ |
85 |
+ |
ios::FormatWriter fout(out); |
86 |
+ |
|
87 |
+ |
fout << "<html>"; |
88 |
+ |
|
89 |
|
ext::String segment; |
90 |
|
bool text(true); |
91 |
< |
ios::FormatWriter fout(out); |
91 |
> |
ext::Stack<ext::String> opens; |
92 |
|
|
93 |
|
while (read(in, segment, text)) if (text) |
94 |
|
{ |
95 |
< |
fout << segment << ios::Flush; |
95 |
> |
fout << segment; |
96 |
|
|
97 |
|
text = false; |
98 |
|
} |
102 |
|
|
103 |
|
if (tag == "br") tag = STANDALONE; |
104 |
|
|
105 |
< |
// XXX: automagically fix |
105 |
> |
switch (tag) |
106 |
> |
{ |
107 |
> |
case OPEN: |
108 |
> |
opens.Push(tag); |
109 |
> |
|
110 |
> |
break; |
111 |
> |
case CLOSE: |
112 |
> |
if (tag != opens.Top()) tag = opens.Top(); |
113 |
> |
|
114 |
> |
opens.Pop(); |
115 |
> |
|
116 |
> |
break; |
117 |
> |
default: |
118 |
> |
break; |
119 |
> |
} |
120 |
|
|
121 |
< |
fout << tag << ios::Flush; |
121 |
> |
fout << tag; |
122 |
|
|
123 |
|
text = true; |
124 |
|
} |
125 |
+ |
|
126 |
+ |
fout << "</html>\n"; |
127 |
|
} |
128 |
|
|
129 |
|
bool Iffy::read(ios::Reader& in, ext::String& segment, bool text) |