diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2020-05-05 20:43:45 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2020-05-05 20:43:45 +0200 |
commit | b1c3a29ac759a15cb2ade7e96d7f1b4d1ce28935 (patch) | |
tree | ffae98f0157ffa2031c4591877950454009d194c /src/core/wee-eval.c | |
parent | 8df8d20f81dc64bb286f5d1a1d629d050949893d (diff) | |
download | weechat-b1c3a29ac759a15cb2ade7e96d7f1b4d1ce28935.zip |
core: add include comparison operators in evaluation of expressions
New comparison operators:
- "==*": is matching mask, case sensitive (wildcard "*" is allowed)
- "!!*": is NOT matching mask, case sensitive (wildcard "*" is allowed)
- "==-": is included, case sensitive
- "!!-": is NOT included, case sensitive
- "=-": is included, case insensitive
- "!-": is NOT included, case insensitive
Diffstat (limited to 'src/core/wee-eval.c')
-rw-r--r-- | src/core/wee-eval.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/core/wee-eval.c b/src/core/wee-eval.c index 7ca93360a..e30f944fe 100644 --- a/src/core/wee-eval.c +++ b/src/core/wee-eval.c @@ -54,7 +54,12 @@ char *logical_ops[EVAL_NUM_LOGICAL_OPS] = { "||", "&&" }; char *comparisons[EVAL_NUM_COMPARISONS] = -{ "=~", "!~", "=*", "!*", "==", "!=", "<=", "<", ">=", ">" }; +{ "=~", "!~", /* regex */ + "==*", "!!*", "=*", "!*", /* string match */ + "==-", "!!-", "=-", "!-", /* includes */ + "==", "!=", /* equal, not equal */ + "<=", "<", ">=", ">", /* less than, greater than */ +}; char *eval_replace_vars (const char *expr, @@ -934,6 +939,14 @@ eval_compare (const char *expr1, int comparison, const char *expr2, rc ^= 1; goto end; } + else if ((comparison == EVAL_COMPARE_STRING_MATCHING_CASE_SENSITIVE) + || (comparison == EVAL_COMPARE_STRING_NOT_MATCHING_CASE_SENSITIVE)) + { + rc = string_match (expr1, expr2, 1); + if (comparison == EVAL_COMPARE_STRING_NOT_MATCHING_CASE_SENSITIVE) + rc ^= 1; + goto end; + } else if ((comparison == EVAL_COMPARE_STRING_MATCHING) || (comparison == EVAL_COMPARE_STRING_NOT_MATCHING)) { @@ -942,6 +955,22 @@ eval_compare (const char *expr1, int comparison, const char *expr2, rc ^= 1; goto end; } + else if ((comparison == EVAL_COMPARE_INCLUDE_CASE_SENSITIVE) + || (comparison == EVAL_COMPARE_NOT_INCLUDE_CASE_SENSITIVE)) + { + rc = (strstr (expr1, expr2)) ? 1 : 0; + if (comparison == EVAL_COMPARE_NOT_INCLUDE_CASE_SENSITIVE) + rc ^= 1; + goto end; + } + else if ((comparison == EVAL_COMPARE_INCLUDE) + || (comparison == EVAL_COMPARE_NOT_INCLUDE)) + { + rc = (string_strcasestr (expr1, expr2)) ? 1 : 0; + if (comparison == EVAL_COMPARE_NOT_INCLUDE) + rc ^= 1; + goto end; + } length1 = strlen (expr1); length2 = strlen (expr2); |