From: Mikko Rasa Date: Sat, 12 Jan 2008 12:14:14 +0000 (+0000) Subject: Fix c_unescape X-Git-Tag: strings-1.0~7 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a3bf8b72faa5fce99f0f6384d6d9b6588a1de072;p=libs%2Fcore.git Fix c_unescape --- diff --git a/source/utils.cpp b/source/utils.cpp index 0318e99..2232527 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -162,7 +162,7 @@ string c_unescape(const std::string &str) string result; for(string::const_iterator i=str.begin(); i!=str.end(); ++i) { - if(numeric_type==1) + if(numeric_type==16) { unsigned digit=0; if(*i>='0' && *i<='9') @@ -182,7 +182,7 @@ string c_unescape(const std::string &str) numeric_type=0; } } - else if(numeric_type==2) + else if(numeric_type==8) { unsigned digit=0; if(*i>='0' && *i<='7') @@ -190,12 +190,9 @@ string c_unescape(const std::string &str) else throw InvalidParameterValue("Invalid octal digit"); - if(numeric_pos==0 && digit>3) - throw InvalidParameterValue("Octal escape sequence must start with [0-3]"); - numeric_value=(numeric_value<<3 | digit); ++numeric_pos; - if(numeric_pos==2) + if(numeric_pos==3) { result+=numeric_value; numeric_type=0; @@ -203,12 +200,18 @@ string c_unescape(const std::string &str) } else if(escape) { - if(*i=='x' || (*i>='0' && *i<='7')) + if(*i=='x') { - numeric_type=(*i=='x' ? 1 : 2); + 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'; + } else if(*i=='n') result+='\n'; else if(*i=='t')