/* $Id$ */
#include <iostream>
#include <string>
+#include <msp/core/getopt.h>
#include "regex.h"
using namespace std;
int main(int argc, char **argv)
{
- if(argc<2)
+ bool debug=false;
+ GetOpt getopt;
+ getopt.add_option('d', "debug", debug, GetOpt::NO_ARG);
+ getopt(argc, argv);
+
+ const list<string> &args=getopt.get_args();
+
+ if(args.empty())
{
cerr<<"Usage: "<<argv[0]<<" <regex>\n";
return 1;
}
Regex regex(argv[1]);
- cout<<regex.disassemble();
+ if(debug)
+ cout<<regex.disassemble();
string line;
while(getline(cin, line))
{
if(RegMatch match=regex.match(line))
- {
cout<<line<<'\n';
- }
}
return 0;
using namespace std;
-#include <iostream>
-
namespace {
/**
}
string::const_iterator end=iter;
- for(; (end!=str.end() && *end!=']'); ++end);
+ for(; (end!=str.end() && (end==iter || *end!=']')); ++end);
if(end==str.end())
throw InvalidParameterValue("Unmatched '['");
uint8_t mask[32]={0};
unsigned type=0;
bool range=false;
- unsigned char first, last;
+ unsigned char first=0, last=0;
for(string::const_iterator i=iter; i!=end; ++i)
{
unsigned char c=*i;
{
if(!g1.match)
return false;
-
+
// Any match is better than no match
if(!g2.match)
return true;
The MATCH_CHAR instruction consumes the input character and matches it against
a single character. Since regexes often match sequences of printable character,
-a match for such a character may be encoded as the character itself.
+a match for a non-opcode character may be encoded as the character itself.
The MATCH_RANGE instruction consumes the input character and matches it against
an inclusive character range.