don't count punctuation when searching for a whole word in

is_whole_word()


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2666 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2005-06-15 03:03:45 +00:00
parent d26f1ebdf1
commit e221311f2e
5 changed files with 25 additions and 23 deletions

View File

@ -126,8 +126,9 @@ bool is_cntrl_mbchar(const char *c)
} }
/* Return TRUE for a multibyte character found in a word (currently only /* Return TRUE for a multibyte character found in a word (currently only
* an alphanumeric or punctuation character) and FALSE otherwise. */ * an alphanumeric or punctuation character, and the latter only if
bool is_word_mbchar(const char *c) * allow_punct is TRUE) and FALSE otherwise. */
bool is_word_mbchar(const char *c, bool allow_punct)
{ {
assert(c != NULL); assert(c != NULL);
@ -141,10 +142,11 @@ bool is_word_mbchar(const char *c)
wc = (unsigned char)*c; wc = (unsigned char)*c;
} }
return iswalnum(wc) || iswpunct(wc); return iswalnum(wc) || (allow_punct ? iswpunct(wc) : FALSE);
} else } else
#endif #endif
return isalnum((unsigned char)*c) || ispunct((unsigned char)*c); return isalnum((unsigned char)*c) || (allow_punct ?
ispunct((unsigned char)*c) : FALSE);
} }
/* c is a control character. It displays as ^@, ^?, or ^[ch], where ch /* c is a control character. It displays as ^@, ^?, or ^[ch], where ch
@ -241,7 +243,7 @@ int mb_cur_max(void)
{ {
return return
#ifdef NANO_WIDE #ifdef NANO_WIDE
(!ISSET(NO_UTF8)) ? MB_CUR_MAX : !ISSET(NO_UTF8) ? MB_CUR_MAX :
#endif #endif
1; 1;
} }
@ -560,7 +562,7 @@ const char *mbstrcasestr(const char *haystack, const char *needle)
free(r_mb); free(r_mb);
free(q_mb); free(q_mb);
return (found_needle) ? haystack : NULL; return found_needle ? haystack : NULL;
} else } else
#endif #endif
return strcasestr(haystack, needle); return strcasestr(haystack, needle);
@ -670,7 +672,7 @@ const char *mbrevstrcasestr(const char *haystack, const char *needle,
free(r_mb); free(r_mb);
free(q_mb); free(q_mb);
return (found_needle) ? rev_start : NULL; return found_needle ? rev_start : NULL;
} else } else
#endif #endif
return revstrcasestr(haystack, needle, rev_start); return revstrcasestr(haystack, needle, rev_start);

View File

@ -1460,7 +1460,7 @@ bool do_next_word(bool allow_update)
/* If we've found it, stop moving forward through the current /* If we've found it, stop moving forward through the current
* line. */ * line. */
if (!is_word_mbchar(char_mb)) if (!is_word_mbchar(char_mb, TRUE))
break; break;
/* If we haven't found it, then we've started on a word, so set /* If we haven't found it, then we've started on a word, so set
@ -1481,7 +1481,7 @@ bool do_next_word(bool allow_update)
/* If we've found it, stop moving forward through the /* If we've found it, stop moving forward through the
* current line. */ * current line. */
if (is_word_mbchar(char_mb)) if (is_word_mbchar(char_mb, TRUE))
break; break;
current_x += char_mb_len; current_x += char_mb_len;
@ -1538,7 +1538,7 @@ void do_prev_word(void)
/* If we've found it, stop moving backward through the current /* If we've found it, stop moving backward through the current
* line. */ * line. */
if (!is_word_mbchar(char_mb)) if (!is_word_mbchar(char_mb, TRUE))
break; break;
if (current_x == 0) if (current_x == 0)
@ -1561,7 +1561,7 @@ void do_prev_word(void)
/* If we've found it, stop moving backward through the /* If we've found it, stop moving backward through the
* current line. */ * current line. */
if (is_word_mbchar(char_mb)) if (is_word_mbchar(char_mb, TRUE))
break; break;
if (current_x == 0) if (current_x == 0)
@ -1600,7 +1600,7 @@ void do_prev_word(void)
/* If we've found it, stop moving backward through the /* If we've found it, stop moving backward through the
* current line. */ * current line. */
if (!is_word_mbchar(char_mb)) if (!is_word_mbchar(char_mb, TRUE))
break; break;
if (current_x == 0) if (current_x == 0)

