X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fstrings%2Futils.cpp;h=80e59f07a6cb5802eb741aa870a0498e2308fea0;hp=fff6cdb290362cb724b96b61c29f68c5970dfe0c;hb=9955efca718d8be72b63c7c2182ca59e7b9d0935;hpb=a268ee8d1990eca21155137d0245b2985579d064 diff --git a/source/strings/utils.cpp b/source/strings/utils.cpp index fff6cdb..80e59f0 100644 --- a/source/strings/utils.cpp +++ b/source/strings/utils.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "utils.h" using namespace std; @@ -129,6 +130,20 @@ string strip(const string &s) return result; } +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 std::string &str) { bool escape = false; @@ -253,7 +268,9 @@ string c_escape(const string &str, bool escape_8bit) result += "\\\\"; else if(static_cast(*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(*i)>>(6-j*3))&7); result.append(buf, 4); } else