Replacing a fake 'while', and deleting a redundant 'if' -- we searched

for whole words only, so it will be a whole word.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5781 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Benno Schulenberg 2016-03-31 11:14:25 +00:00
parent c709c104a1
commit 5022e47940
2 changed files with 21 additions and 14 deletions

View File

@ -1,3 +1,7 @@
2016-03-31 Benno Schulenberg <bensberg@justemail.net>
* src/text.c (do_int_spell_fix): Replace a fake 'while' and delete
a redundant 'if' -- we searched for whole words only, so it will be.
2016-03-30 Benno Schulenberg <bensberg@justemail.net> 2016-03-30 Benno Schulenberg <bensberg@justemail.net>
* src/search.c (do_replace_loop, go_looking, findnextstr): Report * src/search.c (do_replace_loop, go_looking, findnextstr): Report
"Cancelled" instead of "Not found" when the user aborts a replace "Cancelled" instead of "Not found" when the user aborts a replace

View File

@ -2353,14 +2353,16 @@ void do_full_justify(void)
* return FALSE if the user cancels. */ * return FALSE if the user cancels. */
bool do_int_spell_fix(const char *word) bool do_int_spell_fix(const char *word)
{ {
char *save_search; char *save_search, *exp_word;
size_t match_len, current_x_save = openfile->current_x; size_t match_len, current_x_save = openfile->current_x;
size_t pww_save = openfile->placewewant; size_t pww_save = openfile->placewewant;
filestruct *edittop_save = openfile->edittop; filestruct *edittop_save = openfile->edittop;
filestruct *current_save = openfile->current; filestruct *current_save = openfile->current;
/* Save where we are. */ /* Save where we are. */
bool canceled = FALSE; bool canceled = FALSE;
/* The return value. */ /* The inverse of this function's return value. */
bool result;
/* The return value of searching for a misspelled word. */
unsigned stash[sizeof(flags) / sizeof(flags[0])]; unsigned stash[sizeof(flags) / sizeof(flags[0])];
/* A storage place for the current flag settings. */ /* A storage place for the current flag settings. */
#ifndef NANO_TINY #ifndef NANO_TINY
@ -2417,21 +2419,24 @@ bool do_int_spell_fix(const char *word)
openfile->current_x = (size_t)-1; openfile->current_x = (size_t)-1;
openfile->placewewant = 0; openfile->placewewant = 0;
/* Find the first whole occurrence of word. */
findnextstr_wrap_reset(); findnextstr_wrap_reset();
while (findnextstr(TRUE, openfile->fileage, 0, word, &match_len) == 1) {
if (is_whole_word(openfile->current_x, openfile->current->data, /* Find the first whole occurrence of word. */
word)) { result = findnextstr(TRUE, openfile->fileage, 0, word, &match_len);
size_t xpt = xplustabs();
char *exp_word = display_string(openfile->current->data, /* The word must exist; if not, something is wrong. */
xpt, strnlenpt(openfile->current->data, if (result == 0)
openfile->current_x + match_len) - xpt, FALSE); statusbar("Internal error: speller listed unfindable word");
else if (result == 1) {
exp_word = display_string(openfile->current->data, xplustabs(),
strnlenpt(openfile->current->data,
openfile->current_x + match_len) - xplustabs(), FALSE);
edit_refresh(); edit_refresh();
spotlight(TRUE, exp_word); spotlight(TRUE, exp_word);
/* Allow all instances of the word to be corrected. */ /* Let the user supply a correctly spelled alternative. */
canceled = (do_prompt(FALSE, canceled = (do_prompt(FALSE,
#ifndef DISABLE_TABCOMP #ifndef DISABLE_TABCOMP
TRUE, TRUE,
@ -2446,14 +2451,12 @@ bool do_int_spell_fix(const char *word)
free(exp_word); free(exp_word);
/* If a replacement was given, go through all occurrences. */
if (!canceled && strcmp(word, answer) != 0) { if (!canceled && strcmp(word, answer) != 0) {
openfile->current_x--; openfile->current_x--;
do_replace_loop(TRUE, openfile->current, do_replace_loop(TRUE, openfile->current,
&openfile->current_x, word); &openfile->current_x, word);
} }
break;
}
} }
#ifndef NANO_TINY #ifndef NANO_TINY