1 /* <ctype.h> replacement macros.
3 Copyright (C) 2000 Free Software Foundation, Inc.
4 Contributed by Zack Weinberg <zackw@stanford.edu>.
6 This file is part of the libiberty library.
7 Libiberty is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 Libiberty is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with libiberty; see the file COPYING.LIB. If
19 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite
20 Boston, MA 02111-1307, USA.
22 In addition, as a special exception, the Free Software Foundation
23 gives permission to link the code of its release of Wget with the
24 OpenSSL project's "OpenSSL" library (or with modified versions of it
25 that use the same license as the "OpenSSL" library), and distribute
26 the linked executables. You must obey the GNU General Public License
27 in all respects for all of the code used other than "OpenSSL". If you
28 modify this file, you may extend this exception to your version of the
29 file, but you are not obligated to do so. If you do not wish to do
30 so, delete this exception statement from your version. */
32 /* This is a compatible replacement of the standard C library's <ctype.h>
33 with the following properties:
35 - Implements all isxxx() macros required by C99.
36 - Also implements some character classes useful when
37 parsing C-like languages.
38 - Does not change behavior depending on the current locale.
39 - Behaves properly for all values in the range of a signed or
43 #include <safe-ctype.h>
44 #include <stdio.h> /* for EOF */
47 #define bl _sch_isblank
48 #define cn _sch_iscntrl
49 #define di _sch_isdigit
50 #define is _sch_isidst
51 #define lo _sch_islower
52 #define nv _sch_isnvsp
53 #define pn _sch_ispunct
54 #define pr _sch_isprint
55 #define sp _sch_isspace
56 #define up _sch_isupper
58 #define xd _sch_isxdigit
61 #define L lo|is |pr /* lower case letter */
62 #define XL lo|is|xd|pr /* lowercase hex digit */
63 #define U up|is |pr /* upper case letter */
64 #define XU up|is|xd|pr /* uppercase hex digit */
65 #define D di |xd|pr /* decimal digit */
66 #define P pn |pr /* punctuation */
67 #define _ pn|is |pr /* underscore */
69 #define C cn /* control character */
70 #define Z nv |cn /* NUL */
71 #define M nv|sp |cn /* cursor movement: \f \v */
72 #define V vs|sp |cn /* vertical space: \r \n */
73 #define T nv|sp|bl|cn /* tab */
74 #define S nv|sp|bl|pr /* space */
77 #if '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \
78 && 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21 \
81 const unsigned short _sch_istable[256] =
83 Z, C, C, C, C, C, C, C, /* NUL SOH STX ETX EOT ENQ ACK BEL */
84 C, T, V, M, M, V, C, C, /* BS HT LF VT FF CR SO SI */
85 C, C, C, C, C, C, C, C, /* DLE DC1 DC2 DC3 DC4 NAK SYN ETB */
86 C, C, C, C, C, C, C, C, /* CAN EM SUB ESC FS GS RS US */
87 S, P, P, P, P, P, P, P, /* SP ! " # $ % & ' */
88 P, P, P, P, P, P, P, P, /* ( ) * + , - . / */
89 D, D, D, D, D, D, D, D, /* 0 1 2 3 4 5 6 7 */
90 D, D, P, P, P, P, P, P, /* 8 9 : ; < = > ? */
91 P, XU, XU, XU, XU, XU, XU, U, /* @ A B C D E F G */
92 U, U, U, U, U, U, U, U, /* H I J K L M N O */
93 U, U, U, U, U, U, U, U, /* P Q R S T U V W */
94 U, U, U, P, P, P, P, _, /* X Y Z [ \ ] ^ _ */
95 P, XL, XL, XL, XL, XL, XL, L, /* ` a b c d e f g */
96 L, L, L, L, L, L, L, L, /* h i j k l m n o */
97 L, L, L, L, L, L, L, L, /* p q r s t u v w */
98 L, L, L, P, P, P, P, C, /* x y z { | } ~ DEL */
100 /* high half of unsigned char is locale-specific, so all tests are
101 false in "C" locale */
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
104 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
107 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
108 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
113 const unsigned char _sch_tolower[256] =
115 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
116 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
117 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
118 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
121 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
122 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
124 91, 92, 93, 94, 95, 96,
126 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
127 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
131 128,129,130,131, 132,133,134,135, 136,137,138,139, 140,141,142,143,
132 144,145,146,147, 148,149,150,151, 152,153,154,155, 156,157,158,159,
133 160,161,162,163, 164,165,166,167, 168,169,170,171, 172,173,174,175,
134 176,177,178,179, 180,181,182,183, 184,185,186,187, 188,189,190,191,
136 192,193,194,195, 196,197,198,199, 200,201,202,203, 204,205,206,207,
137 208,209,210,211, 212,213,214,215, 216,217,218,219, 220,221,222,223,
138 224,225,226,227, 228,229,230,231, 232,233,234,235, 236,237,238,239,
139 240,241,242,243, 244,245,246,247, 248,249,250,251, 252,253,254,255,
142 const unsigned char _sch_toupper[256] =
144 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
145 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
146 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
147 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
150 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
151 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
153 91, 92, 93, 94, 95, 96,
155 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
156 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
160 128,129,130,131, 132,133,134,135, 136,137,138,139, 140,141,142,143,
161 144,145,146,147, 148,149,150,151, 152,153,154,155, 156,157,158,159,
162 160,161,162,163, 164,165,166,167, 168,169,170,171, 172,173,174,175,
163 176,177,178,179, 180,181,182,183, 184,185,186,187, 188,189,190,191,
165 192,193,194,195, 196,197,198,199, 200,201,202,203, 204,205,206,207,
166 208,209,210,211, 212,213,214,215, 216,217,218,219, 220,221,222,223,
167 224,225,226,227, 228,229,230,231, 232,233,234,235, 236,237,238,239,
168 240,241,242,243, 244,245,246,247, 248,249,250,251, 252,253,254,255,
172 #error "Unsupported host character set"
173 #endif /* not ASCII */