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

Comparing Represent/Represent.cpp (file contents):
Revision 391 by douglas, 2004-12-24T20:31:04-08:00 vs.
Revision 394 by douglas, 2004-12-24T22:39:00-08:00

# Line 75 | Line 75 | void Represent::parse()
75                  query = content;
76          }
77  
78 //      api::Cout << query << ios::NewLine;
79
78          ext::Vector<ext::String> pairs(query.Split('&'));
79  
80          _foreach (ext::Vector<ext::String>, pair, pairs)
# Line 84 | Line 82 | void Represent::parse()
82                  ext::String::ConstIterator equal(pair->FindFirst('='));
83                  ext::String name(pair->Begin(), equal), value(equal != pair->End() ? equal + 1 : equal, pair->End());
84  
85 <                // XXX: clean up %20, etc.
85 >                cgi.insert(std::pair<std::string, std::string>(decode(name), decode(value)));
86 >        }
87 > }
88 >
89 > std::string Represent::decode(const ext::String& encoded)
90 > {
91 >        std::string decoded(encoded);
92 >        std::string::size_type pos(0);
93  
94 <                cgi.insert(std::pair<std::string, std::string>(name, value));
94 >        while ((pos = decoded.find_first_of("%+", pos)) != std::string::npos) switch (decoded[pos])
95 >        {
96 >        case '%':
97 >                decoded.replace(pos, 3, 1, Hexadecimal(decoded.substr(pos + 1, 2), false).convert<char>(false));
98 >                break;
99 >        case '+':
100 >                decoded[pos] = ' ';
101          }
102 +
103 +        return decoded;
104   }
105  
106   void Represent::headings(xml::TextWriter& xhtml)
# Line 173 | Line 186 | void Represent::output(xml::TextWriter&
186          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"));
187          ext::Vector<Item> items;
188  
189 <        _foru (index, 0, *count.begin())
189 >        _foru (index, 0, *count.begin() < 128 ? *count.begin() : 128)
190          {
191                  Item item(DataType(type != type_ ? type->second : std::string()), data != data_ ? data->second : std::string(), InputType(input != input_ ? input->second : std::string()));
192  
# Line 186 | Line 199 | void Represent::output(xml::TextWriter&
199  
200          _rfor (MultiMapConstIterator, delete_, cgi.lower_bound("delete"), cgi.upper_bound("delete")) items.RemoveAt(lexical_cast<size_t>(delete_->second));
201  
202 +        if (items.First().data.IsEmpty()) items.RemoveFirst();
203 +
204          size_t index(0);
205  
206          _foreach (ext::Vector<Item>, item, items) switch (item->type)
# Line 340 | Line 355 | char Represent::input(const Item& item)
355          case InputType::INPUT_Binary:
356                  return Binary(item.data, false).convert<char>(false);
357          case InputType::INPUT_Hexadecimal:
358 <                return Hexadecimal(input.data, false).convert<char>(false);
358 >                return Hexadecimal(item.data, false).convert<char>(false);
359          }
360   }
361  
# Line 364 | Line 379 | void Represent::normal(xml::TextWriter&
379          xhtml.OutputText(lexical_cast<ext::String>(type));
380   }
381  
382 + // XXX: damn, this one is really quite screwy
383   template <>
384   void Represent::normal(xml::TextWriter& xhtml, const char& char_)
385   {
386 <        xhtml.OutputText(ext::CodePoint(char_));
386 >        xhtml.OutputText("'");
387 >        xhtml.OutputText(std::string(1, char_).c_str());
388 >        xhtml.OutputText("'");
389   }
390  
391   template <>
392   void Represent::normal(xml::TextWriter& xhtml, const std::string& string)
393   {
394 +        xhtml.OutputText("\"");
395          xhtml.OutputText(string);
396 +        xhtml.OutputText("\"");
397   }
398  
399   template <>
400   void Represent::normal(xml::TextWriter& xhtml, const ext::String& string)
401   {
402 +        xhtml.OutputText("\"");
403          xhtml.OutputText(string);
404 +        xhtml.OutputText("\"");
405   }
406  
407   template <typename Type>
# Line 400 | Line 422 | void Represent::binary(xml::TextWriter&
422                  xml::ScopeElement(xhtml, "br");
423  
424                  xhtml.OutputText(Binary(*atom));
425 +                xhtml.OutputText(" = '");
426 +                xhtml.OutputText(ext::CodePoint(*atom));
427 +                xhtml.OutputText("'");
428          }
429   }
430  
# Line 415 | Line 440 | void Represent::binary(xml::TextWriter&
440                  xml::ScopeElement(xhtml, "br");
441  
442                  xhtml.OutputText(Binary(*atom));
443 +                xhtml.OutputText(" = '");
444 +                xhtml.OutputText(ext::CodePoint(*atom));
445 +                xhtml.OutputText("'");
446          }
447   }
448  
# Line 435 | Line 463 | void Represent::hexadecimal(xml::TextWri
463          {
464                  xml::ScopeElement(xhtml, "br");
465  
466 <                xhtml.OutputText(Hexadecimal(string));
466 >                xhtml.OutputText(Hexadecimal(*atom));
467 >                xhtml.OutputText(" = '");
468 >                xhtml.OutputText(ext::CodePoint(*atom));
469 >                xhtml.OutputText("'");
470          }
471   }
472  
# Line 450 | Line 481 | void Represent::hexadecimal(xml::TextWri
481          {
482                  xml::ScopeElement(xhtml, "br");
483  
484 <                xhtml.OutputText(Hexadecimal(string));
484 >                xhtml.OutputText(Hexadecimal(*atom));
485 >                xhtml.OutputText(" = '");
486 >                xhtml.OutputText(ext::CodePoint(*atom));
487 >                xhtml.OutputText("'");
488          }
489   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines