Created
November 21, 2010 23:13
-
-
Save mattytrentini/709266 to your computer and use it in GitHub Desktop.
CgiParameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef CgiParameters map<string, string>; | |
CgiParameters test; | |
test["a"] = "1"; | |
test["b"] = "fred"; | |
test["c"] = "1.04"; | |
EXPECT_EQ(1, GetCgiParameter<int>(test, "a")) | |
EXPECT_EQ(string("fred"), GetCgiParameter<string>(test, "b")) | |
EXPECT_EQ_FLOAT(1.04f, GetCgiParameter<float>(test, "c")) | |
template <typename T> | |
T GetCgiParameter(const CgiParameters& params, const string& name) | |
{ | |
CgiParameters::const_iterator it = params.find(name); | |
if (it == params.end()) | |
{ | |
throw CgiParameterNotFound; | |
} | |
return boost::lexical_cast<T>(*it->second); | |
} | |
CgiParameters test(parseCgiParameters("?a=1&b=fred&c=1.04")); | |
CgiParameters parseCgiParameters(const string& http_parameters) | |
{ | |
std::string params = url_decode(http_parameters); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment