]> git.tdb.fi Git - libs/core.git/blob - examples/grep.cpp
66d70f3a486fe6801b7b95ad970cf1a554a48726
[libs/core.git] / examples / grep.cpp
1 #include <iostream>
2 #include <string>
3 #include <msp/core/getopt.h>
4 #include <msp/strings/regex.h>
5
6 using namespace std;
7 using namespace Msp;
8
9 int main(int argc, char **argv)
10 {
11         bool debug = false;
12         string re_str;
13         GetOpt getopt;
14         getopt.add_option('d', "debug", debug, GetOpt::NO_ARG);
15         getopt.add_argument("regex", re_str, GetOpt::REQUIRED_ARG);
16         getopt(argc, argv);
17
18         Regex regex(re_str);
19         if(debug)
20                 cout<<regex.disassemble();
21         string line;
22         while(getline(cin, line))
23         {
24                 if(RegMatch match = regex.match(line))
25                         cout<<line<<'\n';
26         }
27
28         return 0;
29 }