diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2014-03-13 14:14:10 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2014-03-13 14:14:10 +0100 |
commit | eb21248ae7330bcece6d1d3e06711d5724f4d36e (patch) | |
tree | 8812803b2f773b6d7374d3835646ad3355361656 /src/core | |
parent | 1a30be392b2ebf392a172b8135261c87e716a4e0 (diff) | |
download | weechat-eb21248ae7330bcece6d1d3e06711d5724f4d36e.zip |
core: fix highlight problem with "(?-i)" and upper case letters in option weechat.look.highlight
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-string.c | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/src/core/wee-string.c b/src/core/wee-string.c index ff3d143e9..ae8292290 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -910,7 +910,7 @@ int string_has_highlight (const char *string, const char *highlight_words) { char *msg, *highlight, *match, *match_pre, *match_post, *msg_pos; - char *pos, *pos_end, *ptr_str, *ptr_string_ref; + char *pos, *pos_end; int end, length, startswith, endswith, wildcard_start, wildcard_end, flags; if (!string || !string[0] || !highlight_words || !highlight_words[0]) @@ -919,20 +919,18 @@ string_has_highlight (const char *string, const char *highlight_words) msg = strdup (string); if (!msg) return 0; - string_tolower (msg); + highlight = strdup (highlight_words); if (!highlight) { free (msg); return 0; } - string_tolower (highlight); pos = highlight; end = 0; while (!end) { - ptr_string_ref = (char *)string; flags = 0; pos = (char *)string_regex_flags (pos, REG_ICASE, &flags); @@ -950,16 +948,6 @@ string_has_highlight (const char *string, const char *highlight_words) return 0; } - if (flags & REG_ICASE) - { - for (ptr_str = pos; ptr_str < pos_end; ptr_str++) - { - if ((ptr_str[0] >= 'A') && (ptr_str[0] <= 'Z')) - ptr_str[0] += ('a' - 'A'); - } - ptr_string_ref = msg; - } - length = pos_end - pos; pos_end[0] = '\0'; if (length > 0) @@ -978,15 +966,18 @@ string_has_highlight (const char *string, const char *highlight_words) if (length > 0) { - msg_pos = ptr_string_ref; - /* highlight found! */ - while ((match = strstr (msg_pos, pos)) != NULL) + msg_pos = msg; + while (1) { - match_pre = utf8_prev_char (ptr_string_ref, match); + match = (flags & REG_ICASE) ? + string_strcasestr (msg_pos, pos) : strstr (msg_pos, pos); + if (!match) + break; + match_pre = utf8_prev_char (msg, match); if (!match_pre) match_pre = match - 1; match_post = match + length; - startswith = ((match == ptr_string_ref) || (!string_is_word_char (match_pre))); + startswith = ((match == msg) || (!string_is_word_char (match_pre))); endswith = ((!match_post[0]) || (!string_is_word_char (match_post))); if ((wildcard_start && wildcard_end) || (!wildcard_start && !wildcard_end && @@ -994,6 +985,7 @@ string_has_highlight (const char *string, const char *highlight_words) (wildcard_start && endswith) || (wildcard_end && startswith)) { + /* highlight found! */ free (msg); free (highlight); return 1; |