X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fstrings%2Futils.cpp;h=a67eb15b1f4b2b738fecc1b40bc60e7e9e3a97f3;hp=93bbbbf2ae81d3c073b2abe3320029108ccd45ba;hb=26636afce9c85c6c78c7267ebcd18d165825024b;hpb=967785734be5c3fc6f75da122c2d93ebbb338271 diff --git a/source/strings/utils.cpp b/source/strings/utils.cpp index 93bbbbf..a67eb15 100644 --- a/source/strings/utils.cpp +++ b/source/strings/utils.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include "utils.h" using namespace std; @@ -148,7 +148,7 @@ string c_unescape(const std::string &str) else if(*i>='A' && *i<='F') digit = *i-'A'+10; else - throw InvalidParameterValue("Invalid hexadecimal digit"); + throw invalid_argument("c_unescape"); numeric_value = (numeric_value<<4 | digit); ++numeric_pos; @@ -164,7 +164,7 @@ string c_unescape(const std::string &str) if(*i>='0' && *i<='7') digit = *i-'0'; else - throw InvalidParameterValue("Invalid octal digit"); + throw invalid_argument("c_unescape"); numeric_value = (numeric_value<<3 | digit); ++numeric_pos; @@ -209,7 +209,7 @@ string c_unescape(const std::string &str) else if(*i=='\\') result += '\\'; else - throw InvalidParameterValue("Invalid escape sequence"); + throw invalid_argument("c_unescape"); escape = false; } @@ -220,7 +220,7 @@ string c_unescape(const std::string &str) } if(escape) - throw InvalidParameterValue("Stray backslash at end of string"); + throw invalid_argument("c_unescape"); return result; } @@ -253,7 +253,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