diff options
author | Colin Watson <cjwatson@debian.org> | 2019-02-05 00:37:38 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2019-02-05 00:37:38 +0000 |
commit | 1bd019e2bb9507e732dafe3a68c9d59f68c0dd3f (patch) | |
tree | c87e9d26c9b4f165155c00ef93295ed4ea393d59 | |
parent | 152829db94835384ebd0f84ddaea9e0c3fa4b271 (diff) |
Simplify case-insensitivity in word_fnmatch
Using FNM_CASEFOLD saves us from having to lower-case the pattern
manually, and it also fixes the behaviour of "apropos -w" when given a
non-lower-case pattern.
* lib/wordfnmatch.c (word_fnmatch): Use isalpha and FNM_CASEFOLD rather
than manually lower-casing string or expecting pattern to have already
been lower-cased.
* NEWS: Document this.
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | lib/wordfnmatch.c | 18 |
2 files changed, 11 insertions, 9 deletions
@@ -21,6 +21,8 @@ Major changes since man-db 2.8.5: * Fix failure to link libman using the Darwin linker. + * "apropos -w" now works when given a non-lower-case pattern. + man-db 2.8.5 (5 January 2019) ============================= diff --git a/lib/wordfnmatch.c b/lib/wordfnmatch.c index 73fad8e1..613035b2 100644 --- a/lib/wordfnmatch.c +++ b/lib/wordfnmatch.c @@ -32,19 +32,19 @@ #include "manconfig.h" -#include "lower.h" #include "wordfnmatch.h" /* TODO: How on earth do we allow multiple-word matches without * reimplementing fnmatch()? */ -bool word_fnmatch (const char *lowpattern, const char *string) +bool word_fnmatch (const char *pattern, const char *string) { - char *lowstring = lower (string); - char *begin = lowstring, *p; + char *dupstring = xstrdup (string); + const char *begin = dupstring; + char *p; - for (p = lowstring; *p; p++) { - if (CTYPE (islower, *p) || *p == '_') + for (p = dupstring; *p; p++) { + if (CTYPE (isalpha, *p) || *p == '_') continue; /* Check for multiple non-word characters in a row. */ @@ -52,14 +52,14 @@ bool word_fnmatch (const char *lowpattern, const char *string) begin++; else { *p = '\0'; - if (fnmatch (lowpattern, begin, 0) == 0) { - free (lowstring); + if (fnmatch (pattern, begin, FNM_CASEFOLD) == 0) { + free (dupstring); return true; } begin = p + 1; } } - free (lowstring); + free (dupstring); return false; } |