if can have a variable test or a content check
This commit is contained in:
@@ -845,7 +845,7 @@ if testtag AX_USE_DOXYGEN; then
|
|||||||
doxyreplace PROJECT_NAME "@PACKAGE_NAME@"
|
doxyreplace PROJECT_NAME "@PACKAGE_NAME@"
|
||||||
doxyreplace PROJECT_NUMBER "@PACKAGE_VERSION@"
|
doxyreplace PROJECT_NUMBER "@PACKAGE_VERSION@"
|
||||||
doxyreplace PROJECT_BRIEF "@DESCRIPTION@"
|
doxyreplace PROJECT_BRIEF "@DESCRIPTION@"
|
||||||
doxyreplace PROJECT_LOGO "@top_srcdir@/@PACKACE_LOGO@"
|
doxyreplace PROJECT_LOGO "@top_srcdir@/@PACKAGE_LOGO@"
|
||||||
doxyreplace INLINE_INHERITED_MEMB YES
|
doxyreplace INLINE_INHERITED_MEMB YES
|
||||||
doxyreplace MULTILINE_CPP_IS_BRIEF YES
|
doxyreplace MULTILINE_CPP_IS_BRIEF YES
|
||||||
doxyreplace TAB_SIZE 2
|
doxyreplace TAB_SIZE 2
|
||||||
|
@@ -2084,16 +2084,28 @@ class If: public Command {
|
|||||||
" <command3>\n"
|
" <command3>\n"
|
||||||
" <command4>\n"
|
" <command4>\n"
|
||||||
" <...>\n"
|
" <...>\n"
|
||||||
|
"\n\n"+
|
||||||
|
tag()+" <selector> -> <text>\n"
|
||||||
|
" <command1>\n"
|
||||||
|
" <command2>\n"
|
||||||
|
" <...>\n"
|
||||||
|
"else\n"
|
||||||
|
" <command3>\n"
|
||||||
|
" <command4>\n"
|
||||||
|
" <...>\n"
|
||||||
"\n\n"
|
"\n\n"
|
||||||
"Execute commands conditionally. "
|
"Execute commands conditionally. "
|
||||||
|
"The first variant compares a variable to a value. "
|
||||||
"The comparision <cmp> can be = ^ . ~ < >, "
|
"The comparision <cmp> can be = ^ . ~ < >, "
|
||||||
"which means equal, different, contains, match, "
|
"which means equal, different, contains, match, "
|
||||||
"less (as integer), bigger (as integer). "
|
"less (as integer), bigger (as integer). "
|
||||||
"Match allows a regular expression. "
|
"Match allows a regular expression. "
|
||||||
|
"The second variant checks for a text in a selector, "
|
||||||
|
"similar to command exists. "
|
||||||
"There is an optional else part.";
|
"There is an optional else part.";
|
||||||
}
|
}
|
||||||
QString command() const {
|
QString command() const {
|
||||||
return tag()+" "+_variable+" "+QString(_cmp)+" "+_value
|
return tag()+" "+_variable+" "+_cmp+" "+_value
|
||||||
+(_script.get()?"\n"+_script->print().join("\n "):"");
|
+(_script.get()?"\n"+_script->print().join("\n "):"");
|
||||||
}
|
}
|
||||||
std::shared_ptr<Command> parse(Script*, QString args,
|
std::shared_ptr<Command> parse(Script*, QString args,
|
||||||
@@ -2101,10 +2113,17 @@ class If: public Command {
|
|||||||
int indent) {
|
int indent) {
|
||||||
std::shared_ptr<If> cmd(new If());
|
std::shared_ptr<If> cmd(new If());
|
||||||
int pos(args.indexOf(QRegularExpression("[=^.~<>]")));
|
int pos(args.indexOf(QRegularExpression("[=^.~<>]")));
|
||||||
if (pos<0) throw BadArgument(tag()+" needs a comparision, not: "+args);
|
int len(1);
|
||||||
|
if (args.contains("->")) {
|
||||||
|
pos = args.indexOf("->");
|
||||||
|
len = 2;
|
||||||
|
cmd->_cmp = "->";
|
||||||
|
} else {
|
||||||
|
if (pos<0) throw BadArgument(tag()+" needs a comparision, not: "+args);
|
||||||
|
cmd->_cmp = args[pos];
|
||||||
|
}
|
||||||
cmd->_variable = args.left(pos).trimmed();
|
cmd->_variable = args.left(pos).trimmed();
|
||||||
cmd->_cmp = args[pos].toLatin1();
|
cmd->_value = args.mid(pos+len).trimmed();
|
||||||
cmd->_value = args.mid(pos+1).trimmed();
|
|
||||||
cmd->_script = std::shared_ptr<Script>(new Script);
|
cmd->_script = std::shared_ptr<Script>(new Script);
|
||||||
cmd->_script->parse(subCommandBlock(in), file, line+1, indent+1);
|
cmd->_script->parse(subCommandBlock(in), file, line+1, indent+1);
|
||||||
if (in.size() && in.first().contains(QRegularExpression("^else *$"))) {
|
if (in.size() && in.first().contains(QRegularExpression("^else *$"))) {
|
||||||
@@ -2117,32 +2136,46 @@ class If: public Command {
|
|||||||
bool execute(Script* script, QWebFrame* frame) {
|
bool execute(Script* script, QWebFrame* frame) {
|
||||||
Logger log(this, script, false);
|
Logger log(this, script, false);
|
||||||
QString value(script->replacevars(_value));
|
QString value(script->replacevars(_value));
|
||||||
|
QString selector(script->replacevars(_variable));
|
||||||
bool check(false);
|
bool check(false);
|
||||||
switch (_cmp) {
|
if (_cmp=="->") {
|
||||||
case '=': check = script->variable(_variable)==value;
|
Q_FOREACH(QWebElement element, frame->findAllElements(selector)) {
|
||||||
break;
|
if (value.isEmpty() || // just find element
|
||||||
case '^': check = script->variable(_variable)!=value;
|
element.toOuterXml().indexOf(value)!=-1 ||
|
||||||
break;
|
element.toPlainText().indexOf(value)!=-1) {
|
||||||
case '.': check = script->variable(_variable).contains(value);
|
check = true;
|
||||||
break;
|
break;
|
||||||
case '~': check =
|
}
|
||||||
script->variable(_variable).contains(QRegularExpression(value));
|
}
|
||||||
break;
|
log(QString("evaluated expression to ")+(check?"true":"false")+": "
|
||||||
case '<': check = script->variable(_variable).toInt()<value.toInt();
|
+selector+" "+_cmp+" "+value);
|
||||||
break;
|
} else {
|
||||||
case '>': check = script->variable(_variable).toInt()>value.toInt();
|
switch (_cmp[0].toLatin1()) {
|
||||||
break;
|
case '=': check = script->variable(_variable)==value;
|
||||||
default:;
|
break;
|
||||||
|
case '^': check = script->variable(_variable)!=value;
|
||||||
|
break;
|
||||||
|
case '.': check = script->variable(_variable).contains(value);
|
||||||
|
break;
|
||||||
|
case '~': check =
|
||||||
|
script->variable(_variable).contains(QRegularExpression(value));
|
||||||
|
break;
|
||||||
|
case '<': check = script->variable(_variable).toInt()<value.toInt();
|
||||||
|
break;
|
||||||
|
case '>': check = script->variable(_variable).toInt()>value.toInt();
|
||||||
|
break;
|
||||||
|
default:;
|
||||||
|
}
|
||||||
|
log(QString("evaluated expression to ")+(check?"true":"false")+":"
|
||||||
|
+script->variable(_variable)+" "+_cmp+" "+value);
|
||||||
}
|
}
|
||||||
log("evaluated expression: "+script->variable(_variable)
|
|
||||||
+" "+_cmp+" "+value);
|
|
||||||
if (check) return runScript(this, _script, script, frame);
|
if (check) return runScript(this, _script, script, frame);
|
||||||
else if (_else) return runScript(this, _else, script, frame);
|
else if (_else) return runScript(this, _else, script, frame);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
QString _variable;
|
QString _variable;
|
||||||
char _cmp;
|
QString _cmp;
|
||||||
QString _value;
|
QString _value;
|
||||||
std::shared_ptr<Script> _script;
|
std::shared_ptr<Script> _script;
|
||||||
std::shared_ptr<Script> _else;
|
std::shared_ptr<Script> _else;
|
||||||
|
Reference in New Issue
Block a user