View File

@ -172,7 +172,7 @@ bool is_cntrl_char(int c);
bool is_cntrl_wchar(wint_t wc); bool is_cntrl_wchar(wint_t wc);
#endif #endif
bool is_cntrl_mbchar(const char *c); bool is_cntrl_mbchar(const char *c);
bool is_word_mbchar(const char *c); bool is_word_mbchar(const char *c, bool allow_punct);
char control_rep(char c); char control_rep(char c);
#ifdef NANO_WIDE #ifdef NANO_WIDE
wchar_t control_wrep(wchar_t c); wchar_t control_wrep(wchar_t c);

View File

@ -273,11 +273,11 @@ bool is_whole_word(size_t pos, const char *buf, const char *word)
parse_mbchar(buf + word_end, r, NULL, NULL); parse_mbchar(buf + word_end, r, NULL, NULL);
/* If we're at the beginning of the line or the character before the /* If we're at the beginning of the line or the character before the
* word isn't a "word" character, and if we're at the end of the * word isn't a non-punctuation "word" character, and if we're at
* line or the character after the word isn't a "word" character, we * the end of the line or the character after the word isn't a
* have a whole word. */ * non-punctuation "word" character, we have a whole word. */
retval = (pos == 0 || !is_word_mbchar(p)) && retval = (pos == 0 || !is_word_mbchar(p, FALSE)) &&
(word_end == strlen(buf) || !is_word_mbchar(r)); (word_end == strlen(buf) || !is_word_mbchar(r, FALSE));
free(p); free(p);
free(r); free(r);

View File

@ -1917,7 +1917,7 @@ void do_statusbar_next_word(void)
/* If we've found it, stop moving forward through the current /* If we've found it, stop moving forward through the current
* line. */ * line. */
if (!is_word_mbchar(char_mb)) if (!is_word_mbchar(char_mb, TRUE))
break; break;
statusbar_x += char_mb_len; statusbar_x += char_mb_len;
@ -1933,7 +1933,7 @@ void do_statusbar_next_word(void)
/* If we've found it, stop moving forward through the current /* If we've found it, stop moving forward through the current
* line. */ * line. */
if (is_word_mbchar(char_mb)) if (is_word_mbchar(char_mb, TRUE))
break; break;
statusbar_x += char_mb_len; statusbar_x += char_mb_len;
@ -1960,7 +1960,7 @@ void do_statusbar_prev_word(void)
/* If we've found it, stop moving backward through the current /* If we've found it, stop moving backward through the current
* line. */ * line. */
if (!is_word_mbchar(char_mb)) if (!is_word_mbchar(char_mb, TRUE))
break; break;
if (statusbar_x == 0) if (statusbar_x == 0)
@ -1982,7 +1982,7 @@ void do_statusbar_prev_word(void)
/* If we've found it, stop moving backward through the current /* If we've found it, stop moving backward through the current
* line. */ * line. */
if (is_word_mbchar(char_mb)) if (is_word_mbchar(char_mb, TRUE))
break; break;
if (statusbar_x == 0) if (statusbar_x == 0)
@ -2005,7 +2005,7 @@ void do_statusbar_prev_word(void)
/* If we've found it, stop moving backward through the /* If we've found it, stop moving backward through the
* current line. */ * current line. */
if (!is_word_mbchar(char_mb)) if (!is_word_mbchar(char_mb, TRUE))
break; break;
if (statusbar_x == 0) if (statusbar_x == 0)