1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-29 06:16:40 +02:00

Allow mask or regex for IRC command /ignore (mask is default)

This commit is contained in:
Sebastien Helleu
2008-10-31 13:12:56 +01:00
parent b5eeb9254e
commit f766dc2f11
15 changed files with 278 additions and 167 deletions
+50
View File
@@ -715,6 +715,56 @@ string_has_highlight (const char *string, const char *highlight_words)
return 0;
}
/*
* string_mask_to_regex: convert a mask (string with only "*" as joker) to a
* regex, paying attention to special chars in a regex
*/
char *
string_mask_to_regex (const char *mask)
{
char *result;
const char *ptr_mask;
int index_result;
char *regex_special_char = ".[]{}()|?+";
if (!mask)
return NULL;
result = malloc ((strlen (mask) * 2) + 1);
if (!result)
return NULL;
result[0] = '\0';
index_result = 0;
ptr_mask = mask;
while (ptr_mask[0])
{
/* '*' in string ? then replace by '.*' */
if (ptr_mask[0] == '*')
{
result[index_result++] = '.';
result[index_result++] = '*';
}
/* special regex char in string ? escape it with '\' */
else if (strchr (regex_special_char, ptr_mask[0]))
{
result[index_result++] = '\\';
result[index_result++] = ptr_mask[0];
}
/* standard char, just copy it */
else
result[index_result++] = ptr_mask[0];
ptr_mask++;
}
/* add final '\0' */
result[index_result] = '\0';
return result;
}
/*
* string_explode: explode a string according to separators
* examples: