]> git.tdb.fi Git - libs/net.git/blobdiff - source/utils.cpp
Style update: spaces around assignments
[libs/net.git] / source / utils.cpp
index b6340db7dfd2da87a9abc6c9cbb8baabb6fba999..5222f76024438deda488a6ec847b677244d14d0a 100644 (file)
@@ -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; i<str.size(); ++i)
        {
-               char c=str[i];
+               char c = str[i];
                if(c=='%')
                {
                        if(i+3>str.size())
                                throw InvalidParameterValue("Malformed data");
-                       result+=lexical_cast<unsigned char>(str.substr(i+1, 2), "x");
-                       i+=2;
+                       result += lexical_cast<unsigned char>(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<string> parts=split(str, '&');
+       vector<string> parts = split(str, '&');
        Query query;
        for(vector<string>::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;
 }