summaryrefslogtreecommitdiff
path: root/src/plugins/aspell/weechat-aspell.c
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2013-09-20 19:31:34 +0200
committerSebastien Helleu <flashcode@flashtux.org>2013-09-20 19:31:34 +0200
commita9ca95241d4ad5b60b04053c2987160f18f2d3d5 (patch)
tree33b9eb8b3842fda88f53fe0cdc0bae3e502623cb /src/plugins/aspell/weechat-aspell.c
parent2fcdba1332d604d37ab443e020b066497cc9ff9c (diff)
downloadweechat-a9ca95241d4ad5b60b04053c2987160f18f2d3d5.zip
aspell: fix detection of word start/end when there are apostrophes or minus chars before/after word (thanks to Nils Görs)
Diffstat (limited to 'src/plugins/aspell/weechat-aspell.c')
-rw-r--r--src/plugins/aspell/weechat-aspell.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/plugins/aspell/weechat-aspell.c b/src/plugins/aspell/weechat-aspell.c
index 471a639eb..86871293c 100644
--- a/src/plugins/aspell/weechat-aspell.c
+++ b/src/plugins/aspell/weechat-aspell.c
@@ -545,14 +545,14 @@ weechat_aspell_modifier_cb (void *data, const char *modifier,
long unsigned int value;
struct t_gui_buffer *buffer;
struct t_aspell_speller_buffer *ptr_speller_buffer;
- char *result, *ptr_string, *pos_space, *ptr_end, save_end;
+ char *result, *ptr_string, *pos_space, *ptr_end, *ptr_end_valid, save_end;
char *word_for_suggestions, *old_suggestions, *suggestions;
char *word_and_suggestions;
const char *color_normal, *color_error, *ptr_suggestions;
int utf8_char_int, char_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;
+ int input_pos, current_pos, word_start_pos, word_end_pos, word_end_pos_valid;
/* make C compiler happy */
(void) data;
@@ -672,11 +672,9 @@ weechat_aspell_modifier_cb (void *data, const char *modifier,
current_pos = 0;
while (ptr_string[0])
{
- /* find start of word */
+ /* find start of word: it must start with an alphanumeric char */
utf8_char_int = weechat_utf8_char_int (ptr_string);
- while ((!iswalnum (utf8_char_int) && (utf8_char_int != '\'')
- && (utf8_char_int != '-'))
- || iswspace (utf8_char_int))
+ while ((!iswalnum (utf8_char_int)) || iswspace (utf8_char_int))
{
char_size = weechat_utf8_char_size (ptr_string);
memcpy (result + index_result, ptr_string, char_size);
@@ -692,19 +690,29 @@ weechat_aspell_modifier_cb (void *data, const char *modifier,
word_start_pos = current_pos;
word_end_pos = current_pos;
+ word_end_pos_valid = current_pos;
- /* find end of word */
+ /* find end of word: ' and - allowed in word, but not at the end */
+ ptr_end_valid = ptr_string;
ptr_end = weechat_utf8_next_char (ptr_string);
utf8_char_int = weechat_utf8_char_int (ptr_end);
while (iswalnum (utf8_char_int) || (utf8_char_int == '\'')
|| (utf8_char_int == '-'))
{
- ptr_end = weechat_utf8_next_char (ptr_end);
word_end_pos++;
+ if (iswalnum (utf8_char_int))
+ {
+ /* pointer to last alphanumeric char in the word */
+ ptr_end_valid = ptr_end;
+ word_end_pos_valid = word_end_pos;
+ }
+ ptr_end = weechat_utf8_next_char (ptr_end);
if (!ptr_end[0])
break;
utf8_char_int = weechat_utf8_char_int (ptr_end);
}
+ ptr_end = weechat_utf8_next_char (ptr_end_valid);
+ word_end_pos = word_end_pos_valid;
word_ok = 0;
if (weechat_aspell_string_is_url (ptr_string))
{