37 #include "rnr/rnrconfig.h" 71 "Unit test librnr_appkit RegEx class.",
74 "The %P command unit tests the librnr_appkit RegEx class operation.",
92 const RegEx re1(
"^[a-z]*$", RegEx::ReFlagICase);
94 const RegEx re3(
"['\"]{1,2}([0-9]+)(hello)(^)");
95 const RegEx re4(
"^[a-z]*$");
96 RegEx reGo =
"([cC]at)|([dD]og)";
98 static string getline(istream &is)
103 is.getline(buf,
sizeof(buf));
105 for(s = buf; *s && isspace(*s); ++s);
115 static void utPr(ostream &os,
const string name,
const RegEx &re)
117 os <<
" ... RE " << name << endl;
119 os <<
"getRegEx() " << re.
getRegEx() << endl;
120 os <<
"isValid() " << re.
isValid() << endl;
121 os <<
"getFlags() " << re.
getFlags() << endl;
123 os <<
"getErrorStr() " << re.
getErrorStr() << endl;
124 os <<
"operator<<() " << re << endl;
134 const char *testinputs[] =
144 os <<
" Test Constant RegEx:" << endl;
148 for(
size_t i = 0; testinputs[i] != NULL; ++i)
150 string input(testinputs[i]);
152 os << input <<
" --> ";
154 if( re.
match(input) )
174 os <<
" Test Run-Time Operations:" << endl;
175 os <<
"q - Quit." << endl;
176 os <<
"n <re> - Specify new re." << endl;
177 os <<
"m <input> - Match input to re." << endl;
178 os <<
"a <input> - Match all input substrings to re." << endl;
179 os <<
"p - Print re." << endl;
187 cin.ignore(INT_MAX,
'\n');
198 else if( cmd ==
"n" )
203 os <<
"bad input" << endl;
205 else if( !reGo.isValid() )
211 os <<
"new valid re" << endl;
214 else if( cmd ==
"m" )
218 os <<
"try match on '" << arg <<
"' --> ";
219 if( reGo.
match(arg) )
221 os <<
"match" << endl;
225 os <<
"no match" << endl;
228 else if( cmd ==
"a" )
232 os <<
"try match all on '" << arg <<
"'" << endl;
234 reGo.
match(arg, matches);
236 for(
size_t i = 0; i < matches.size(); ++i)
238 os << i <<
". (" << matches[i].m_uStart <<
"," 239 << matches[i].m_uEnd <<
") '" 240 << matches[i].m_strMatch <<
"'" << endl;
243 else if( cmd ==
"p" )
245 utPr(os,
"Go", reGo);
249 os <<
"'" << cmd <<
"': Bad command. One of: a m n p q" << endl;
266 Argv0 = basename(argv[0]);
280 int main(
int argc,
char* argv[])
287 cout <<
" Test Pre-Compiled:" << endl;
288 utPr(cout,
"0", re0);
289 utPr(cout,
"1", re1);
290 utPr(cout,
"copy of 1", re2);
291 utPr(cout,
"3", re3);
292 utPr(cout,
"4", re4);
293 utPr(cout,
"Go", reGo);
std::vector< ReMatch > ReMatchVec
vector of matches
static void utPr(ostream &os, const string name, const RegEx &re)
Print RegEx data.
static char * Argv0
the command
int getReturnCode() const
Get the extened return code from the last RegEx operation.
const std::string & getRegEx() const
Get the pre-compiled regular expression.
static double OptsHz
thread hertz rate
#define APP_EC_OK
success exit code
static OptsInfo_T OptsInfo[]
Command line options information.
static void utRun(ostream &os)
Test RegEx operations.
static const PkgInfo_T PkgInfo
const std::string & getErrorStr() const
Get the last RegExs operation error string.
static void mainInit(int argc, char *argv[])
Main initialization.
Package version information.
bool match(const std::string &strInput, const int nFlags=ReFlagDefaults)
Match the input string against the regular expression.
static void utConstRe(ostream &os, const RegEx &re)
Print RegEx data.
int main(int argc, char *argv[])
Main.
int getFlags() const
Get compile behavior flags.
The Regular Expression Class interface.
bool isValid() const
Test if in a valid state (i.e. compiled).
static OptsPgmInfo_T PgmInfo
Program information.
const RegEx re0
Globally constructed, pre-compiled re's.