1 /* c-ctype.h: ASCII-safe versions of the <ctype.h> macros.
3 Copyright 1992, 1994, 2008, 2010, 2011 Karl Berry.
4 Copyright 1998, 2000, 2005 Olaf Weber.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this library; if not, see <http://www.gnu.org/licenses/>. */
19 #ifndef KPATHSEA_C_CTYPE_H
20 #define KPATHSEA_C_CTYPE_H
24 /* Be sure we have `isascii', even if wrong. */
31 #define ISALNUM(c) (isascii (c) && isalnum((unsigned char)c))
32 #define ISALPHA(c) (isascii (c) && isalpha((unsigned char)c))
33 #define ISASCII isascii
34 #define ISCNTRL(c) (isascii (c) && iscntrl((unsigned char)c))
35 #define ISDIGIT(c) (isascii (c) && isdigit ((unsigned char)c))
36 #define ISGRAPH(c) (isascii (c) && isgraph((unsigned char)c))
37 #define ISLOWER(c) (isascii (c) && islower((unsigned char)c))
38 #define ISPRINT(c) (isascii (c) && isprint((unsigned char)c))
39 #define ISPUNCT(c) (isascii (c) && ispunct((unsigned char)c))
40 #define ISSPACE(c) (isascii (c) && isspace((unsigned char)c))
41 #define ISUPPER(c) (isascii (c) && isupper((unsigned char)c))
42 #define ISXDIGIT(c) (isascii (c) && isxdigit((unsigned char)c))
43 #define TOASCII toascii
44 #define TOLOWER(c) (ISUPPER (c) ? tolower ((unsigned char)c) : (c))
45 #define TOUPPER(c) (ISLOWER (c) ? toupper ((unsigned char)c) : (c))
47 /* This isn't part of the usual <ctype.h>, but it's useful sometimes. */
49 #define isblank(c) ((c) == ' ' || (c) == '\t')
52 #define ISBLANK(c) (isascii (c) && isblank ((unsigned char)c))
55 /* Here's why this mess is necessary:
57 From: meyering@cs.utexas.edu (Jim Meyering)
58 Date: Wed, 25 Nov 1992 09:52:33 -0600
59 Subject: ss-921123: using isascii with <ctype.h> macros
61 Yesterday some cursory regression testing found that GNU od
62 (in an upcoming release of textutils) generated incorrect output
63 when run on an SGI indigo because isprint ('\377') returned true.
64 Of course, '\377' is not a printing character; the problem lay
65 in using isprint without first making sure its integer argument
66 corresponded to an ascii code.
68 MORAL: always guard uses of ctype macros with isascii if it's available.
69 An obvious alternative is to avoid <ctype.h> and define and use your
70 own versions of the ctype macros.
72 A pretty clean approach to using <ctype.h> and isascii was
73 suggested by David MacKenzie:
79 #define ISDIGIT(c) (isascii (c) && isdigit (c))
80 #define ISPRINT(c) (isascii (c) && isprint (c))
83 then, use ISDIGIT, etc. instead of isdigit, etc. */
85 #endif /* not KPATHSEA_C_CTYPE_H */