counting: count words correctly also when --wordchars is used

It should give the same result as 'wc -w' as long as the content
of 'wordchars' does not affect the counting.

This fixes https://savannah.gnu.org/bugs/?58123.

Bug existed since version 2.6.2, since the --wordchars option was
introduced in commit 6f12992c.
master
Benno Schulenberg 2020-04-06 11:04:21 +02:00
parent 845a5973c9
commit 547de4a7bb
1 changed files with 5 additions and 3 deletions

View File

@ -131,15 +131,17 @@ bool is_word_char(const char *c, bool allow_punct)
if (is_alnum_char(c))
return TRUE;
if (allow_punct && is_punct_char(c))
return TRUE;
if (word_chars != NULL && *word_chars != '\0') {
char symbol[MAXCHARLEN + 1];
int symlen = collect_char(c, symbol);
symbol[symlen] = '\0';
return (strstr(word_chars, symbol) != NULL);
}
return (allow_punct && is_punct_char(c));
} else
return FALSE;
}
/* Return the visible representation of control character c. */