summaryrefslogtreecommitdiff
path: root/src/gui/gui-line.c
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2018-08-07 21:50:04 +0200
committerSébastien Helleu <flashcode@flashtux.org>2018-08-12 20:30:13 +0200
commit12a6f74ec01d9daa2e23dce5ab15b1ee3ce09006 (patch)
treeacf40a6fdbe99a8192c29408f130bdf900f12d2e /src/gui/gui-line.c
parentd699ae89aa0ff818b6264ad17f62377f1753999d (diff)
downloadweechat-12a6f74ec01d9daa2e23dce5ab15b1ee3ce09006.zip
core: fix check of tags in lines
All changes: - fix check of tags in lines: check lines without tags, fix check of tags with negation ("!tag") - add string functions string_split_tags and string_free_split_tags - add tests on function gui_line_match_tags
Diffstat (limited to 'src/gui/gui-line.c')
-rw-r--r--src/gui/gui-line.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c
index 7b4894c29..fd7677198 100644
--- a/src/gui/gui-line.c
+++ b/src/gui/gui-line.c
@@ -604,35 +604,44 @@ gui_line_match_tags (struct t_gui_line_data *line_data,
int tags_count, char ***tags_array)
{
int i, j, k, match, tag_found, tag_negated;
+ const char *ptr_tag;
if (!line_data)
return 0;
- if (line_data->tags_count == 0)
- return 0;
-
for (i = 0; i < tags_count; i++)
{
match = 1;
for (j = 0; tags_array[i][j]; j++)
{
+ ptr_tag = tags_array[i][j];
tag_found = 0;
tag_negated = 0;
/* check if tag is negated (prefixed with a '!') */
- if ((tags_array[i][j][0] == '!') && tags_array[i][j][1])
+ if ((ptr_tag[0] == '!') && ptr_tag[1])
+ {
+ ptr_tag++;
tag_negated = 1;
+ }
- for (k = 0; k < line_data->tags_count; k++)
+ if (strcmp (ptr_tag, "*") == 0)
{
- if (string_match (line_data->tags_array[k],
- (tag_negated) ? tags_array[i][j] + 1 : tags_array[i][j],
- 0))
+ tag_found = 1;
+ }
+ else
+ {
+ for (k = 0; k < line_data->tags_count; k++)
{
- tag_found = 1;
- break;
+ if (string_match (line_data->tags_array[k], ptr_tag, 0))
+ {
+ tag_found = 1;
+ break;
+ }
}
}
+ if (tag_found && tag_negated)
+ return 0;
if ((!tag_found && !tag_negated) || (tag_found && tag_negated))
{
match = 0;