fix check when the second argument contains operator-characters
This commit is contained in:
@@ -19,7 +19,7 @@ AM_INIT_AUTOMAKE([1.9 tar-pax])
|
||||
AX_INIT_STANDARD_PROJECT
|
||||
|
||||
# requirements, uncomment, what you need:
|
||||
AX_USE_CXX
|
||||
AX_USE_CXX_11
|
||||
#AX_USE_LIBTOOL
|
||||
AX_USE_SCRIPTS
|
||||
AX_USE_DOXYGEN
|
||||
|
@@ -32,6 +32,8 @@
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <xml-cxx/xml.hxx>
|
||||
#include <mrw/stdext.hxx>
|
||||
|
||||
@@ -210,24 +212,27 @@ class Command: public QObject {
|
||||
}
|
||||
QStringList quotedStrings(QString value,
|
||||
QString delimiter = " ",
|
||||
bool keepDelimiters = false) const {
|
||||
bool keepDelimiters = false,
|
||||
unsigned int max = 0) const {
|
||||
QStringList res;
|
||||
QString quot("'\"");
|
||||
unsigned int found(0);
|
||||
while (value=value.trimmed(), value.size()) {
|
||||
QRegularExpression re;
|
||||
int start(0);
|
||||
if (quot.contains(value[0])) {
|
||||
re = QRegularExpression(value[0]+" *(("+delimiter+" *)|$)");
|
||||
re = QRegularExpression(value[0]+" *((("+delimiter+") *)|$)");
|
||||
start = 1;
|
||||
} else {
|
||||
re = QRegularExpression("( *"+delimiter+" *)|$");
|
||||
re = QRegularExpression(" *((("+delimiter+") *)|$)");
|
||||
}
|
||||
int pos(value.indexOf(re, start));
|
||||
if (pos<start) throw BadArgument("quote missmatch in "+value);
|
||||
QRegularExpressionMatch m(re.match(value, start));
|
||||
res += value.mid(start, m.capturedStart()-start);
|
||||
value.remove(0, m.capturedEnd());
|
||||
if (keepDelimiters && m.capturedLength()) res+=m.captured().mid(start).trimmed();
|
||||
if (keepDelimiters && !m.captured(3).isEmpty()) res+=m.captured(3).trimmed();
|
||||
if (++found==max) return res += value;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -2609,12 +2614,12 @@ class Check: public Command {
|
||||
std::shared_ptr<Check> cmd(new Check());
|
||||
cmd->_next = 0;
|
||||
QString comp("[=!.^~<>]");
|
||||
QStringList allargs = quotedStrings(args, comp, true);
|
||||
QStringList allargs = quotedStrings(args, comp, true, 1);
|
||||
if (allargs.size()<2 || allargs[1].size()!=1 ||
|
||||
!QRegularExpression("^"+comp+"$").match(allargs[1]).hasMatch())
|
||||
throw BadArgument(tag()+" needs a comparision, not: "+args);
|
||||
throw BadArgument(tag()+" needs a comparision, not: "+args, allargs);
|
||||
if (allargs.size()>3)
|
||||
throw BadArgument(tag()+" has at most three arguments");
|
||||
throw BadArgument(tag()+" has at most three arguments", allargs);
|
||||
cmd->_value1 = allargs[0];
|
||||
cmd->_cmp = allargs[1][0].toLatin1();
|
||||
if (allargs.size()==3) {
|
||||
@@ -2623,7 +2628,7 @@ class Check: public Command {
|
||||
if (in.size() && in.first().contains(QRegularExpression("^ "))) {
|
||||
cmd->_next = script->parseLine(in, file, line+1, indent+1);
|
||||
cmd->_next->log(false); // suppress logging of subcommand
|
||||
} else throw BadArgument(tag()+" needs a third argument or a following command");
|
||||
} else throw BadArgument(tag()+" needs a third argument or a following command", allargs);
|
||||
}
|
||||
return cmd;
|
||||
}
|
||||
|
@@ -59,6 +59,9 @@ class UnknownCommand: public ParseError {
|
||||
class BadArgument: public ParseError {
|
||||
public:
|
||||
BadArgument(QString arg): ParseError("bad argument:"+p(arg)) {}
|
||||
BadArgument(QString arg, QStringList args):
|
||||
ParseError("bad argument:"+p(arg)+p("→ arguments:"+pq(args))) {
|
||||
}
|
||||
};
|
||||
|
||||
class MissingArguments: public ParseError {
|
||||
|
Reference in New Issue
Block a user