mirror of
https://github.com/weechat/weechat.git
synced 2026-07-09 19:23:13 +02:00
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
This commit is contained in:
+24
-13
@@ -7364,19 +7364,29 @@ command_init ()
|
||||
"separated by semicolons\n"
|
||||
" operator: a logical or comparison operator:\n"
|
||||
" - logical operators:\n"
|
||||
" && boolean \"and\"\n"
|
||||
" || boolean \"or\"\n"
|
||||
" && boolean \"and\"\n"
|
||||
" || boolean \"or\"\n"
|
||||
" - comparison operators:\n"
|
||||
" == equal\n"
|
||||
" != not equal\n"
|
||||
" <= less or equal\n"
|
||||
" < less\n"
|
||||
" >= greater or equal\n"
|
||||
" > greater\n"
|
||||
" =~ is matching POSIX extended regex\n"
|
||||
" !~ is NOT matching POSIX extended regex\n"
|
||||
" =* is matching mask (wildcard \"*\" is allowed)\n"
|
||||
" !* is NOT matching mask (wildcard \"*\" is allowed)\n"
|
||||
" == equal\n"
|
||||
" != not equal\n"
|
||||
" <= less or equal\n"
|
||||
" < less\n"
|
||||
" >= greater or equal\n"
|
||||
" > greater\n"
|
||||
" =~ is matching POSIX extended regex\n"
|
||||
" !~ is NOT matching POSIX extended regex\n"
|
||||
" ==* is matching mask, case sensitive "
|
||||
"(wildcard \"*\" is allowed)\n"
|
||||
" !!* is NOT matching mask, case sensitive "
|
||||
"(wildcard \"*\" is allowed)\n"
|
||||
" =* is matching mask, case insensitive "
|
||||
"(wildcard \"*\" is allowed)\n"
|
||||
" !* is NOT matching mask, case insensitive "
|
||||
"(wildcard \"*\" is allowed)\n"
|
||||
" ==- is included, case sensitive\n"
|
||||
" !!- is NOT included, case sensitive\n"
|
||||
" =- is included, case insensitive\n"
|
||||
" !- is NOT included, case insensitive\n"
|
||||
"\n"
|
||||
"An expression is considered as \"true\" if it is not NULL, not "
|
||||
"empty, and different from \"0\".\n"
|
||||
@@ -7465,7 +7475,8 @@ command_init ()
|
||||
" /eval -n -c abcd =~ (?-i)^ABC ==> 0\n"
|
||||
" /eval -n -c abcd =~ (?-i)^abc ==> 1\n"
|
||||
" /eval -n -c abcd !~ abc ==> 0\n"
|
||||
" /eval -n -c abcd =* a*d ==> 1"),
|
||||
" /eval -n -c abcd =* a*d ==> 1\n"
|
||||
" /eval -n -c abcd =- bc ==> 1"),
|
||||
"-n|-s|-c -n|-s|-c",
|
||||
&command_eval, NULL, NULL);
|
||||
hook_command (
|
||||
|
||||
+30
-1
@@ -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);
|
||||
|
||||
@@ -44,8 +44,14 @@ enum t_eval_comparison
|
||||
{
|
||||
EVAL_COMPARE_REGEX_MATCHING = 0,
|
||||
EVAL_COMPARE_REGEX_NOT_MATCHING,
|
||||
EVAL_COMPARE_STRING_MATCHING_CASE_SENSITIVE,
|
||||
EVAL_COMPARE_STRING_NOT_MATCHING_CASE_SENSITIVE,
|
||||
EVAL_COMPARE_STRING_MATCHING,
|
||||
EVAL_COMPARE_STRING_NOT_MATCHING,
|
||||
EVAL_COMPARE_INCLUDE_CASE_SENSITIVE,
|
||||
EVAL_COMPARE_NOT_INCLUDE_CASE_SENSITIVE,
|
||||
EVAL_COMPARE_INCLUDE,
|
||||
EVAL_COMPARE_NOT_INCLUDE,
|
||||
EVAL_COMPARE_EQUAL,
|
||||
EVAL_COMPARE_NOT_EQUAL,
|
||||
EVAL_COMPARE_LESS_EQUAL,
|
||||
|
||||
Reference in New Issue
Block a user