3 This file is part of libmsphttp
4 Copyright © 2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/strings/formatter.h>
15 const char reserved[]=" :/?#[]@!$&'()*+,;=%";
17 bool is_reserved(char c)
19 for(const char *r=reserved; *r; ++r)
30 string urlencode(const string &str)
33 for(string::const_iterator i=str.begin(); i!=str.end(); ++i)
36 result+=format("%%%02X", *i);
43 string urldecode(const string &str)
46 for(unsigned i=0; i<str.size(); ++i)
52 throw InvalidParameterValue("Malformed data");
53 result+=lexical_cast<unsigned char>(str.substr(i+1, 2), "x");