ape/ctype.h: add isblank, fix functions (thanks staalmannen)

Our ctype.h mistakenly ommitted isblank. Add it in.

While we're here, the make the 'isfoo()' functions
are broken: they're offsetting into the array, and
don't work with negative character values.

Sync the function bodies with the macros, and make
them produce correct results.
front
Ori Bernstein 2020-08-29 11:09:20 -07:00
parent 74bf624055
commit ec533a1ad8
2 changed files with 16 additions and 11 deletions

View File

@ -8,6 +8,7 @@ extern "C" {
extern int isalnum(int); extern int isalnum(int);
extern int isalpha(int); extern int isalpha(int);
extern int isblank(int);
extern int iscntrl(int); extern int iscntrl(int);
extern int isdigit(int); extern int isdigit(int);
extern int isgraph(int); extern int isgraph(int);
@ -38,6 +39,7 @@ enum
extern unsigned char _ctype[]; extern unsigned char _ctype[];
#define isalnum(c) (_ctype[(unsigned char)(c)]&(_ISupper|_ISlower|_ISdigit)) #define isalnum(c) (_ctype[(unsigned char)(c)]&(_ISupper|_ISlower|_ISdigit))
#define isalpha(c) (_ctype[(unsigned char)(c)]&(_ISupper|_ISlower)) #define isalpha(c) (_ctype[(unsigned char)(c)]&(_ISupper|_ISlower))
#define isblank(c) (_ctype[(unsigned char)(c)]&_ISblank)
#define iscntrl(c) (_ctype[(unsigned char)(c)]&_IScntrl) #define iscntrl(c) (_ctype[(unsigned char)(c)]&_IScntrl)
#define isdigit(c) (_ctype[(unsigned char)(c)]&_ISdigit) #define isdigit(c) (_ctype[(unsigned char)(c)]&_ISdigit)
#define isgraph(c) (_ctype[(unsigned char)(c)]&(_ISpunct|_ISupper|_ISlower|_ISdigit)) #define isgraph(c) (_ctype[(unsigned char)(c)]&(_ISpunct|_ISupper|_ISlower|_ISdigit))

View File

@ -2,6 +2,7 @@
#undef isalnum #undef isalnum
#undef isalpha #undef isalpha
#undef isblank
#undef iscntrl #undef iscntrl
#undef isdigit #undef isdigit
#undef isgraph #undef isgraph
@ -11,14 +12,16 @@
#undef isspace #undef isspace
#undef isupper #undef isupper
#undef isxdigit #undef isxdigit
int isalnum(int c){ return (_ctype+1)[c]&(_ISupper|_ISlower|_ISdigit); }
int isalpha(int c){ return (_ctype+1)[c]&(_ISupper|_ISlower); } int isalnum(int c) {return _ctype[(unsigned char)(c)]&(_ISupper|_ISlower|_ISdigit);}
int iscntrl(int c){ return (_ctype+1)[c]&_IScntrl; } int isalpha(int c) {return _ctype[(unsigned char)(c)]&(_ISupper|_ISlower);}
int isdigit(int c){ return (_ctype+1)[c]&_ISdigit; } int isblank(int c) {return _ctype[(unsigned char)(c)]&_ISblank;}
int isgraph(int c){ return (_ctype+1)[c]&(_ISpunct|_ISupper|_ISlower|_ISdigit); } int iscntrl(int c) {return _ctype[(unsigned char)(c)]&_IScntrl;}
int islower(int c){ return (_ctype+1)[c]&_ISlower; } int isdigit(int c) {return _ctype[(unsigned char)(c)]&_ISdigit;}
int isprint(int c){ return (_ctype+1)[c]&(_ISpunct|_ISupper|_ISlower|_ISdigit|_ISblank); } int isgraph(int c) {return _ctype[(unsigned char)(c)]&(_ISpunct|_ISupper|_ISlower|_ISdigit);}
int ispunct(int c){ return (_ctype+1)[c]&_ISpunct; } int islower(int c) {return _ctype[(unsigned char)(c)]&_ISlower;}
int isspace(int c){ return (_ctype+1)[c]&_ISspace; } int isprint(int c) {return _ctype[(unsigned char)(c)]&(_ISpunct|_ISupper|_ISlower|_ISdigit|_ISblank);}
int isupper(int c){ return (_ctype+1)[c]&_ISupper; } int ispunct(int c) {return _ctype[(unsigned char)(c)]&_ISpunct;}
int isxdigit(int c){ return (_ctype+1)[c]&_ISxdigit; } int isspace(int c) {return _ctype[(unsigned char)(c)]&_ISspace;}
int isupper(int c) {return _ctype[(unsigned char)(c)]&_ISupper;}
int isxdigit(int c) {return _ctype[(unsigned char)(c)]&_ISxdigit;}