From 13fde991bd7a76c6d5936fecade665632116a0d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 6 Jul 2004 00:29:52 +0000 Subject: [PATCH] Added BeOS compatible ctype.h. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8331 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/posix/ctype.h | 47 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/headers/posix/ctype.h b/headers/posix/ctype.h index 0d12f1a3d7..3407151b81 100644 --- a/headers/posix/ctype.h +++ b/headers/posix/ctype.h @@ -1,5 +1,8 @@ #ifndef _CTYPE_H #define _CTYPE_H +/* +** Distributed under the terms of the OpenBeOS License. +*/ #ifdef __cplusplus extern "C" { @@ -22,8 +25,48 @@ int toascii(int); int tolower(int); int toupper(int); -#define _toupper(ch) ((int) (((int)ch) - 'a' + 'A')) -#define _tolower(ch) ((int) (((int)ch) - 'A' + 'a')) +enum { + _ISblank = 0x0001, /* blank */ + _IScntrl = 0x0002, /* control */ + _ISpunct = 0x0004, /* punctuation */ + _ISalnum = 0x0008, /* alpha-numeric */ + _ISupper = 0x0100, /* uppercase */ + _ISlower = 0x0200, /* lowercase */ + _ISalpha = 0x0400, /* alphabetic */ + _ISdigit = 0x0800, /* digit */ + _ISxdigit = 0x1000, /* hexadecimal digit */ + _ISspace = 0x2000, /* white space */ + _ISprint = 0x4000, /* printing */ + _ISgraph = 0x8000, /* graphical */ +}; + +/* Characteristics */ +extern const unsigned short int *__ctype_b; +/* Case conversions */ +extern const int *__ctype_tolower; +extern const int *__ctype_toupper; + +#define __isctype(c, type) \ + (__ctype_b[(int)(c)] & (unsigned short int)type) + +#define isascii(c) (((c) & ~0x7f) == 0) /* ASCII characters have bit 8 cleared */ +#define toascii(c) ((c) & 0x7f) /* Clear higher bits */ + +#define tolower(c) ((int)__ctype_tolower[(int)(c)]) +#define toupper(c) ((int)__ctype_toupper[(int)(c)]) + +#define isalnum(c) __isctype((c), _ISalnum) +#define isalpha(c) __isctype((c), _ISalpha) +#define isblank(c) __isctype((c), _ISblank) +#define iscntrl(c) __isctype((c), _IScntrl) +#define isdigit(c) __isctype((c), _ISdigit) +#define islower(c) __isctype((c), _ISlower) +#define isgraph(c) __isctype((c), _ISgraph) +#define isprint(c) __isctype((c), _ISprint) +#define ispunct(c) __isctype((c), _ISpunct) +#define isspace(c) __isctype((c), _ISspace) +#define isupper(c) __isctype((c), _ISupper) +#define isxdigit(c) __isctype((c), _ISxdigit) #ifdef __cplusplus }