mirror of https://github.com/arendst/Tasmota.git
Merge pull request #10779 from barbudor/pr_stringops
add and fix new string ops in rules
This commit is contained in:
commit
9b91208bb7
|
@ -99,8 +99,10 @@
|
||||||
#define COMPARE_OPERATOR_STRING_ENDS_WITH 8
|
#define COMPARE_OPERATOR_STRING_ENDS_WITH 8
|
||||||
#define COMPARE_OPERATOR_STRING_STARTS_WITH 9
|
#define COMPARE_OPERATOR_STRING_STARTS_WITH 9
|
||||||
#define COMPARE_OPERATOR_STRING_CONTAINS 10
|
#define COMPARE_OPERATOR_STRING_CONTAINS 10
|
||||||
#define MAXIMUM_COMPARE_OPERATOR COMPARE_OPERATOR_STRING_CONTAINS
|
#define COMPARE_OPERATOR_STRING_NOT_EQUAL 11
|
||||||
const char kCompareOperators[] PROGMEM = "=\0>\0<\0|\0==!=>=<=$>$<$|";
|
#define COMPARE_OPERATOR_STRING_NOT_CONTAINS 12
|
||||||
|
#define MAXIMUM_COMPARE_OPERATOR COMPARE_OPERATOR_STRING_NOT_CONTAINS
|
||||||
|
const char kCompareOperators[] PROGMEM = "=\0>\0<\0|\0==!=>=<=$>$<$|$!$^";
|
||||||
|
|
||||||
#ifdef USE_EXPRESSION
|
#ifdef USE_EXPRESSION
|
||||||
#include <LinkedList.h> // Import LinkedList library
|
#include <LinkedList.h> // Import LinkedList library
|
||||||
|
@ -589,7 +591,13 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all
|
||||||
match = str_str_value.startsWith(rule_svalue);
|
match = str_str_value.startsWith(rule_svalue);
|
||||||
break;
|
break;
|
||||||
case COMPARE_OPERATOR_STRING_CONTAINS:
|
case COMPARE_OPERATOR_STRING_CONTAINS:
|
||||||
match = (str_str_value.indexOf(rule_svalue) > 0);
|
match = (str_str_value.indexOf(rule_svalue) >= 0);
|
||||||
|
break;
|
||||||
|
case COMPARE_OPERATOR_STRING_NOT_EQUAL:
|
||||||
|
match = (0!=strcasecmp(str_value, rule_svalue)); // Compare strings - this also works for hexadecimals
|
||||||
|
break;
|
||||||
|
case COMPARE_OPERATOR_STRING_NOT_CONTAINS:
|
||||||
|
match = (str_str_value.indexOf(rule_svalue) < 0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
match = true;
|
match = true;
|
||||||
|
@ -1634,7 +1642,13 @@ bool evaluateComparisonExpression(const char *expression, int len)
|
||||||
bResult = leftExpr.startsWith(rightExpr);
|
bResult = leftExpr.startsWith(rightExpr);
|
||||||
break;
|
break;
|
||||||
case COMPARE_OPERATOR_STRING_CONTAINS:
|
case COMPARE_OPERATOR_STRING_CONTAINS:
|
||||||
bResult = (leftExpr.indexOf(rightExpr) > 0);
|
bResult = (leftExpr.indexOf(rightExpr) >= 0);
|
||||||
|
break;
|
||||||
|
case COMPARE_OPERATOR_STRING_NOT_EQUAL:
|
||||||
|
bResult = !leftExpr.equalsIgnoreCase(rightExpr); // Compare strings - this also works for hexadecimals
|
||||||
|
break;
|
||||||
|
case COMPARE_OPERATOR_STRING_NOT_CONTAINS:
|
||||||
|
bResult = (leftExpr.indexOf(rightExpr) < 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return bResult;
|
return bResult;
|
||||||
|
|
Loading…
Reference in New Issue