From 50629bf4792a5ebdbf0511a70503059542b4b733 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Tue, 18 May 2021 11:37:37 +0200 Subject: [PATCH] ctype: test and fix character class functions (DONE) --- STATUS | 2 +- include/ctype.h | 13 +++++++------ src/libc/ctype/isxdigit.c | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/STATUS b/STATUS index a45fad4..b9e6796 100644 --- a/STATUS +++ b/STATUS @@ -31,7 +31,7 @@ DONE: Function/symbol/macro is defined, builds, links, and is tested TODO: Check standard compliance 7.4 - 7.4.1 is*: TEST + 7.4.1 is*: DONE 7.4.2 to*: TEST 7.5 diff --git a/include/ctype.h b/include/ctype.h index 69b73e7..e250f24 100644 --- a/include/ctype.h +++ b/include/ctype.h @@ -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) ({ \ diff --git a/src/libc/ctype/isxdigit.c b/src/libc/ctype/isxdigit.c index 1b0cc47..1002540 100644 --- a/src/libc/ctype/isxdigit.c +++ b/src/libc/ctype/isxdigit.c @@ -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'); }