--- Represent/Represent.cpp 2004/12/25 04:46:32 392 +++ Represent/Represent.cpp 2004/12/25 06:32:04 393 @@ -75,8 +75,6 @@ void Represent::parse() query = content; } -// api::Cout << query << ios::NewLine; - ext::Vector pairs(query.Split('&')); _foreach (ext::Vector, pair, pairs) @@ -84,10 +82,25 @@ void Represent::parse() ext::String::ConstIterator equal(pair->FindFirst('=')); ext::String name(pair->Begin(), equal), value(equal != pair->End() ? equal + 1 : equal, pair->End()); - // XXX: clean up %20, etc. + cgi.insert(std::pair(decode(name), decode(value))); + } +} + +std::string Represent::decode(const ext::String& encoded) +{ + std::string decoded(encoded); + std::string::size_type pos(0); - cgi.insert(std::pair(name, value)); + while ((pos = decoded.find_first_of("%+", pos)) != std::string::npos) switch (decoded[pos]) + { + case '%': + decoded.replace(pos, 3, 1, Hexadecimal(decoded.substr(pos + 1, 2), false).convert(false)); + break; + case '+': + decoded[pos] = ' '; } + + return decoded; } void Represent::headings(xml::TextWriter& xhtml) @@ -173,7 +186,7 @@ void Represent::output(xml::TextWriter& MultiMapConstIterator type(cgi.lower_bound("type")), type_(cgi.upper_bound("type")), data(cgi.lower_bound("data")), data_(cgi.upper_bound("data")), input(cgi.lower_bound("input")), input_(cgi.upper_bound("input")); ext::Vector items; - _foru (index, 0, *count.begin()) + _foru (index, 0, *count.begin() < 128 ? *count.begin() : 128) { Item item(DataType(type != type_ ? type->second : std::string()), data != data_ ? data->second : std::string(), InputType(input != input_ ? input->second : std::string())); @@ -364,22 +377,29 @@ void Represent::normal(xml::TextWriter& xhtml.OutputText(lexical_cast(type)); } +// XXX: damn, this one is really quite screwy template <> void Represent::normal(xml::TextWriter& xhtml, const char& char_) { - xhtml.OutputText(ext::CodePoint(char_)); + xhtml.OutputText("'"); + xhtml.OutputText(std::string(1, char_).c_str()); + xhtml.OutputText("'"); } template <> void Represent::normal(xml::TextWriter& xhtml, const std::string& string) { + xhtml.OutputText("\""); xhtml.OutputText(string); + xhtml.OutputText("\""); } template <> void Represent::normal(xml::TextWriter& xhtml, const ext::String& string) { + xhtml.OutputText("\""); xhtml.OutputText(string); + xhtml.OutputText("\""); } template @@ -400,6 +420,9 @@ void Represent::binary(xml::TextWriter& xml::ScopeElement(xhtml, "br"); xhtml.OutputText(Binary(*atom)); + xhtml.OutputText(" = '"); + xhtml.OutputText(ext::CodePoint(*atom)); + xhtml.OutputText("'"); } } @@ -415,6 +438,9 @@ void Represent::binary(xml::TextWriter& xml::ScopeElement(xhtml, "br"); xhtml.OutputText(Binary(*atom)); + xhtml.OutputText(" = '"); + xhtml.OutputText(ext::CodePoint(*atom)); + xhtml.OutputText("'"); } } @@ -435,7 +461,10 @@ void Represent::hexadecimal(xml::TextWri { xml::ScopeElement(xhtml, "br"); - xhtml.OutputText(Hexadecimal(string)); + xhtml.OutputText(Hexadecimal(*atom)); + xhtml.OutputText(" = '"); + xhtml.OutputText(ext::CodePoint(*atom)); + xhtml.OutputText("'"); } } @@ -450,6 +479,9 @@ void Represent::hexadecimal(xml::TextWri { xml::ScopeElement(xhtml, "br"); - xhtml.OutputText(Hexadecimal(string)); + xhtml.OutputText(Hexadecimal(*atom)); + xhtml.OutputText(" = '"); + xhtml.OutputText(ext::CodePoint(*atom)); + xhtml.OutputText("'"); } }