ctype: test and fix character class functions (DONE)

This commit is contained in:
Lephenixnoir 2021-05-18 11:37:37 +02:00
parent d70a2c671c
commit 50629bf479
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
3 changed files with 9 additions and 8 deletions

2
STATUS
View File

@ -31,7 +31,7 @@ DONE: Function/symbol/macro is defined, builds, links, and is tested
TODO: Check standard compliance
7.4 <ctype.h>
7.4.1 is*: TEST
7.4.1 is*: DONE
7.4.2 to*: TEST
7.5 <errno.h>

View File

@ -4,8 +4,9 @@
/*
** Character classification functions. These are all implemented as sets of
** comparisons. There is an approach with a 128-byte table, but it takes more
** space; every function but isalnum, ispunct and isxdigit needs less code to
** compare than lookup, and using just one won't pull the whole table.
** space; in fact, every function but isalnum, ispunct and isxdigit needs less
** code to compare than to perform the lookup. Additionally, users won't need
** the whole table for a single call to isspace().
*/
extern int isalnum(int c);
extern int isalpha(int c);
@ -31,8 +32,8 @@ extern int toupper(int c);
*/
#define isalnum(c) ({ \
int __c = (c); \
isalpha(c) || isdigit(c); \
int __c0 = (c); \
isalpha(__c0) || isdigit(__c0); \
})
#define isalpha(c) ({ \
@ -67,7 +68,7 @@ extern int toupper(int c);
#define isprint(c) ({ \
int __c = (c); \
(__c >= 32) || (__c < 0x7f); \
(__c >= 32) && (__c < 0x7f); \
})
#define ispunct(c) ({ \
@ -89,7 +90,7 @@ extern int toupper(int c);
#define isxdigit(c) ({ \
int __c = (c); \
int __c20 = __c | 0x20; \
(__c >= '0' && __c <= '9') || (__c20 >= 'a' && __c20 <= 'z'); \
(__c >= '0' && __c <= '9') || (__c20 >= 'a' && __c20 <= 'f'); \
})
#define tolower(c) ({ \

View File

@ -4,5 +4,5 @@
int isxdigit(int c)
{
int c20 = c | 0x20;
return (c >= '0' && c <= '9') || (c20 >= 'a' && c20 <= 'z');
return (c >= '0' && c <= '9') || (c20 >= 'a' && c20 <= 'f');
}