ctype: implement islower/isupper macro

"perf" uses a the forked copy of this file, and wants to use these two macros. Signed-off-by: Namhyung Kim <namhyung.kim@lge.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Namhyung Kim committed Feb 10, 2012 at 11:13 UTC 43ccdf56ec5c92478361a0eb94b91c535fd4d2bd
1 file changed +15
git-compat-util.h
+15
@@ -463,6 +463,8 @@ static inline int has_extension(const char *filename, const char *ext)
463 #undef isdigit
464 #undef isalpha
465 #undef isalnum
466 +#undef islower
467 +#undef isupper
468 #undef tolower
469 #undef toupper
470 extern unsigned char sane_ctype[256];
@@ -478,6 +480,8 @@ extern unsigned char sane_ctype[256];
480 #define isdigit(x) sane_istest(x,GIT_DIGIT)
481 #define isalpha(x) sane_istest(x,GIT_ALPHA)
482 #define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
483 +#define islower(x) sane_iscase(x, 1)
484 +#define isupper(x) sane_iscase(x, 0)
485 #define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)
486 #define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)
487 #define tolower(x) sane_case((unsigned char)(x), 0x20)
@@ -491,6 +495,17 @@ static inline int sane_case(int x, int high)
495 return x;
496 }
497
498 +static inline int sane_iscase(int x, int is_lower)
499 +{
500 + if (!sane_istest(x, GIT_ALPHA))
501 + return 0;
502 +
503 + if (is_lower)
504 + return (x & 0x20) != 0;
505 + else
506 + return (x & 0x20) == 0;
507 +}
508 +
509 static inline int strtoul_ui(char const *s, int base, unsigned int *result)
510 {
511 unsigned long ul;