#include "nobject.h"
#include "nstring.h"
#include "nregex.h"
#include "ngetopt.h"
#include "nlist.h"
class RegexExample {
public:
RegexExample(void): m_reg(), m_string() { }
bool setRegex(const NOpt<RegexExample> &opt) {
m_reg = opt.getValues().at(0);
return true;
}
bool setString(const NOpt<RegexExample> &opt) {
m_string = opt.getValues().at(0);
return true;
}
void run(void) {
NRegex regex(m_reg, m_string);
NList<NRegex::MatchOffset> off_list;
if (regex.match()) {
NMessage::print() << "Matched: " << m_reg
<< " with " << m_string;
}
else {
NWarning::print() << "Not matched: " << m_reg
<< " with " << m_string;
}
}
private:
NString m_reg;
NString m_string;
};
void setup_opts(NGetOpt<RegexExample> *opts) {
opts->add("h", "help", false, "Display the help for this program", NULL);
opts->add("r", "regex", true, "The regex to match",
&RegexExample::setRegex);
opts->add("s", "string", true, "The string to match",
&RegexExample::setString);
}
int main(int argc, char **argv) {
RegexExample app;
NGetOpt<RegexExample> opts(argc, argv, &app, 1);
setup_opts(&opts);
try {
if (opts.proccess()) {
app.run();
}
}
catch (NException &e) {
NWarning::print() << e.getDescription();
exit(1);
}
return 0;
}