diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2016-10-02 08:58:19 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2016-10-02 08:58:19 +0200 |
commit | 54841f6294380c023f586598b672816f36a1adc3 (patch) | |
tree | ca468a6af023ce148e15a9f0f558d3e0b47ffcf0 /src/core | |
parent | f98d50ebab5c2a47da7b368ee219547638892e59 (diff) | |
download | weechat-54841f6294380c023f586598b672816f36a1adc3.zip |
api: fix return of function string_match() when there are multiple masks in the string (issue #812)
Some tests are added as well to test the multiple masks in the string.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-string.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 1481e6361..f63d6f6f5 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -378,7 +378,7 @@ string_strcasestr (const char *string, const char *search) int string_match (const char *string, const char *mask, int case_sensitive) { - const char *ptr_string, *ptr_mask, *pos_word, *pos_end; + const char *ptr_string, *ptr_mask, *pos_word, *pos_word2, *pos_end; char *word; int wildcard, length_word; @@ -429,7 +429,10 @@ string_match (const char *string, const char *mask, int case_sensitive) /* check if the word is matching */ if (wildcard) { - /* search the word anywhere in the string (from current position) */ + /* + * search the word anywhere in the string (from current position), + * multiple times if needed + */ pos_word = (case_sensitive) ? strstr (ptr_string, word) : string_strcasestr (ptr_string, word); if (!pos_word) @@ -437,6 +440,15 @@ string_match (const char *string, const char *mask, int case_sensitive) free (word); return 0; } + while (1) + { + pos_word2 = (case_sensitive) ? + strstr (pos_word + length_word, word) : + string_strcasestr (pos_word + length_word, word); + if (!pos_word2) + break; + pos_word = pos_word2; + } ptr_string = pos_word + length_word; } else |