Skip to content

Commit

Permalink
improves number checks using regexp.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrodriguez-dis committed Oct 14, 2017
1 parent a018535 commit b8fc631
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion jail/default_scripts/vpl_evaluate.cpp
Expand Up @@ -109,6 +109,7 @@ class OutputChecker{
* Class NumbersOutput Declaration
*/
class NumbersOutput:public OutputChecker{
static regex_t* regNumber;
struct Number{
bool isInteger;
long int integer;
Expand Down Expand Up @@ -621,8 +622,27 @@ bool NumbersOutput::calcStartWithAsterisk(){
}
return false;
}

regex_t* NumbersOutput::regNumber = NULL;
NumbersOutput::NumbersOutput(const string &text):OutputChecker(text){
if( regNumber == NULL) {
regNumber = new regex_t;
regcomp(regNumber, "[-+]?[0-9]*\\.?[0-9]+(e[-+]?[0-9]+)?", REG_EXTENDED | REG_NEWLINE | REG_ICASE);
}
regmatch_t pmatch[2];
int offset=0;
const char *str = text.c_str();
Number number;
string nstr;
while (offset < text.size() && regexec(regNumber, str+offset, 2, pmatch, 0) == 0 ) {
int pos = offset + pmatch[0].rm_so;
int length = pmatch[0].rm_eo - pmatch[0].rm_so;
offset += pmatch[0].rm_eo;
nstr = text.substr(pos, length);
if ( number.set(nstr) ) {
numbers.push_back(number);
}
}
/*
int l=text.size();
string str;
Number number;
Expand All @@ -638,6 +658,7 @@ NumbersOutput::NumbersOutput(const string &text):OutputChecker(text){
if(str.size()>0){
if(isNumStart(str[0]) && number.set(str)) numbers.push_back(number);
}
*/
startWithAsterisk=calcStartWithAsterisk();
}

Expand Down

0 comments on commit b8fc631

Please sign in to comment.