safe-ctype.h revision 78828
1139804Simp/* <ctype.h> replacement macros. 2139804Simp 344574Sphk Copyright (C) 2000, 2001 Free Software Foundation, Inc. 475540Sjhay Contributed by Zack Weinberg <zackw@stanford.edu>. 544574Sphk 644574SphkThis file is part of the libiberty library. 744574SphkLibiberty is free software; you can redistribute it and/or 844574Sphkmodify it under the terms of the GNU Library General Public 944574SphkLicense as published by the Free Software Foundation; either 1044574Sphkversion 2 of the License, or (at your option) any later version. 1144574Sphk 1244574SphkLibiberty is distributed in the hope that it will be useful, 1344574Sphkbut WITHOUT ANY WARRANTY; without even the implied warranty of 1444574SphkMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1544574SphkLibrary General Public License for more details. 1644574Sphk 1744574SphkYou should have received a copy of the GNU Library General Public 1844574SphkLicense along with libiberty; see the file COPYING.LIB. If 192858Swollmannot, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 202858SwollmanBoston, MA 02111-1307, USA. */ 2144574Sphk 2244666Sphk/* This is a compatible replacement of the standard C library's <ctype.h> 232858Swollman with the following properties: 2444574Sphk 2544574Sphk - Implements all isxxx() macros required by C99. 2644574Sphk - Also implements some character classes useful when 2721101Sjhay parsing C-like languages. 2844574Sphk - Does not change behavior depending on the current locale. 2944574Sphk - Behaves properly for all values in the range of a signed or 3044574Sphk unsigned char. 312858Swollman 3232925Seivind To avoid conflicts, this header defines the isxxx functions in upper 33116182Sobrien case, e.g. ISALPHA not isalpha. */ 34116182Sobrien 35116182Sobrien#ifndef SAFE_CTYPE_H 3644666Sphk#define SAFE_CTYPE_H 3744666Sphk 382858Swollman#ifdef isalpha 392858Swollman #error "safe-ctype.h and ctype.h may not be used simultaneously" 4012221Sbde#else 412858Swollman 42164033Srwatson/* Categories. */ 432858Swollman 4482717Sdillonenum { 4582717Sdillon /* In C99 */ 4644574Sphk _sch_isblank = 0x0001, /* space \t */ 472858Swollman _sch_iscntrl = 0x0002, /* nonprinting characters */ 4858377Sphk _sch_isdigit = 0x0004, /* 0-9 */ 4936941Sphk _sch_islower = 0x0008, /* a-z */ 50144445Sjhb _sch_isprint = 0x0010, /* any printing character including ' ' */ 512858Swollman _sch_ispunct = 0x0020, /* all punctuation */ 522858Swollman _sch_isspace = 0x0040, /* space \t \n \r \f \v */ 532858Swollman _sch_isupper = 0x0080, /* A-Z */ 5444574Sphk _sch_isxdigit = 0x0100, /* 0-9A-Fa-f */ 5544574Sphk 56126974Sphk /* Extra categories useful to cpplib. */ 5744574Sphk _sch_isidst = 0x0200, /* A-Za-z_ */ 5844574Sphk _sch_isvsp = 0x0400, /* \n \r */ 59126974Sphk _sch_isnvsp = 0x0800, /* space \t \f \v \0 */ 6044574Sphk 6144574Sphk /* Combinations of the above. */ 6244574Sphk _sch_isalpha = _sch_isupper|_sch_islower, /* A-Za-z */ 6344574Sphk _sch_isalnum = _sch_isalpha|_sch_isdigit, /* A-Za-z0-9 */ 6444574Sphk _sch_isidnum = _sch_isidst|_sch_isdigit, /* A-Za-z0-9_ */ 6544574Sphk _sch_isgraph = _sch_isalnum|_sch_ispunct, /* isprint and not space */ 6644574Sphk _sch_iscppsp = _sch_isvsp|_sch_isnvsp /* isspace + \0 */ 6744574Sphk}; 6844574Sphk 6944574Sphk/* Character classification. */ 7044574Sphkextern const unsigned short _sch_istable[256]; 71126974Sphk 7244574Sphk#define _sch_test(c, bit) (_sch_istable[(c) & 0xff] & (bit)) 7344574Sphk 7444574Sphk#define ISALPHA(c) _sch_test(c, _sch_isalpha) 7544574Sphk#define ISALNUM(c) _sch_test(c, _sch_isalnum) 7632513Sphk#define ISBLANK(c) _sch_test(c, _sch_isblank) 7744574Sphk#define ISCNTRL(c) _sch_test(c, _sch_iscntrl) 7844574Sphk#define ISDIGIT(c) _sch_test(c, _sch_isdigit) 7944574Sphk#define ISGRAPH(c) _sch_test(c, _sch_isgraph) 8044574Sphk#define ISLOWER(c) _sch_test(c, _sch_islower) 8144574Sphk#define ISPRINT(c) _sch_test(c, _sch_isprint) 8244574Sphk#define ISPUNCT(c) _sch_test(c, _sch_ispunct) 8344574Sphk#define ISSPACE(c) _sch_test(c, _sch_isspace) 8444574Sphk#define ISUPPER(c) _sch_test(c, _sch_isupper) 8544574Sphk#define ISXDIGIT(c) _sch_test(c, _sch_isxdigit) 8632513Sphk 8745294Sphk#define ISIDNUM(c) _sch_test(c, _sch_isidnum) 8844574Sphk#define ISIDST(c) _sch_test(c, _sch_isidst) 8944574Sphk#define IS_VSPACE(c) _sch_test(c, _sch_isvsp) 9045294Sphk#define IS_NVSPACE(c) _sch_test(c, _sch_isnvsp) 9145294Sphk#define IS_SPACE_OR_NUL(c) _sch_test(c, _sch_iscppsp) 9245294Sphk 9345294Sphk/* Character transformation. */ 9445294Sphkextern const unsigned char _sch_toupper[256]; 9545294Sphkextern const unsigned char _sch_tolower[256]; 9645294Sphk#define TOUPPER(c) _sch_toupper[(c) & 0xff] 9745294Sphk#define TOLOWER(c) _sch_tolower[(c) & 0xff] 9832513Sphk 9944574Sphk#endif /* no ctype.h */ 10044574Sphk#endif /* SAFE_CTYPE_H */ 10144574Sphk