X-Git-Url: http://git.tdb.fi/?p=libs%2Fnet.git;a=blobdiff_plain;f=source%2Futils.cpp;h=5222f76024438deda488a6ec847b677244d14d0a;hp=b6340db7dfd2da87a9abc6c9cbb8baabb6fba999;hb=df006bfbbe8e8b49a52296f42894d4a452ed4c90;hpb=4f7b7be13874ae30d2a9cbb481bdacf4e160505f diff --git a/source/utils.cpp b/source/utils.cpp index b6340db..5222f76 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -41,9 +41,9 @@ string urlencode(const string &str, EncodeLevel level) for(string::const_iterator i=str.begin(); i!=str.end(); ++i) { if(is_reserved(*i, level)) - result+=format("%%%02X", *i); + result += format("%%%02X", *i); else - result+=*i; + result += *i; } return result; } @@ -54,11 +54,11 @@ string urlencode_plus(const string &str, EncodeLevel level) for(string::const_iterator i=str.begin(); i!=str.end(); ++i) { if(*i==' ') - result+='+'; + result += '+'; else if(is_reserved(*i, level)) - result+=format("%%%02X", *i); + result += format("%%%02X", *i); else - result+=*i; + result += *i; } return result; } @@ -68,18 +68,18 @@ string urldecode(const string &str) string result; for(unsigned i=0; istr.size()) throw InvalidParameterValue("Malformed data"); - result+=lexical_cast(str.substr(i+1, 2), "x"); - i+=2; + result += lexical_cast(str.substr(i+1, 2), "x"); + i += 2; } else if(c=='+') - result+=' '; + result += ' '; else - result+=c; + result += c; } return result; } @@ -87,14 +87,14 @@ string urldecode(const string &str) Url parse_url(const string &str) { static Regex r_url("(([a-z]+)://)?([a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(:[0-9])?)?(/[^?#]*)?(\\?([^#]+))?(#(.*))?"); - if(RegMatch m=r_url.match(str)) + if(RegMatch m = r_url.match(str)) { Url url; - url.scheme=m[2].str; - url.host=m[3].str; - url.path=urldecode(m[6].str); - url.query=m[8].str; - url.fragment=m[10].str; + url.scheme = m[2].str; + url.host = m[3].str; + url.path = urldecode(m[6].str); + url.query = m[8].str; + url.fragment = m[10].str; return url; } else @@ -107,32 +107,32 @@ string build_url(const Url &url) throw InvalidParameterValue("Only absolute paths are supported"); string str; if(!url.scheme.empty()) - str+=url.scheme+"://"; - str+=url.host; - str+=urlencode(url.path); + str += url.scheme+"://"; + str += url.host; + str += urlencode(url.path); if(!url.query.empty()) { - str+='?'; - str+=url.query; + str += '?'; + str += url.query; } if(!url.fragment.empty()) { - str+='#'; - str+=url.fragment; + str += '#'; + str += url.fragment; } return str; } Query parse_query(const std::string &str) { - vector parts=split(str, '&'); + vector parts = split(str, '&'); Query query; for(vector::const_iterator i=parts.begin(); i!=parts.end(); ++i) { - unsigned equals=i->find('='); - string &value=query[urldecode(i->substr(0, equals))]; + unsigned equals = i->find('='); + string &value = query[urldecode(i->substr(0, equals))]; if(equals!=string::npos) - value=urldecode(i->substr(equals+1)); + value = urldecode(i->substr(equals+1)); } return query; } @@ -143,10 +143,10 @@ string build_query(const Query &query) for(Query::const_iterator i=query.begin(); i!=query.end(); ++i) { if(i!=query.begin()) - str+='&'; - str+=urlencode_plus(i->first); - str+='='; - str+=urlencode_plus(i->second); + str += '&'; + str += urlencode_plus(i->first); + str += '='; + str += urlencode_plus(i->second); } return str; }