string Regex::disassemble() const
{
- ostringstream ss;
+ string result;
for(Code::const_iterator i=code.begin(); i!=code.end();)
{
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