Copyright © 2007 Mikko Rasa
Distributed under the LGPL
*/
+
#include <stack>
+#include <limits>
#include <msp/core/except.h>
#include "formatter.h"
#include "regex.h"
bool has_branches=false;
unsigned level=0;
bool escape=false;
+ unsigned bracket=0;
string::const_iterator end;
for(end=iter; end!=expr.end(); ++end)
{
if(escape)
escape=false;
+ else if(bracket)
+ {
+ if(bracket==3 && *end==']')
+ bracket=0;
+ else if(bracket==1 && *end=='^')
+ bracket=2;
+ else
+ bracket=3;
+ }
else if(*end=='\\')
escape=true;
else if(*end=='(')
else if(level==0)
has_branches=true;
}
+ else if(*end=='[')
+ bracket=1;
}
if(level>0)
if(flag)
{
- if(static_cast<unsigned char>(*i)<=LAST_INSTRUCTION_)
- result+=MATCH_CHAR;
+ result+=MATCH_CHAR;
result+=*i;
}
}
string::const_iterator end=iter;
- for(; (end!=str.end() && (end==iter || *end!=']')); ++end);
+ for(; (end!=str.end() && (end==iter || *end!=']')); ++end) ;
if(end==str.end())
throw InvalidParameterValue("Unmatched '['");
bool negate_match=false;
for(; j->citer!=code.end();)
{
- Instruction instr=static_cast<Instruction>(*j->citer);
- if(instr>LAST_INSTRUCTION_)
- instr=MATCH_CHAR;
- else
- ++j->citer;
+ Instruction instr=static_cast<Instruction>(*j->citer++);
if(instr==NEGATE)
negate_match=true;
string Regex::disassemble_instruction(Code::const_iterator &i) const
{
- Instruction instr=static_cast<Instruction>(*i);
- if(instr>=LAST_INSTRUCTION_)
- instr=MATCH_CHAR;
- else
- ++i;
+ Instruction instr=static_cast<Instruction>(*i++);
ostringstream result;
switch(instr)
case MATCH_ANY:
result<<"MATCH_ANY";
break;
- case FIRST_INSTRUCTION_:
- case LAST_INSTRUCTION_:
+ default:
result<<"UNKNOWN "<<instr;
}