Commit e1c16b37 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

add multibyte character support to is_whole_word(), plus a comment fix

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2318 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 31 additions and 19 deletions
+31 -19
...@@ -111,13 +111,13 @@ CVS code - ...@@ -111,13 +111,13 @@ CVS code -
chars.c), move_right() (renamed move_mbright() and moved to chars.c), move_right() (renamed move_mbright() and moved to
chars.c), do_home(), do_verbatim_input(), do_delete(), chars.c), do_home(), do_verbatim_input(), do_delete(),
do_tab(), do_enter(), indent_length(), do_next_word(), do_tab(), do_enter(), indent_length(), do_next_word(),
do_prev_word(), do_input(), do_output(), strstrwrapper(), do_prev_word(), do_input(), do_output(), is_whole_word(),
get_buffer(), unget_input(), unget_kbinput(), get_input(), strstrwrapper(), get_buffer(), unget_input(), unget_kbinput(),
parse_kbinput(), unparse_kbinput(), parse_verbatim_kbinput(), get_input(), parse_kbinput(), unparse_kbinput(),
do_statusbar_input(), do_statusbar_home(), parse_verbatim_kbinput(), do_statusbar_input(),
do_statusbar_verbatim_kbinput(), do_statusbar_output(), and do_statusbar_home(), do_statusbar_verbatim_kbinput(),
display_string(); removal of buffer_to_keys() and do_statusbar_output(), and display_string(); removal of
keys_to_buffer(). (DLR) buffer_to_keys() and keys_to_buffer(). (DLR)
- Add -O/--morespace command line option, plus a corresponding - Add -O/--morespace command line option, plus a corresponding
Meta-O toggle and a "morespace" rcfile option. When these are Meta-O toggle and a "morespace" rcfile option. When these are
used, the normally-unused blank line below the titlebar will used, the normally-unused blank line below the titlebar will
......
...@@ -483,8 +483,7 @@ void not_found_msg(const char *str); ...@@ -483,8 +483,7 @@ void not_found_msg(const char *str);
void search_abort(void); void search_abort(void);
void search_init_globals(void); void search_init_globals(void);
int search_init(bool replacing, bool use_answer); int search_init(bool replacing, bool use_answer);
bool is_whole_word(int curr_pos, const char *datastr, const char bool is_whole_word(size_t pos, const char *buf, const char *word);
*searchword);
bool findnextstr(bool can_display_wrap, bool wholeword, bool bool findnextstr(bool can_display_wrap, bool wholeword, bool
no_sameline, const filestruct *begin, size_t beginx, const char no_sameline, const filestruct *begin, size_t beginx, const char
*needle, size_t *needle_len); *needle, size_t *needle_len);
......
...@@ -265,20 +265,33 @@ int search_init(bool replacing, bool use_answer) ...@@ -265,20 +265,33 @@ int search_init(bool replacing, bool use_answer)
return 0; return 0;
} }
bool is_whole_word(int curr_pos, const char *datastr, const char bool is_whole_word(size_t pos, const char *buf, const char *word)
*searchword)
{ {
size_t sln = curr_pos + strlen(searchword); char *p = charalloc(mb_cur_max()), *r = charalloc(mb_cur_max());
size_t word_end = pos + strlen(word);
bool retval;
/* Start of line or previous character is not a letter and end of assert(buf != NULL && pos <= strlen(buf) && word != NULL);
* line or next character is not a letter. */
return (curr_pos < 1 || !isalpha(datastr[curr_pos - 1])) && parse_mbchar(buf + move_mbleft(buf, pos), p, NULL, NULL);
(sln == strlen(datastr) || !isalpha(datastr[sln])); parse_mbchar(buf + word_end, r, NULL, NULL);
/* If we're at the beginning of the line or the character before the
* word isn't an alphanumeric character, and if we're at the end of
* the line or the character after the word isn't an alphanumeric
* character, we have a whole word. */
retval = (pos < 1 || !is_alnum_mbchar(p)) &&
(word_end == strlen(buf) || !is_alnum_mbchar(r));
free(p);
free(r);
return retval;
} }
/* Look for needle, starting at current, column current_x. If /* Look for needle, starting at (current, current_x). If no_sameline is
* no_sameline is TRUE, skip over begin when looking for needle. begin * TRUE, skip over begin when looking for needle. begin is the line
* is the line where we first started searching, at column beginx. If * where we first started searching, at column beginx. If
* can_display_wrap is TRUE, we put messages on the statusbar, wrap * can_display_wrap is TRUE, we put messages on the statusbar, wrap
* around the file boundaries. The return value specifies whether we * around the file boundaries. The return value specifies whether we
* found anything. If we did, set needle_len to the length of the * found anything. If we did, set needle_len to the length of the
......
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