I'm new to C++ and cgicc, and I want to know if there is an easy way to parse the get parameters to the cgi script? ?action=yes&function=no
into an array or something like that?
Here's a simple function using the regular expression library included in C++11.
#include <regex>
// ...
std::map<std::string, std::string> Foo::Parse(const std::string& query)
{
std::map<std::string, std::string> data;
std::regex pattern("([\\w+%]+)=([^&]*)");
auto words_begin = std::sregex_iterator(query.begin(), query.end(), pattern);
auto words_end = std::sregex_iterator();
for (std::sregex_iterator i = words_begin; i != words_end; i++)
{
std::string key = (*i)[1].str();
std::string value = (*i)[2].str();
data[key] = value;
}
return data;
}
A possible solution
read_cgi_input(&items);
http://eekim.com/software/cgihtml/index.html
http://eekim.com/software/cgihtml/cgihtml-5.html#ss5.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With