Commit 1bc0c7e0 authored by Chris Allegretta's avatar Chris Allegretta
Browse files

- Better partial word checking code. New function search.c:is_whole_word(),...

- Better partial word checking code. New function search.c:is_whole_word(), changes to findnextstr(), and nano.c:do_int_spell_fix() (Rocco Corsi)


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@989 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 45 additions and 30 deletions
+45 -30
...@@ -2,6 +2,9 @@ CVS code - ...@@ -2,6 +2,9 @@ CVS code -
- General - General
- Add Meta-A as alternate keyystroke for ^^ for people with - Add Meta-A as alternate keyystroke for ^^ for people with
non-US keyboards. non-US keyboards.
- Better partial word checking code. New function
search.c:is_whole_word(), changes to findnextstr(),
and nano.c:do_int_spell_fix() (Rocco Corsi).
- nano.c: - nano.c:
usage() usage()
- Remove extra \n in --keypad description (Jordi). - Remove extra \n in --keypad description (Jordi).
......
...@@ -1471,8 +1471,15 @@ int do_int_spell_fix(char *word) ...@@ -1471,8 +1471,15 @@ int do_int_spell_fix(char *word)
edit_update(fileage, TOP); edit_update(fileage, TOP);
while (1) {
/* make sure word is still mis-spelt (i.e. when multi-errors) */ /* make sure word is still mis-spelt (i.e. when multi-errors) */
if (findnextstr(TRUE, FALSE, fileage, beginx_top, prevanswer) != NULL) { if (findnextstr(TRUE, FALSE, fileage, beginx_top, prevanswer) != NULL) {
/* find wholewords only */
if (!is_whole_word(current_x, current, prevanswer))
continue;
do_replace_highlight(TRUE, prevanswer); do_replace_highlight(TRUE, prevanswer);
/* allow replace word to be corrected */ /* allow replace word to be corrected */
...@@ -1493,6 +1500,9 @@ int do_int_spell_fix(char *word) ...@@ -1493,6 +1500,9 @@ int do_int_spell_fix(char *word)
} }
} }
break;
}
/* restore the search/replace strings */ /* restore the search/replace strings */
last_search = mallocstrcpy(last_search, save_search); last_search = mallocstrcpy(last_search, save_search);
last_replace = mallocstrcpy(last_replace, save_replace); last_replace = mallocstrcpy(last_replace, save_replace);
......
...@@ -114,6 +114,7 @@ int check_operating_dir(char *currpath, int allow_tabcomp); ...@@ -114,6 +114,7 @@ int check_operating_dir(char *currpath, int allow_tabcomp);
int do_writeout(char *path, int exiting, int append); int do_writeout(char *path, int exiting, int append);
int do_gotoline(int line, int save_pos); int do_gotoline(int line, int save_pos);
int is_whole_word(int curr_pos, filestruct *fileptr, char *searchword);
int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx, int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx,
int wholewords, int *i); int wholewords, int *i);
int do_find_bracket(void); int do_find_bracket(void);
......
...@@ -226,6 +226,20 @@ void not_found_msg(char *str) ...@@ -226,6 +226,20 @@ void not_found_msg(char *str)
} }
} }
int is_whole_word(int curr_pos, filestruct *fileptr, char *searchword)
{
/* start of line or previous character not a letter */
if ((curr_pos < 1) || (!isalpha((int) fileptr->data[curr_pos-1])))
/* end of line or next character not a letter */
if (((curr_pos + strlen(searchword)) == strlen(fileptr->data))
|| (!isalpha((int) fileptr->data[curr_pos + strlen(searchword)])))
return TRUE;
return FALSE;
}
int past_editbuff; /* search is now looking through lines not displayed */ int past_editbuff; /* search is now looking through lines not displayed */
filestruct *findnextstr(int quiet, int bracket_mode, filestruct * begin, int beginx, filestruct *findnextstr(int quiet, int bracket_mode, filestruct * begin, int beginx,
...@@ -611,21 +625,8 @@ int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx, ...@@ -611,21 +625,8 @@ int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx,
break; break;
/* Make sure only whole words are found */ /* Make sure only whole words are found */
if (wholewords) if ((wholewords) && (!is_whole_word(current_x, fileptr, prevanswer)))
{
/* start of line or previous character not a letter */
if ((current_x == 0) || (!isalpha((int) fileptr->data[current_x-1])))
{
/* end of line or next character not a letter */
if (((current_x + strlen(prevanswer)) == strlen(fileptr->data))
|| (!isalpha((int) fileptr->data[current_x + strlen(prevanswer)])))
;
else
continue; continue;
}
else
continue;
}
/* If we're here, we've found the search string */ /* If we're here, we've found the search string */
if (!replaceall) { if (!replaceall) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment