X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fstrings%2Futils.cpp;h=416188ec3d574e71caaecf2fa4353eaff8f67564;hb=74e62aabadda67d02b3eab09baa37c9d7640b794;hp=5728332d595c1bba62d126f9ddbee776c6164004;hpb=b56eb5ec1da675da0c66abc53c1e4f6c4e4cccbd;p=libs%2Fcore.git diff --git a/source/strings/utils.cpp b/source/strings/utils.cpp index 5728332..416188e 100644 --- a/source/strings/utils.cpp +++ b/source/strings/utils.cpp @@ -1,13 +1,7 @@ -/* $Id$ - -This file is part of libmspstrings -Copyright © 2006-2008 Mikko Rasa -Distributed under the LGPL -*/ - #include #include -#include +#include +#include #include "utils.h" using namespace std; @@ -155,7 +149,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; @@ -171,7 +165,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; @@ -216,7 +210,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; } @@ -227,7 +221,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; } @@ -260,7 +254,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