diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2020-08-22 08:56:21 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2020-08-22 08:56:21 +0200 |
commit | b459dab84bcc2fa30634c083c931797e3ca6f4f6 (patch) | |
tree | 64a88f37bde2e372c2aecae66c40fd7d005f04e7 /src | |
parent | 268aa631c6b464c0d97dce5dbe76f145a6cc5f68 (diff) | |
download | weechat-b459dab84bcc2fa30634c083c931797e3ca6f4f6.zip |
spell: properly skip WeeChat color codes when checking words in input (closes #1547)
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/spell/spell.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/plugins/spell/spell.c b/src/plugins/spell/spell.c index e260f1164..905864019 100644 --- a/src/plugins/spell/spell.c +++ b/src/plugins/spell/spell.c @@ -656,7 +656,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; + int code_point, char_size, color_code_size; int length, index_result, length_word, word_ok; int length_color_normal, length_color_error, rc; int input_pos, current_pos, word_start_pos, word_end_pos, word_end_pos_valid; @@ -782,12 +782,33 @@ 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) + { + memcpy (result + index_result, ptr_string, color_code_size); + index_result += color_code_size; + ptr_string += color_code_size; + } + if (!ptr_string[0]) + break; + /* find start of word: it must start with an alphanumeric char */ 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) + { + memcpy (result + index_result, ptr_string, color_code_size); + index_result += color_code_size; + ptr_string += color_code_size; + } + if (!ptr_string[0]) + break; + if (!ptr_string_orig && !iswspace (code_point)) ptr_string_orig = ptr_string; + char_size = weechat_utf8_char_size (ptr_string); memcpy (result + index_result, ptr_string, char_size); index_result += char_size; |