commit e221311f2e3cb0838572e3c57aa690532de07dba
parent d26f1ebdf1dbeadb0a2f4f23703caee6e05387ca
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Wed, 15 Jun 2005 03:03:45 +0000
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
Diffstat:
5 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/src/chars.c b/src/chars.c
@@ -126,8 +126,9 @@ bool is_cntrl_mbchar(const char *c)
}
/* Return TRUE for a multibyte character found in a word (currently only
- * an alphanumeric or punctuation character) and FALSE otherwise. */
-bool is_word_mbchar(const char *c)
+ * an alphanumeric or punctuation character, and the latter only if
+ * allow_punct is TRUE) and FALSE otherwise. */
+bool is_word_mbchar(const char *c, bool allow_punct)
{
assert(c != NULL);
@@ -141,10 +142,11 @@ bool is_word_mbchar(const char *c)
wc = (unsigned char)*c;
}
- return iswalnum(wc) || iswpunct(wc);
+ return iswalnum(wc) || (allow_punct ? iswpunct(wc) : FALSE);
} else
#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
@@ -241,7 +243,7 @@ int mb_cur_max(void)
{
return
#ifdef NANO_WIDE
- (!ISSET(NO_UTF8)) ? MB_CUR_MAX :
+ !ISSET(NO_UTF8) ? MB_CUR_MAX :
#endif
1;
}
@@ -560,7 +562,7 @@ const char *mbstrcasestr(const char *haystack, const char *needle)
free(r_mb);
free(q_mb);
- return (found_needle) ? haystack : NULL;
+ return found_needle ? haystack : NULL;
} else
#endif
return strcasestr(haystack, needle);
@@ -670,7 +672,7 @@ const char *mbrevstrcasestr(const char *haystack, const char *needle,
free(r_mb);
free(q_mb);
- return (found_needle) ? rev_start : NULL;
+ return found_needle ? rev_start : NULL;
} else
#endif
return revstrcasestr(haystack, needle, rev_start);
diff --git a/src/nano.c b/src/nano.c
@@ -1460,7 +1460,7 @@ bool do_next_word(bool allow_update)
/* If we've found it, stop moving forward through the current
* line. */
- if (!is_word_mbchar(char_mb))
+ if (!is_word_mbchar(char_mb, TRUE))
break;
/* 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
* current line. */
- if (is_word_mbchar(char_mb))
+ if (is_word_mbchar(char_mb, TRUE))
break;
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
* line. */
- if (!is_word_mbchar(char_mb))
+ if (!is_word_mbchar(char_mb, TRUE))
break;
if (current_x == 0)
@@ -1561,7 +1561,7 @@ void do_prev_word(void)
/* If we've found it, stop moving backward through the
* current line. */
- if (is_word_mbchar(char_mb))
+ if (is_word_mbchar(char_mb, TRUE))
break;
if (current_x == 0)
@@ -1600,7 +1600,7 @@ void do_prev_word(void)
/* If we've found it, stop moving backward through the
* current line. */
- if (!is_word_mbchar(char_mb))
+ if (!is_word_mbchar(char_mb, TRUE))
break;
if (current_x == 0)
diff --git a/src/proto.h b/src/proto.h
@@ -172,7 +172,7 @@ bool is_cntrl_char(int c);
bool is_cntrl_wchar(wint_t wc);
#endif
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);
#ifdef NANO_WIDE
wchar_t control_wrep(wchar_t c);
diff --git a/src/search.c b/src/search.c
@@ -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);
/* 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
- * line or the character after the word isn't a "word" character, we
- * have a whole word. */
- retval = (pos == 0 || !is_word_mbchar(p)) &&
- (word_end == strlen(buf) || !is_word_mbchar(r));
+ * word isn't a non-punctuation "word" character, and if we're at
+ * the end of the line or the character after the word isn't a
+ * non-punctuation "word" character, we have a whole word. */
+ retval = (pos == 0 || !is_word_mbchar(p, FALSE)) &&
+ (word_end == strlen(buf) || !is_word_mbchar(r, FALSE));
free(p);
free(r);
diff --git a/src/winio.c b/src/winio.c
@@ -1917,7 +1917,7 @@ void do_statusbar_next_word(void)
/* If we've found it, stop moving forward through the current
* line. */
- if (!is_word_mbchar(char_mb))
+ if (!is_word_mbchar(char_mb, TRUE))
break;
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
* line. */
- if (is_word_mbchar(char_mb))
+ if (is_word_mbchar(char_mb, TRUE))
break;
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
* line. */
- if (!is_word_mbchar(char_mb))
+ if (!is_word_mbchar(char_mb, TRUE))
break;
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
* line. */
- if (is_word_mbchar(char_mb))
+ if (is_word_mbchar(char_mb, TRUE))
break;
if (statusbar_x == 0)
@@ -2005,7 +2005,7 @@ void do_statusbar_prev_word(void)
/* If we've found it, stop moving backward through the
* current line. */
- if (!is_word_mbchar(char_mb))
+ if (!is_word_mbchar(char_mb, TRUE))
break;
if (statusbar_x == 0)