1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
23 #include "curl_setup.h"
26 #define _U (1<<0) /* upper case */
28 #define _L (1<<1) /* lower case */
30 #define _N (1<<2) /* decimal numerical digit */
32 #define _S (1<<3) /* space */
34 #define _P (1<<4) /* punctuation */
36 #define _C (1<<5) /* control */
38 #define _X (1<<6) /* hexadecimal letter */
40 #define _B (1<<7) /* blank */
42 static const unsigned char ascii[128] = {
43 _C, _C, _C, _C, _C, _C, _C, _C,
44 _C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C,
45 _C, _C, _C, _C, _C, _C, _C, _C,
46 _C, _C, _C, _C, _C, _C, _C, _C,
47 _S|_B, _P, _P, _P, _P, _P, _P, _P,
48 _P, _P, _P, _P, _P, _P, _P, _P,
49 _N, _N, _N, _N, _N, _N, _N, _N,
50 _N, _N, _P, _P, _P, _P, _P, _P,
51 _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U,
52 _U, _U, _U, _U, _U, _U, _U, _U,
53 _U, _U, _U, _U, _U, _U, _U, _U,
54 _U, _U, _U, _P, _P, _P, _P, _P,
55 _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L,
56 _L, _L, _L, _L, _L, _L, _L, _L,
57 _L, _L, _L, _L, _L, _L, _L, _L,
58 _L, _L, _L, _P, _P, _P, _P, _C
61 int Curl_isspace(int c)
63 if((c < 0) || (c >= 0x80))
65 return (ascii[c] & _S);
68 int Curl_isdigit(int c)
70 if((c < 0) || (c >= 0x80))
72 return (ascii[c] & _N);
75 int Curl_isalnum(int c)
77 if((c < 0) || (c >= 0x80))
79 return (ascii[c] & (_N|_U|_L));
82 int Curl_isxdigit(int c)
84 if((c < 0) || (c >= 0x80))
86 return (ascii[c] & (_N|_X));
89 int Curl_isgraph(int c)
91 if((c < 0) || (c >= 0x80) || (c == ' '))
93 return (ascii[c] & (_N|_X|_U|_L|_P|_S));
96 int Curl_isprint(int c)
98 if((c < 0) || (c >= 0x80))
100 return (ascii[c] & (_N|_X|_U|_L|_P|_S));
103 int Curl_isalpha(int c)
105 if((c < 0) || (c >= 0x80))
107 return (ascii[c] & (_U|_L));
110 int Curl_isupper(int c)
112 if((c < 0) || (c >= 0x80))
114 return (ascii[c] & (_U));
117 int Curl_islower(int c)
119 if((c < 0) || (c >= 0x80))
121 return (ascii[c] & (_L));