1 /* c-ctype.h: ASCII-safe versions of the <ctype.h> macros.
3 Copyright 1992 Karl Berry
4 Copyright 2007 TeX Users Group
5 Copyright 2014 Clerk Ma
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 /* Be sure we have `isascii'. */
32 #define ISALNUM(c) (isascii (c) && isalnum(c))
33 #define ISALPHA(c) (isascii (c) && isalpha(c))
34 #define ISASCII isascii
35 #define ISCNTRL(c) (isascii (c) && iscntrl(c))
36 #define ISDIGIT(c) (isascii (c) && isdigit (c))
37 #define ISGRAPH(c) (isascii (c) && isgraph(c))
38 #define ISLOWER(c) (isascii (c) && islower(c))
39 #define ISPRINT(c) (isascii (c) && isprint(c))
40 #define ISPUNCT(c) (isascii (c) && ispunct(c))
41 #define ISSPACE(c) (isascii (c) && isspace(c))
42 #define ISUPPER(c) (isascii (c) && isupper(c))
43 #define ISXDIGIT(c) (isascii (c) && isxdigit(c))
44 #define TOASCII toascii
45 #define TOLOWER(c) (ISUPPER (c) ? tolower (c) : (c))
46 #define TOUPPER(c) (ISLOWER (c) ? toupper (c) : (c))
48 /* This isn't part of the usual <ctype.h>, but it's useful sometimes. */
50 #define isblank(c) ((c) == ' ' || (c) == '\t')
54 /* Here's why this mess is necessary:
56 From: meyering@cs.utexas.edu (Jim Meyering)
57 Date: Wed, 25 Nov 1992 09:52:33 -0600
58 Subject: ss-921123: using isascii with <ctype.h> macros
60 Yesterday some cursory regression testing found that GNU od
61 (in an upcoming release of textutils) generated incorrect output
62 when run on an SGI indigo because isprint ('\377') returned true.
63 Of course, '\377' is not a printing character; the problem lay
64 in using isprint without first making sure its integer argument
65 corresponded to an ascii code.
67 MORAL: always guard uses of ctype macros with isascii if it's available.
68 An obvious alternative is to avoid <ctype.h> and define and use your
69 own versions of the ctype macros.
71 A pretty clean approach to using <ctype.h> and isascii was
72 suggested by David MacKenzie:
78 #define ISDIGIT(c) (isascii (c) && isdigit (c))
79 #define ISPRINT(c) (isascii (c) && isprint (c))
82 then, use ISDIGIT, etc. instead of isdigit, etc. */
84 #endif /* not C_CTYPE_H */