]> git.tdb.fi Git - libs/core.git/blobdiff - source/strings/utils.cpp
Remove unnecessary std:: qualifiers
[libs/core.git] / source / strings / utils.cpp
index fff6cdb290362cb724b96b61c29f68c5970dfe0c..1b4cad080dee85950740b58de822484be2c2214e 100644 (file)
@@ -1,6 +1,7 @@
 #include <algorithm>
 #include <list>
 #include <stdexcept>
+#include <cctype>
 #include "utils.h"
 
 using namespace std;
@@ -39,7 +40,7 @@ vector<string> do_split(const string &str, const string &sep, int max_split)
        return result;
 }
 
-bool check_str(const std::string &str, int (*pred)(int))
+bool check_str(const string &str, int (*pred)(int))
 {
        for(string::const_iterator i=str.begin(); i!=str.end(); ++i)
                if(!pred(*i))
@@ -129,7 +130,21 @@ string strip(const string &s)
        return result;
 }
 
-string c_unescape(const std::string &str)
+string &append(string &str, const string &sep, const string &other)
+{
+       if(!str.empty() && !other.empty())
+               str += sep;
+       str += other;
+       return str;
+}
+
+string join(const string &str1, const string &sep, const string &str2)
+{
+       string result = str1;
+       return append(result, sep, str2);
+}
+
+string c_unescape(const string &str)
 {
        bool escape = false;
        unsigned numeric_type = 0;
@@ -253,7 +268,9 @@ string c_escape(const string &str, bool escape_8bit)
                        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 };
+                       for(unsigned j=0; j<3; ++j)
+                               buf[1+j] = '0'+((static_cast<unsigned char>(*i)>>(6-j*3))&7);
                        result.append(buf, 4);
                }
                else