diff --git a/ctype.c b/ctype.c index b5d856fd26..af722f957f 100644 --- a/ctype.c +++ b/ctype.c @@ -3,7 +3,7 @@ * * No surprises, and works with signed and unsigned chars. */ -#include "cache.h" +#include "git-compat-util.h" enum { S = GIT_SPACE, diff --git a/git-compat-util.h b/git-compat-util.h index 8f3972cd32..426ae43be9 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -463,6 +463,8 @@ static inline int has_extension(const char *filename, const char *ext) #undef isdigit #undef isalpha #undef isalnum +#undef islower +#undef isupper #undef tolower #undef toupper extern unsigned char sane_ctype[256]; @@ -478,6 +480,8 @@ extern unsigned char sane_ctype[256]; #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 islower(x) sane_iscase(x, 1) +#define isupper(x) sane_iscase(x, 0) #define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL) #define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL) #define tolower(x) sane_case((unsigned char)(x), 0x20) @@ -491,6 +495,17 @@ static inline int sane_case(int x, int high) return x; } +static inline int sane_iscase(int x, int is_lower) +{ + if (!sane_istest(x, GIT_ALPHA)) + return 0; + + if (is_lower) + return (x & 0x20) != 0; + else + return (x & 0x20) == 0; +} + static inline int strtoul_ui(char const *s, int base, unsigned int *result) { unsigned long ul;