ref: 5d893a21b31bdc2b297d96395c2d61ae8b0ec313
parent: 3487db833c50ea00e069f424ddbc13500b1f4e7a
author: Quentin Rameau <quinq@fifth.space>
date: Sat Feb 18 09:42:42 EST 2017
[libc] Add isblank
--- a/libc/include/ctype.h
+++ b/libc/include/ctype.h
@@ -17,7 +17,7 @@
extern int tolower(int c);
extern int toupper(int c);
-#ifdef __USE_MACROS
+#ifdef __USE_MACROS
#define _U 0x01 /* upper */
#define _L 0x02 /* lower */
@@ -25,13 +25,15 @@
#define _C 0x08 /* cntrl */
#define _P 0x10 /* punct */
#define _S 0x20 /* white space (space/lf/tab) */
-#define _X 0x40 /* hex digit */
+#define _X 0x40 /* hex char */
#define _SP 0x80 /* hard space (0x20) */
+#define _TB 0x100 /* tabulation */
extern unsigned char _ctype[];
#define isalnum(c) (_ctype[(unsigned char) c] & (_U|_L|_D))
#define isalpha(c) (_ctype[(unsigned char) c] & (_U|_L))
+#define isblank(c) (_ctype[(unsigned char) c] & (_SP|_TB))
#define iscntrl(c) (_ctype[(unsigned char) c] & (_C))
#define isdigit(c) (_ctype[(unsigned char) c] & (_D))
#define isgraph(c) (_ctype[(unsigned char) c] & (_P|_U|_L|_D))
@@ -45,6 +47,5 @@
#define isascii(c) (((unsigned) c)<=0x7f)
#endif
-
#endif
--- a/libc/src/Makefile
+++ b/libc/src/Makefile
@@ -4,10 +4,9 @@
LIBCOBJ = assert.o strcpy.o strcmp.o strlen.o strchr.o \
strrchr.o strcat.o strncpy.o strncat.o strcoll.o \
memset.o memcpy.o memmove.o memcmp.o memchr.o \
- isalnum.o isalpha.o isascii.o iscntrl.o isdigit.o isgraph.o \
- islower.o isprint.o ispunct.o isspace.o isupper.o isxdigit.o \
- toupper.o tolower.o \
- setlocale.o
+ isalnum.o isalpha.o isascii.o isblank.o iscntrl.o isdigit.o \
+ isgraph.o islower.o isprint.o ispunct.o isspace.o isupper.o \
+ isxdigit.o toupper.o tolower.o setlocale.o
all: libc.a
--- a/libc/src/ctype.c
+++ b/libc/src/ctype.c
@@ -1,9 +1,8 @@
-
#include <ctype.h>
unsigned char _ctype[255] = {
_C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */
- _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */
+ _C,_C|_S|_TB,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */
_C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */
_C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */
_S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */
--- /dev/null
+++ b/libc/src/isblank.c
@@ -1,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#define __USE_MACROS
+#include <ctype.h>
+#undef isblank
+
+int
+isblank(int c)
+{
+ return _ctype[(unsigned char) c] & (_SP|_TB);
+}