diff --git a/src/chars.c b/src/chars.c index 01c89310fd12724fec71b928377f832f3db405b5..7d1a19f3daf7922e41caf7567bb25277e1cd0a01 100644 --- 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 index 3f90ea89e75cb776386e71b533da1ad8018577a6..c8cdc077d5b33e8f0d874fe30f1ceedf6051236c 100644 --- 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 index fdbaf8e2413dd9135ae69f8c6cbaba4fc653b16e..527fb1b906fccf94a7a567ba3e52273019ad1a3f 100644 --- 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 index 07aa492f583b4bb99c68d5c465ecda94cf84c890..9019c57011f6ada02000db0bc3d004933eeae16a 100644 --- 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 index 3c42333bdd7c8bc184c3132bc6937027cd8db06e..aff5fe04775127a47585c5987a132215cf36f322 100644 --- 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)