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 422 by douglas, 2005-03-09T19:08:17-08:00

# Line 75 | Line 75 | void Represent::parse()
75                  query = content;
76          }
77  
78 < //      api::Cout << query << ios::NewLine;
78 >        ext::Vector<ext::String> pairs(ext::SplitAll(query, ext::String("&")));
79  
80 <        ext::Vector<ext::String> pairs(query.Split('&'));
81 <
82 <        _foreach (ext::Vector<ext::String>, pair, pairs)
80 >        _foreach (const ext::Vector<ext::String>, pair, pairs)
81          {
82 <                ext::String::ConstIterator equal(pair->FindFirst('='));
82 >                ext::String::ConstIterator equal(ext::FindFirstAll(*pair, ext::String("=")));
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 <                cgi.insert(std::pair<std::string, std::string>(name, value));
89 > std::string Represent::decode(const ext::String& encoded)
90 > {
91 >        std::string decoded(encoded);
92 >        std::string::size_type pos(0);
93 >
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 95 | Line 108 | void Represent::headings(xml::TextWriter
108          xml::ScopeElement tr(xhtml, "tr");
109          ext::String headings[] = { "Data Type", "Data Representation", "Input Type", "Storage" };
110  
111 <        _foru (index, 0, sizeof (headings) / sizeof (ext::String))
111 >        _for (unsigned, index, 0, sizeof (headings) / sizeof (ext::String))
112          {
113                  xml::ScopeElement th(xhtml, "th");
114  
# Line 114 | Line 127 | void Represent::form(xml::TextWriter& xh
127  
128                  DataType type(cgi.find("type") != cgi.end() ? cgi.find("type")->second : std::string());
129  
130 <                _foreach (ext::Vector<DataType>, type_, DataType::enumerate())
130 >                _foreach (const ext::Vector<DataType>, type_, DataType::enumerate())
131                  {
132                          xml::ScopeElement option(xhtml, "option");
133  
# Line 143 | Line 156 | void Represent::form(xml::TextWriter& xh
156  
157                  InputType input(cgi.find("input") != cgi.end() ? cgi.find("input")->second : std::string());
158  
159 <                _foreach (ext::Vector<InputType>, input_, InputType::enumerate())
159 >                _foreach (const ext::Vector<InputType>, input_, InputType::enumerate())
160                  {
161                          xml::ScopeElement option(xhtml, "option");
162  
# Line 166 | Line 179 | void Represent::output(xml::TextWriter&
179          std::set<MultiMapSize, std::greater<MultiMapSize> > count;
180          ext::String names[] = { "type", "data", "input" };
181  
182 <        _foru (index, 0, sizeof (names) / sizeof (ext::String)) count.insert(cgi.count(names[index]));
182 >        _for (unsigned, index, 0, sizeof (names) / sizeof (ext::String)) count.insert(cgi.count(names[index]));
183  
184          typedef std::multimap<std::string, std::string>::const_iterator MultiMapConstIterator;
185  
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 >        _for (unsigned, 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.IsEmpty() && items.First().data.IsEmpty()) items.RemoveFirst();
203 +
204          size_t index(0);
205  
206          _foreach (ext::Vector<Item>, item, items) switch (item->type)
# Line 241 | Line 256 | void Represent::output(xml::TextWriter&
256  
257                  ext::String names[] = { "type", "data", "input" }, values[] = { item.type, item.data, item.input };
258  
259 <                _foru (index, 0, sizeof (names) / sizeof (ext::String))
259 >                _for (unsigned, index, 0, sizeof (names) / sizeof (ext::String))
260                  {
261                          xml::ScopeElement input(xhtml, "input");
262  
# 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  
347 // XXX: constructing a string from Binary or Hexadecimal seems too dangerous
362   template <>
363   std::string Represent::input(const Item& item)
364   {
365 <        return item.data;
365 >        std::string string;
366 >
367 >        switch (item.input)
368 >        {
369 >        default:
370 >                return item.data;
371 >        case InputType::INPUT_Binary:
372 >                _foreach (const _L<ext::String>, atom, ext::SplitAll(item.data, ext::String(" "))) string += Binary(*atom, false).convert<char>(false);
373 >                break;
374 >        case InputType::INPUT_Hexadecimal:
375 >                _foreach (const _L<ext::String>, atom, ext::SplitAll(item.data, ext::String(" "))) string += Hexadecimal(*atom, false).convert<char>(false);
376 >        }
377 >
378 >        return string;
379   }
380  
354 // XXX: constructing a string from Binary or Hexadecimal seems too dangerous
381   template <>
382   ext::String Represent::input(const Item& item)
383   {
384 <        return item.data;
384 >        ext::String string;
385 >
386 >        switch (item.input)
387 >        {
388 >        default:
389 >                return item.data;
390 >        case InputType::INPUT_Binary:
391 >                _foreach (const _L<ext::String>, atom, ext::SplitAll(item.data, ext::String(" "))) string.InsertLast(Binary(*atom, false).convert<uint32_t>(false));
392 >                break;
393 >        case InputType::INPUT_Hexadecimal:
394 >                _foreach (const _L<ext::String>, atom, ext::SplitAll(item.data, ext::String(" "))) string.InsertLast(Hexadecimal(*atom, false).convert<uint32_t>(false));
395 >        }
396 >
397 >        return string;
398   }
399  
400   template <typename Type>
# Line 367 | Line 406 | void Represent::normal(xml::TextWriter&
406   template <>
407   void Represent::normal(xml::TextWriter& xhtml, const char& char_)
408   {
409 <        xhtml.OutputText(ext::CodePoint(char_));
409 >        xhtml.OutputText("'");
410 >        xhtml.OutputText(std::string(1, char_).c_str());
411 >        xhtml.OutputText("'");
412   }
413  
414   template <>
415   void Represent::normal(xml::TextWriter& xhtml, const std::string& string)
416   {
417 +        xhtml.OutputText("\"");
418          xhtml.OutputText(string);
419 +        xhtml.OutputText("\"");
420   }
421  
422   template <>
423   void Represent::normal(xml::TextWriter& xhtml, const ext::String& string)
424   {
425 +        xhtml.OutputText("\"");
426          xhtml.OutputText(string);
427 +        xhtml.OutputText("\"");
428   }
429  
430   template <typename Type>
# Line 400 | Line 445 | void Represent::binary(xml::TextWriter&
445                  xml::ScopeElement(xhtml, "br");
446  
447                  xhtml.OutputText(Binary(*atom));
448 +                xhtml.OutputText(" = '");
449 +                xhtml.OutputText(ext::CodePoint(*atom));
450 +                xhtml.OutputText("'");
451          }
452   }
453  
# Line 410 | Line 458 | void Represent::binary(xml::TextWriter&
458  
459          xml::ScopeElement(xhtml, "br");
460  
461 <        _foreach (ext::String, atom, string)
461 >        _foreach (const ext::String, atom, string)
462          {
463                  xml::ScopeElement(xhtml, "br");
464  
465                  xhtml.OutputText(Binary(*atom));
466 +                xhtml.OutputText(" = '");
467 +                xhtml.OutputText(ext::CodePoint(*atom));
468 +                xhtml.OutputText("'");
469          }
470   }
471  
# Line 435 | Line 486 | void Represent::hexadecimal(xml::TextWri
486          {
487                  xml::ScopeElement(xhtml, "br");
488  
489 <                xhtml.OutputText(Hexadecimal(string));
489 >                xhtml.OutputText(Hexadecimal(*atom));
490 >                xhtml.OutputText(" = '");
491 >                xhtml.OutputText(ext::CodePoint(*atom));
492 >                xhtml.OutputText("'");
493          }
494   }
495  
# Line 446 | Line 500 | void Represent::hexadecimal(xml::TextWri
500  
501          xml::ScopeElement(xhtml, "br");
502  
503 <        _foreach (ext::String, atom, string)
503 >        _foreach (const ext::String, atom, string)
504          {
505                  xml::ScopeElement(xhtml, "br");
506  
507 <                xhtml.OutputText(Hexadecimal(string));
507 >                xhtml.OutputText(Hexadecimal(*atom));
508 >                xhtml.OutputText(" = '");
509 >                xhtml.OutputText(ext::CodePoint(*atom));
510 >                xhtml.OutputText("'");
511          }
512   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines