]> git.tdb.fi Git - libs/core.git/blobdiff - source/utils.cpp
Further style and comment adjustments
[libs/core.git] / source / utils.cpp
index 5a6bccdaca381e9e4cd066e2c0962489c4c457d1..5728332d595c1bba62d126f9ddbee776c6164004 100644 (file)
@@ -19,10 +19,10 @@ vector<string> do_split(const string &str, const string &sep, int max_split)
 {
        vector<string> result;
 
-       unsigned start=0;
+       unsigned start = 0;
        while(start<str.size())
        {
-               unsigned end=long_sep ? str.find(sep, start) : str.find_first_of(sep, start);
+               unsigned end = long_sep ? str.find(sep, start) : str.find_first_of(sep, start);
                if(end!=start || allow_empty)
                {
                        if(max_split>=0 && result.size()==static_cast<unsigned>(max_split))
@@ -37,7 +37,7 @@ vector<string> do_split(const string &str, const string &sep, int max_split)
                if(end>str.size())
                        break;
 
-               start=end+(long_sep ? sep.size() : 1);
+               start = end+(long_sep ? sep.size() : 1);
 
                if(allow_empty && start==str.size())
                        result.push_back(string());
@@ -56,16 +56,17 @@ bool check_str(const std::string &str, int (*pred)(int))
 
 }
 
+
 namespace Msp {
 
 int strcasecmp(const string &s1, const string &s2)
 {
-       string::const_iterator i1=s1.begin();
-       string::const_iterator i2=s2.begin();
+       string::const_iterator i1 = s1.begin();
+       string::const_iterator i2 = s2.begin();
        for(; (i1!=s1.end() && i2!=s2.end()); ++i1, ++i2)
        {
-               const char c1=::tolower(*i1);
-               const char c2=::tolower(*i2);
+               const char c1 = ::tolower(*i1);
+               const char c2 = ::tolower(*i2);
                if(c1!=c2) return c1-c2;
        }
        if(i1!=s1.end()) return *i1;
@@ -129,7 +130,7 @@ vector<string> split_fields(const string &str, char sep, int max_split)
 
 string strip(const string &s)
 {
-       string result=s;
+       string result = s;
        if(!result.erase(0, result.find_first_not_of(" \t\r\n")).empty())
                result.erase(result.find_last_not_of(" \t\r\n")+1);
        return result;
@@ -137,92 +138,92 @@ string strip(const string &s)
 
 string c_unescape(const std::string &str)
 {
-       bool escape=false;
-       unsigned numeric_type=0;
-       unsigned numeric_pos=0;
-       unsigned numeric_value=0;
+       bool escape = false;
+       unsigned numeric_type = 0;
+       unsigned numeric_pos = 0;
+       unsigned numeric_value = 0;
        string result;
        for(string::const_iterator i=str.begin(); i!=str.end(); ++i)
        {
                if(numeric_type==16)
                {
-                       unsigned digit=0;
+                       unsigned digit = 0;
                        if(*i>='0' && *i<='9')
-                               digit=*i-'0';
+                               digit = *i-'0';
                        else if(*i>='a' && *i<='f')
-                               digit=*i-'a'+10;
+                               digit = *i-'a'+10;
                        else if(*i>='A' && *i<='F')
-                               digit=*i-'A'+10;
+                               digit = *i-'A'+10;
                        else
                                throw InvalidParameterValue("Invalid hexadecimal digit");
 
-                       numeric_value=(numeric_value<<4 | digit);
+                       numeric_value = (numeric_value<<4 | digit);
                        ++numeric_pos;
                        if(numeric_pos==2)
                        {
-                               result+=numeric_value;
-                               numeric_type=0;
+                               result += numeric_value;
+                               numeric_type = 0;
                        }
                }
                else if(numeric_type==8)
                {
-                       unsigned digit=0;
+                       unsigned digit = 0;
                        if(*i>='0' && *i<='7')
-                               digit=*i-'0';
+                               digit = *i-'0';
                        else
                                throw InvalidParameterValue("Invalid octal digit");
 
-                       numeric_value=(numeric_value<<3 | digit);
+                       numeric_value = (numeric_value<<3 | digit);
                        ++numeric_pos;
                        if(numeric_pos==3)
                        {
-                               result+=numeric_value;
-                               numeric_type=0;
+                               result += numeric_value;
+                               numeric_type = 0;
                        }
                }
                else if(escape)
                {
                        if(*i=='x')
                        {
-                               numeric_type=16;
-                               numeric_pos=0;
-                               numeric_value=0;
+                               numeric_type = 16;
+                               numeric_pos = 0;
+                               numeric_value = 0;
                        }
                        else if(*i>='0' && *i<='3')
                        {
-                               numeric_type=8;
-                               numeric_pos=1;
-                               numeric_value=*i-'0';
+                               numeric_type = 8;
+                               numeric_pos = 1;
+                               numeric_value = *i-'0';
                        }
                        else if(*i=='n')
-                               result+='\n';
+                               result += '\n';
                        else if(*i=='t')
-                               result+='\t';
+                               result += '\t';
                        else if(*i=='r')
-                               result+='\r';
+                               result += '\r';
                        else if(*i=='b')
-                               result+='\b';
+                               result += '\b';
                        else if(*i=='v')
-                               result+='\v';
+                               result += '\v';
                        else if(*i=='a')
-                               result+='\a';
+                               result += '\a';
                        else if(*i=='f')
-                               result+='\f';
+                               result += '\f';
                        else if(*i=='\"')
-                               result+='\"';
+                               result += '\"';
                        else if(*i=='\'')
-                               result+='\'';
+                               result += '\'';
                        else if(*i=='\\')
-                               result+='\\';
+                               result += '\\';
                        else
                                throw InvalidParameterValue("Invalid escape sequence");
 
-                       escape=false;
+                       escape = false;
                }
                else if(*i=='\\')
-                       escape=true;
+                       escape = true;
                else
-                       result+=*i;
+                       result += *i;
        }
 
        if(escape)      
@@ -238,32 +239,32 @@ string c_escape(const string &str, bool escape_8bit)
        for(string::const_iterator i=str.begin(); i!=str.end(); ++i)
        {
                if(*i=='\n')
-                       result+="\\n";
+                       result += "\\n";
                else if(*i=='\t')
-                       result+="\\t";
+                       result += "\\t";
                else if(*i=='\r')
-                       result+="\\r";
+                       result += "\\r";
                else if(*i=='\b')
-                       result+="\\b";
+                       result += "\\b";
                else if(*i=='\v')
-                       result+="\\v";
+                       result += "\\v";
                else if(*i=='\a')
-                       result+="\\a";
+                       result += "\\a";
                else if(*i=='\f')
-                       result+="\\f";
+                       result += "\\f";
                else if(*i=='\"')
-                       result+="\\\"";
+                       result += "\\\"";
                else if(*i=='\'')
-                       result+="\\\'";
+                       result += "\\\'";
                else if(*i=='\\')
-                       result+="\\\\";
+                       result += "\\\\";
                else if(static_cast<unsigned char>(*i)<' ' || (escape_8bit && (*i&0x80)))
                {
-                       char buf[4]={'\\', '0'+((*i>>6)&3), '0'+((*i>>3)&7), '0'+(*i&7)};
+                       char buf[4] = {'\\', '0'+((*i>>6)&3), '0'+((*i>>3)&7), '0'+(*i&7)};
                        result.append(buf, 4);
                }
                else
-                       result+=*i;
+                       result += *i;
        }
 
        return result;