Change NUL char handling of isspecial()

Replace isspecial() by the new macro is_glob_special(), which is more,
well, specialized.  The former included the NUL char in its character
class, while the letter only included characters that are special to
file name globbing.

The new name contains underscores because they enhance readability
considerably now that it's made up of three words.  Renaming the
function is necessary to document its changed scope.

The call sites of isspecial() are updated to check explicitly for NUL.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
René Scharfe 2009-01-17 16:50:34 +01:00 committed by Junio C Hamano
parent c841aa8b90
commit 8cc3299262
5 changed files with 15 additions and 8 deletions

View file

@ -9,11 +9,11 @@ enum {
S = GIT_SPACE,
A = GIT_ALPHA,
D = GIT_DIGIT,
G = GIT_SPECIAL, /* \0, *, ?, [, \\ */
G = GIT_GLOB_SPECIAL, /* *, ?, [, \\ */
};
unsigned char sane_ctype[256] = {
G, 0, 0, 0, 0, 0, 0, 0, 0, S, S, 0, 0, S, 0, 0, /* 0.. 15 */
0, 0, 0, 0, 0, 0, 0, 0, 0, S, S, 0, 0, S, 0, 0, /* 0.. 15 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 16.. 31 */
S, 0, 0, 0, 0, 0, 0, 0, 0, 0, G, 0, 0, 0, 0, 0, /* 32.. 47 */
D, D, D, D, D, D, D, D, D, D, 0, 0, 0, 0, 0, G, /* 48.. 63 */

4
dir.c
View file

@ -75,7 +75,7 @@ static int match_one(const char *match, const char *name, int namelen)
for (;;) {
unsigned char c1 = *match;
unsigned char c2 = *name;
if (isspecial(c1))
if (c1 == '\0' || is_glob_special(c1))
break;
if (c1 != c2)
return 0;
@ -680,7 +680,7 @@ static int simple_length(const char *match)
for (;;) {
unsigned char c = *match++;
len++;
if (isspecial(c))
if (c == '\0' || is_glob_special(c))
return len;
}
}

View file

@ -327,13 +327,13 @@ extern unsigned char sane_ctype[256];
#define GIT_SPACE 0x01
#define GIT_DIGIT 0x02
#define GIT_ALPHA 0x04
#define GIT_SPECIAL 0x08
#define GIT_GLOB_SPECIAL 0x08
#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
#define isspace(x) sane_istest(x,GIT_SPACE)
#define isdigit(x) sane_istest(x,GIT_DIGIT)
#define isalpha(x) sane_istest(x,GIT_ALPHA)
#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
#define isspecial(x) sane_istest(x,GIT_SPECIAL)
#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)
#define tolower(x) sane_case((unsigned char)(x), 0x20)
#define toupper(x) sane_case((unsigned char)(x), 0)

5
grep.c
View file

@ -30,8 +30,9 @@ void append_grep_pattern(struct grep_opt *opt, const char *pat,
static int isregexspecial(int c)
{
return isspecial(c) || c == '$' || c == '(' || c == ')' || c == '+' ||
c == '.' || c == '^' || c == '{' || c == '|';
return c == '\0' || is_glob_special(c) ||
c == '$' || c == '(' || c == ')' || c == '+' ||
c == '.' || c == '^' || c == '{' || c == '|';
}
static int is_fixed(const char *s)

View file

@ -21,6 +21,11 @@ static int test_isalnum(int c)
return isalnum(c);
}
static int test_is_glob_special(int c)
{
return is_glob_special(c);
}
#define DIGIT "0123456789"
#define LOWER "abcdefghijklmnopqrstuvwxyz"
#define UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@ -34,6 +39,7 @@ static const struct ctype_class {
{ "isspace", test_isspace, " \n\r\t" },
{ "isalpha", test_isalpha, LOWER UPPER },
{ "isalnum", test_isalnum, LOWER UPPER DIGIT },
{ "is_glob_special", test_is_glob_special, "*?[\\" },
{ NULL }
};