ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Represent/Represent.cpp
Revision: 379
Committed: 2004-12-22T20:42:52-08:00 (20 years, 6 months ago) by douglas
File size: 1459 byte(s)
Log Message:
Moving right along!

File Contents

# User Rev Content
1 douglas 362 // Represent
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7 douglas 371 #include "Hexadecimal.hpp"
8 douglas 362
9 douglas 379 #include <menes-api/environment.hpp>
10 douglas 370 #include <menes-app/simple.hpp>
11 douglas 362
12 douglas 379 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 douglas 370 int Main(const app::Options& options)
18 douglas 362 {
19 douglas 370 Represent represent;
20 douglas 362
21 douglas 370 return 0;
22 douglas 362 }
23    
24 douglas 370 Represent::Represent()
25 douglas 362 {
26 douglas 379 parse();
27 douglas 371
28 douglas 379 api::Cout << "Content-Type: text/html; charset=UTF-8\r\n\r\n" << ios::Flush;
29 douglas 371
30 douglas 379 xml::TextWriter xhtml(api::Cout);
31     xml::ScopeElement table(xhtml, "table");
32 douglas 371
33 douglas 379 {
34     xml::ScopeElement tr(xhtml, "tr");
35     ext::String headings[] = { "Type", "Data Representation", "Storage" };
36 douglas 371
37 douglas 379 _foru (index, 0, sizeof (headings) / sizeof (ext::String))
38     {
39     xml::ScopeElement th(xhtml, "th");
40 douglas 371
41 douglas 379 xhtml.OutputText(headings[index]);
42     }
43     }
44     }
45 douglas 373
46 douglas 379 void Represent::parse()
47     {
48     ext::String query(env.get("QUERY_STRING"));
49 douglas 373
50 douglas 379 if (env.get("REQUEST_METHOD") == "POST")
51     {
52     ext::Buffer content(lexical_cast<size_t>(env.get("CONTENT_LENGTH")));
53 douglas 373
54 douglas 379 api::Cin.ReadFully(content.Begin(), content.GetSize());
55 douglas 373
56 douglas 379 query = content;
57     }
58    
59     ext::Vector<ext::String> pairs(query.Split('&'));
60    
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     cgi.insert(std::pair<std::string, std::string>(name, value));
67     }
68 douglas 362 }

Properties

Name Value
svn:eol-style native
svn:keywords Id