6 |
|
|
7 |
|
#include "Hexadecimal.hpp" |
8 |
|
|
9 |
+ |
#include <menes-api/environment.hpp> |
10 |
|
#include <menes-app/simple.hpp> |
11 |
|
|
12 |
+ |
struct Environment |
13 |
+ |
{ |
14 |
+ |
ext::String get(const ext::String& name) { try { return api::TheEnvironment.Get(name); } catch (ext::Exception) { return ext::String(); } } |
15 |
+ |
} env; |
16 |
+ |
|
17 |
|
int Main(const app::Options& options) |
18 |
|
{ |
19 |
|
Represent represent; |
23 |
|
|
24 |
|
Represent::Represent() |
25 |
|
{ |
26 |
< |
std::string hello("Hello, World!"); |
26 |
> |
parse(); |
27 |
> |
|
28 |
> |
api::Cout << "Content-Type: text/html; charset=UTF-8\r\n\r\n" << ios::Flush; |
29 |
> |
|
30 |
> |
xml::TextWriter xhtml(api::Cout); |
31 |
> |
xml::ScopeElement table(xhtml, "table"); |
32 |
|
|
33 |
< |
api::Cerr << Binary(hello) << " = " << Hexadecimal(hello) << " = " << ext::String(hello) << ios::NewLine; |
33 |
> |
{ |
34 |
> |
xml::ScopeElement tr(xhtml, "tr"); |
35 |
> |
ext::String headings[] = { "Type", "Data Representation", "Storage" }; |
36 |
|
|
37 |
< |
_sforeach (std::string, atom, hello) api::Cerr << Binary(*atom) << " = " << Hexadecimal(*atom) << " = " << ext::String(atom, 1) << ios::NewLine; |
37 |
> |
_foru (index, 0, sizeof (headings) / sizeof (ext::String)) |
38 |
> |
{ |
39 |
> |
xml::ScopeElement th(xhtml, "th"); |
40 |
|
|
41 |
< |
ext::String hello_(hello); |
41 |
> |
xhtml.OutputText(headings[index]); |
42 |
> |
} |
43 |
> |
} |
44 |
> |
} |
45 |
> |
|
46 |
> |
void Represent::parse() |
47 |
> |
{ |
48 |
> |
ext::String query(env.get("QUERY_STRING")); |
49 |
|
|
50 |
< |
api::Cerr << Binary(hello_) << " = " << Hexadecimal(hello_) << " = " << hello_ << ios::NewLine; |
50 |
> |
if (env.get("REQUEST_METHOD") == "POST") |
51 |
> |
{ |
52 |
> |
ext::Buffer content(lexical_cast<size_t>(env.get("CONTENT_LENGTH"))); |
53 |
|
|
54 |
< |
_foreach (ext::String, atom, hello_) api::Cerr << Binary(*atom) << " = " << Hexadecimal(*atom) << " = " << ext::String(*atom) << ios::NewLine; |
54 |
> |
api::Cin.ReadFully(content.Begin(), content.GetSize()); |
55 |
|
|
56 |
< |
_fori (index, -10, 11) api::Cerr << Binary(index) << " = " << Hexadecimal(index) << " = " << index << ios::NewLine; |
56 |
> |
query = content; |
57 |
> |
} |
58 |
|
|
59 |
< |
_foru (index, 0xFFFFFFF6, 11) api::Cerr << Binary(index) << " = " << Hexadecimal(index) << " = " << index << ios::NewLine; |
59 |
> |
ext::Vector<ext::String> pairs(query.Split('&')); |
60 |
|
|
61 |
< |
for (float index(-1); index < 1.1; index += float(0.1)) api::Cerr << Binary(index) << " = " << Hexadecimal(index) << " = " << index << ios::NewLine; |
61 |
> |
_foreach (ext::Vector<ext::String>, pair, pairs) |
62 |
> |
{ |
63 |
> |
ext::String::ConstIterator equal(pair->FindFirst('=')); |
64 |
> |
ext::String name(pair->Begin(), equal), value(equal != pair->End() ? equal + 1 : equal, pair->End()); |
65 |
|
|
66 |
< |
for (double index(-1); index < 1.1; index += 0.1) api::Cerr << Binary(index) << " = " << Hexadecimal(index) << " = " << index << ios::NewLine; |
66 |
> |
cgi.insert(std::pair<std::string, std::string>(name, value)); |
67 |
> |
} |
68 |
|
} |