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 |
> |
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) |
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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) |
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 |
|
|
332 |
|
template <typename Type> |
333 |
|
Type Represent::input(const Item& item) |
334 |
|
{ |
335 |
< |
// XXX: implement |
321 |
< |
|
322 |
< |
return lexical_cast<Type>(item.data); |
323 |
< |
} |
335 |
> |
bool signed_(etl::Limits<Type>::IsSigned); |
336 |
|
|
337 |
< |
template <> |
338 |
< |
bool Represent::input(const Item& item) |
339 |
< |
{ |
340 |
< |
// XXX: implement |
341 |
< |
|
342 |
< |
try { return lexical_cast<bool>(item.data); } catch (ext::Exception) { return false; } |
337 |
> |
switch (item.input) |
338 |
> |
{ |
339 |
> |
default: |
340 |
> |
try { return lexical_cast<Type>(item.data); } catch (ext::Exception) { return 0; } |
341 |
> |
case InputType::INPUT_Binary: |
342 |
> |
return Binary(item.data, signed_).convert<Type>(signed_); |
343 |
> |
case InputType::INPUT_Hexadecimal: |
344 |
> |
return Hexadecimal(item.data, signed_).convert<Type>(signed_); |
345 |
> |
} |
346 |
|
} |
347 |
|
|
348 |
|
template <> |
349 |
|
char Represent::input(const Item& item) |
350 |
|
{ |
351 |
< |
// XXX: implement |
352 |
< |
|
353 |
< |
return item.data.First(); |
351 |
> |
switch (item.input) |
352 |
> |
{ |
353 |
> |
default: |
354 |
> |
return item.data.First(); |
355 |
> |
case InputType::INPUT_Binary: |
356 |
> |
return Binary(item.data, false).convert<char>(false); |
357 |
> |
case InputType::INPUT_Hexadecimal: |
358 |
> |
return Hexadecimal(item.data, false).convert<char>(false); |
359 |
> |
} |
360 |
|
} |
361 |
|
|
341 |
– |
// XXX: constructing a string from Binary or Hexadecimal seems to 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 |
|
|
348 |
– |
// XXX: constructing a string from Binary or Hexadecimal seems to 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> |
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> |
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
} |