]> git.tdb.fi Git - libs/core.git/commitdiff
Use format instead of stringstream in Regex
authorMikko Rasa <tdb@tdb.fi>
Wed, 8 Jun 2011 06:28:09 +0000 (09:28 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 8 Jun 2011 11:08:34 +0000 (14:08 +0300)
source/strings/regex.cpp

index 5ee2fcc5cf926d76e10b3a1b46a7912092e46d9c..03bf7dde64a8c786bcf6ac0449589835d36f797d 100644 (file)
@@ -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<int>(*j)&0xFF);
-               ss<<Fmt("%3d")<<offset<<':'<<Fmt("%-9s")<<bytes;
+               result += format("%3d:%-9s  ", offset, bytes);
                if(bytes.size()>9)
-                       ss<<"\n"<<Fmt("%15s");
-               ss<<"  "<<decompiled<<'\n';
+                       result += "\n               ";
+               result += decompiled;
+               result += '\n';
        }
 
-       return ss.str();
+       return result;
 }
 
 string Regex::disassemble_instruction(Code::const_iterator &i) const
 {
        Instruction instr = static_cast<Instruction>(*i++);
 
-       ostringstream result;
        switch(instr)
        {
        case JUMP:
                {
                        Offset offset = read_int<Offset>(i);
-                       result<<"JUMP "<<Fmt("%+d")<<offset<<" ("<<Fmt("%d")<<i-code.begin()+offset<<')';
+                       return format("JUMP %+d (%d)", offset, (i-code.begin())+offset);
                }
-               break;
        case ND_JUMP:
                {
                        Offset offset = read_int<Offset>(i);
-                       result<<"ND_JUMP "<<Fmt("%+d")<<offset<<" ("<<Fmt("%d")<<i-code.begin()+offset<<')';
+                       return format("ND_JUMP %+d (%d)", offset, (i-code.begin())+offset);
                }
-               break;
        case GROUP_BEGIN:
-               result<<"GROUP_BEGIN "<<read_int<Index>(i);
-               break;
+               return format("GROUP_BEGIN %d", read_int<Index>(i));
        case GROUP_END:
-               result<<"GROUP_END "<<read_int<Index>(i);
-               break;
+               return format("GROUP_END %d", read_int<Index>(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<<'\'';
+                               return format("MATCH_CHAR '%c'", c);
                        else
-                               result<<(static_cast<int>(c)&0xFF);
+                               return format("MATCH_CHAR %d", static_cast<int>(c)&0xFF);
                }
                break;
        case MATCH_RANGE:
-               result<<"MATCH_RANGE "<<(static_cast<int>(*i++)&0xFF);
-               result<<'-'<<(static_cast<int>(*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<<' '<<Fmt("%02X")<<(static_cast<int>(*i++)&0xFF);
-               break;
+               {
+                       string result = "MATCH_MASK";
+                       for(unsigned j=0; j<32; ++j)
+                               result += format(" %02X", static_cast<int>(*i++)&0xFF);
+                       return result;
+               }
        case MATCH_ANY:
-               result<<"MATCH_ANY";
-               break;
+               return "MATCH_ANY";
        default:
-               result<<"UNKNOWN "<<instr;
+               return format("UNKNOWN %d", instr);
        }
-
-       return result.str();
 }
 
 } // namespace Msp