#include #include #include using namespace std; #ifndef _CGIINPUT_H #define _CGIINPUT_H class CGIinput { public: CGIinput() { string input; cin >> input; if (cin) { input = URLdecode(input) + "&"; while (input != "") { int equalPos = input.find("="); int ampPos = input.find("&"); elements.push_back(input.substr(0, equalPos)); values.push_back(input.substr(equalPos+1, ampPos-equalPos-1)); input = input.substr(ampPos+1, input.length()); } } } int NumElements() { return elements.size(); } string Element(int index) { return elements[index]; } string Value(int index) { return values[index]; } string ElementValue(string desiredElement) { for (int i = 0; i < elements.size(); i++) { if (elements[i] == desiredElement) { return values[i]; } } return "NOT FOUND"; } private: vector elements; // the names of the elements from the page vector values; // the corresponding values for the elements string URLdecode(string input) // precondition : input string is URLencoded // postcondition: returns decoded string { string clean = ""; for (int i = 0; i < input.length(); i++) { if (input[i] == '+') { clean += ' '; } else if (input[i] == '%') { const string digits = "0123456789ABCDEF"; clean += (char)(digits.find(input[i+1])*16 + digits.find(input[i+2])); i += 2; } else { clean += input[i]; } } return clean; } }; #endif