diff options
author | Linus Torvalds <torvalds@osdl.org> | 2005-10-13 11:03:18 -0700 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2005-10-14 17:17:27 -0700 |
commit | 4546738b58a0134eef154231b07d60fc174d56e3 (patch) | |
tree | 873d8e5652c06c3891278f33546c437efc209c2d /cache.h | |
parent | d402d5566fdf226697a386dfb9858e5d954e9b91 (diff) | |
download | git-4546738b58a0134eef154231b07d60fc174d56e3.tar.gz git-4546738b58a0134eef154231b07d60fc174d56e3.tar.xz |
Unlocalized isspace and friends
Do our own ctype.h, just to get the sane semantics: we want
locale-independence, _and_ we want the right signed behaviour. Plus we
only use a very small subset of ctype.h anyway (isspace, isalpha,
isdigit and isalnum).
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'cache.h')
-rw-r--r-- | cache.h | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -387,4 +387,30 @@ extern int git_config_bool(const char *, const char *); extern char git_default_email[MAX_GITNAME]; extern char git_default_name[MAX_GITNAME]; +/* Sane ctype - no locale, and works with signed chars */ +#undef isspace +#undef isdigit +#undef isalpha +#undef isalnum +#undef tolower +#undef toupper +extern unsigned char sane_ctype[256]; +#define GIT_SPACE 0x01 +#define GIT_DIGIT 0x02 +#define GIT_ALPHA 0x04 +#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 tolower(x) sane_case((unsigned char)(x), 0x20) +#define toupper(x) sane_case((unsigned char)(x), 0) + +static inline int sane_case(int x, int high) +{ + if (sane_istest(x, GIT_ALPHA)) + x = (x & ~0x20) | high; + return x; +} + #endif /* CACHE_H */ |