From: Mikko Rasa Date: Wed, 8 Jun 2011 06:28:09 +0000 (+0300) Subject: Use format instead of stringstream in Regex X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e378c8f46af4cbc00e4c8b44ea2839b5ac6726ec;p=libs%2Fcore.git Use format instead of stringstream in Regex --- diff --git a/source/strings/regex.cpp b/source/strings/regex.cpp index 5ee2fcc..03bf7dd 100644 --- a/source/strings/regex.cpp +++ b/source/strings/regex.cpp @@ -497,7 +497,7 @@ bool Regex::group_compare(const RegMatch::Group &g1, const RegMatch::Group &g2) string Regex::disassemble() const { - ostringstream ss; + string result; for(Code::const_iterator i=code.begin(); i!=code.end();) { @@ -507,76 +507,69 @@ string Regex::disassemble() const string bytes; for(; j!=i; ++j) bytes += format(" %02X", static_cast(*j)&0xFF); - ss<9) - ss<<"\n"<(*i++); - ostringstream result; switch(instr) { case JUMP: { Offset offset = read_int(i); - result<<"JUMP "<(i); - result<<"ND_JUMP "<(i); - break; + return format("GROUP_BEGIN %d", read_int(i)); case GROUP_END: - result<<"GROUP_END "<(i); - break; + return format("GROUP_END %d", read_int(i)); case NEGATE: - result<<"NEGATE"; - break; + return "NEGATE"; case MATCH_BEGIN: - result<<"MATCH_BEGIN"; - break; + return "MATCH_BEGIN"; case MATCH_END: - result<<"MATCH_END"; - break; + return "MATCH_END"; case MATCH_CHAR: { char c = *i++; - result<<"MATCH_CHAR "; if(c>=0x20 && c<=0x7E) - result<<'\''<(c)&0xFF); + return format("MATCH_CHAR %d", static_cast(c)&0xFF); } break; case MATCH_RANGE: - result<<"MATCH_RANGE "<<(static_cast(*i++)&0xFF); - result<<'-'<<(static_cast(*i++)&0xFF); - break; + { + int begin = *i++; + int end = *i++; + return format("MATCH_RANGE %d-%d", begin&0xFF, end&0xFF); + } case MATCH_MASK: - result<<"MATCH_MASK"; - for(unsigned j=0; j<32; ++j) - result<<' '<(*i++)&0xFF); - break; + { + string result = "MATCH_MASK"; + for(unsigned j=0; j<32; ++j) + result += format(" %02X", static_cast(*i++)&0xFF); + return result; + } case MATCH_ANY: - result<<"MATCH_ANY"; - break; + return "MATCH_ANY"; default: - result<<"UNKNOWN "<