diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2020-08-25 07:36:50 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2020-08-25 19:37:42 +0200 |
commit | e25c36479061cb20f8f163c28e74540311d85274 (patch) | |
tree | e93c176a6f12310f794f6b2815b958de9a2df74c | |
parent | 299f74bfef9e0d239ad141a4df3b2dcf11a4c0da (diff) | |
download | weechat-e25c36479061cb20f8f163c28e74540311d85274.zip |
spell: skip IRC color codes when checking words in input (closes #1547)
-rw-r--r-- | ChangeLog.adoc | 2 | ||||
-rw-r--r-- | src/plugins/spell/spell.c | 75 |
2 files changed, 61 insertions, 16 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 55b423398..d50efa216 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -32,7 +32,7 @@ Bug fixes:: * core: set "notify_level" to 3 if there is a highlight in the line (issue #1529) * core: do not add line with highlight and tag "notify_none" to hotlist (issue #1529) * irc: send all channels in a single JOIN command when reconnecting to the server (issue #1551) - * spell: properly skip WeeChat color codes when checking words in input (issue #1547) + * spell: properly skip WeeChat and IRC color codes when checking words in input (issue #1547) * trigger: fix recursive calls to triggers using regex (issue #1546) * trigger: add `${tg_tags} !!- ,notify_none,` in conditions of default trigger "beep" (issue #1529) diff --git a/src/plugins/spell/spell.c b/src/plugins/spell/spell.c index 2f813d7d4..0cd546eca 100644 --- a/src/plugins/spell/spell.c +++ b/src/plugins/spell/spell.c @@ -31,6 +31,7 @@ #include <string.h> #include <sys/time.h> #include <wctype.h> +#include <ctype.h> #include "../weechat-plugin.h" #include "spell.h" @@ -640,13 +641,67 @@ spell_get_suggestions (struct t_spell_speller_buffer *speller_buffer, } /* + * Skips WeeChat and IRC color codes in *string and adds them to "result". + */ + +void +spell_skip_color_codes (char **string, char **result) +{ + int color_code_size; + + while (*string[0]) + { + color_code_size = weechat_string_color_code_size (*string); + if (color_code_size > 0) + { + /* WeeChat color code */ + weechat_string_dyn_concat (result, *string, color_code_size); + (*string) += color_code_size; + } + else if (*string[0] == '\x03') + { + /* IRC color code */ + weechat_string_dyn_concat (result, *string, 1); + (*string)++; + if (isdigit (*string[0])) + { + /* foreground */ + weechat_string_dyn_concat (result, *string, 1); + (*string)++; + if (isdigit (*string[0])) + { + weechat_string_dyn_concat (result, *string, 1); + (*string)++; + } + } + if ((*string[0] == ',') && (isdigit (*string[1]))) + { + /* background */ + weechat_string_dyn_concat (result, *string, 1); + (*string)++; + if (isdigit (*string[0])) + { + weechat_string_dyn_concat (result, *string, 1); + (*string)++; + } + } + } + else + { + /* not a color code */ + break; + } + } +} + +/* * Updates input text by adding color for misspelled words. */ char * spell_modifier_cb (const void *pointer, void *data, - const char *modifier, - const char *modifier_data, const char *string) + const char *modifier, + const char *modifier_data, const char *string) { unsigned long value; struct t_gui_buffer *buffer; @@ -656,7 +711,7 @@ spell_modifier_cb (const void *pointer, void *data, char *misspelled_word, *old_misspelled_word, *old_suggestions, *suggestions; char *word_and_suggestions; const char *color_normal, *color_error, *ptr_suggestions, *pos_colon; - int code_point, char_size, color_code_size; + int code_point, char_size; int length, word_ok, rc; int input_pos, current_pos, word_start_pos, word_end_pos, word_end_pos_valid; @@ -774,12 +829,7 @@ spell_modifier_cb (const void *pointer, void *data, { ptr_string_orig = NULL; - /* skip color codes */ - while ((color_code_size = weechat_string_color_code_size (ptr_string)) > 0) - { - weechat_string_dyn_concat (result, ptr_string, color_code_size); - ptr_string += color_code_size; - } + spell_skip_color_codes (&ptr_string, result); if (!ptr_string[0]) break; @@ -787,12 +837,7 @@ spell_modifier_cb (const void *pointer, void *data, code_point = weechat_utf8_char_int (ptr_string); while ((!iswalnum (code_point)) || iswspace (code_point)) { - /* skip color codes */ - while ((color_code_size = weechat_string_color_code_size (ptr_string)) > 0) - { - weechat_string_dyn_concat (result, ptr_string, color_code_size); - ptr_string += color_code_size; - } + spell_skip_color_codes (&ptr_string, result); if (!ptr_string[0]) break; |