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>
This commit is contained in:

committed by
Junio C Hamano

parent
d402d5566f
commit
4546738b58
26
cache.h
26
cache.h
@ -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 */
|
||||
|
Reference in New Issue
Block a user