From 4b9e5f50b1903314ebb4a9e12fbdff8cfc572cc2 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 28 Mar 2013 09:40:48 +0400 Subject: [PATCH] (edit_complete_word_cmd): don't get bytes directly from editor buffer. (edit_get_match_keyword_cmd): likewise. Signed-off-by: Andrew Borodin --- src/editor/editcmd.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 2d69b31cb..c2425591a 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -3292,8 +3292,7 @@ edit_complete_word_cmd (WEdit * edit) { gsize i, max_len, word_len = 0, num_compl = 0; off_t word_start = 0; - unsigned char *bufpos; - char *match_expr; + GString *match_expr; GString *compl[MAX_WORD_COMPLETIONS]; /* completions */ /* search start of word to be completed */ @@ -3301,18 +3300,16 @@ edit_complete_word_cmd (WEdit * edit) return; /* prepare match expression */ - bufpos = &edit->buffers1[word_start >> S_EDIT_BUF_SIZE][word_start & M_EDIT_BUF_SIZE]; - /* match_expr = g_strdup_printf ("\\b%.*s[a-zA-Z_0-9]+", word_len, bufpos); */ - match_expr = - g_strdup_printf - ("(^|\\s+|\\b)%.*s[^\\s\\.=\\+\\[\\]\\(\\)\\,\\;\\:\\\"\\'\\-\\?\\/\\|\\\\\\{\\}\\*\\&\\^\\%%\\$#@\\!]+", - (int) word_len, bufpos); + match_expr = g_string_new ("(^|\\s+|\\b)"); + for (i = 0; i < word_len; i++) + g_string_append_c (match_expr, edit_get_byte (edit, word_start + i)); + g_string_append (match_expr, "[^\\s\\.=\\+\\[\\]\\(\\)\\,\\;\\:\\\"\\'\\-\\?\\/\\|\\\\\\{\\}\\*\\&\\^\\%%\\$#@\\!]+"); /* collect the possible completions */ /* start search from begin to end of file */ max_len = - edit_collect_completions (edit, word_start, word_len, match_expr, (GString **) & compl, + edit_collect_completions (edit, word_start, word_len, match_expr->str, (GString **) & compl, &num_compl); if (num_compl > 0) @@ -3342,7 +3339,7 @@ edit_complete_word_cmd (WEdit * edit) } } - g_free (match_expr); + g_string_free (match_expr, TRUE); /* release memory before return */ for (i = 0; i < num_compl; i++) g_string_free (compl[i], TRUE); @@ -3463,10 +3460,9 @@ edit_get_match_keyword_cmd (WEdit * edit) { gsize word_len = 0, max_len = 0; int num_def = 0; - int i; + gsize i; off_t word_start = 0; - unsigned char *bufpos; - char *match_expr; + GString *match_expr; char *path = NULL; char *ptr = NULL; char *tagfile = NULL; @@ -3483,8 +3479,9 @@ edit_get_match_keyword_cmd (WEdit * edit) return; /* prepare match expression */ - bufpos = &edit->buffers1[word_start >> S_EDIT_BUF_SIZE][word_start & M_EDIT_BUF_SIZE]; - match_expr = g_strdup_printf ("%.*s", (int) word_len, bufpos); + match_expr = g_string_sized_new (word_len); + for (i = 0; i < word_len; i++) + g_string_append_c (match_expr, edit_get_byte (edit, word_start + i)); ptr = g_get_current_dir (); path = g_strconcat (ptr, G_DIR_SEPARATOR_S, (char *) NULL); @@ -3506,7 +3503,7 @@ edit_get_match_keyword_cmd (WEdit * edit) if (tagfile) { num_def = - etags_set_definition_hash (tagfile, path, match_expr, (etags_hash_t *) & def_hash); + etags_set_definition_hash (tagfile, path, match_expr->str, (etags_hash_t *) & def_hash); g_free (tagfile); } g_free (path); @@ -3515,10 +3512,10 @@ edit_get_match_keyword_cmd (WEdit * edit) word_len = 0; if (num_def > 0) { - editcmd_dialog_select_definition_show (edit, match_expr, max_len, word_len, + editcmd_dialog_select_definition_show (edit, match_expr->str, max_len, word_len, (etags_hash_t *) & def_hash, num_def); } - g_free (match_expr); + g_string_free (match_expr, TRUE); } /* --------------------------------------------------------------------------------------------- */ -- 2.11.4.GIT