From: Mikko Rasa Date: Sat, 21 Feb 2009 10:31:55 +0000 (+0000) Subject: Fix octal escape generation in c_escape X-Git-Tag: strings-1.1~6 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=cc69674bf670178a8076f2ce9740c2e60c4644c9;p=libs%2Fcore.git Fix octal escape generation in c_escape Fix mask matching to check for proper range Don't use uint8_t since it's not supported by MSVC --- diff --git a/source/regex.cpp b/source/regex.cpp index 4dc1b83..9ba089d 100644 --- a/source/regex.cpp +++ b/source/regex.cpp @@ -324,7 +324,7 @@ Regex::Code Regex::parse_brackets(const string &str, string::const_iterator &ite if(end==str.end()) throw InvalidParameterValue("Unmatched '['"); - uint8_t mask[32]={0}; + unsigned char mask[32]={0}; unsigned type=0; bool range=false; unsigned char first=0, last=0; @@ -468,11 +468,13 @@ bool Regex::run(const string &str, const string::const_iterator &begin, RegMatch } else if(instr==MATCH_MASK) { - uint8_t mask[32]; - for(unsigned k=0; k<32; ++k) - mask[k]=*j->citer++; - match_result=mask[c>>3]&(1<<(c&7)); - input_consumed=true; + if(c>=0 && c<=0xFF) + { + unsigned char m=*(j->citer+(c>>3)); + match_result=m&(1<<(c&7)); + input_consumed=true; + j->citer+=32; + } } else if(instr==MATCH_ANY) { diff --git a/source/utils.cpp b/source/utils.cpp index baf1333..c2bafb9 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -301,7 +301,7 @@ 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)&7), '0'+((*i>>3)&7), '0'+(*i&7)}; + char buf[4]={'\\', '0'+((*i>>6)&3), '0'+((*i>>3)&7), '0'+(*i&7)}; result.append(buf, 4); } else