1 | /*************************************************************************** |
2 | * _ _ ____ _ |
3 | * Project ___| | | | _ \| | |
4 | * / __| | | | |_) | | |
5 | * | (__| |_| | _ <| |___ |
6 | * \___|\___/|_| \_\_____| |
7 | * |
8 | * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. |
9 | * |
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.se/docs/copyright.html. |
13 | * |
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. |
17 | * |
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
19 | * KIND, either express or implied. |
20 | * |
21 | ***************************************************************************/ |
22 | |
23 | #include "curl_setup.h" |
24 | |
25 | #ifndef CURL_DOES_CONVERSIONS |
26 | |
27 | #undef _U |
28 | #define _U (1<<0) /* upper case */ |
29 | #undef _L |
30 | #define _L (1<<1) /* lower case */ |
31 | #undef _N |
32 | #define _N (1<<2) /* decimal numerical digit */ |
33 | #undef _S |
34 | #define _S (1<<3) /* space */ |
35 | #undef _P |
36 | #define _P (1<<4) /* punctuation */ |
37 | #undef _C |
38 | #define _C (1<<5) /* control */ |
39 | #undef _X |
40 | #define _X (1<<6) /* hexadecimal letter */ |
41 | #undef _B |
42 | #define _B (1<<7) /* blank */ |
43 | |
44 | static const unsigned char ascii[128] = { |
45 | _C, _C, _C, _C, _C, _C, _C, _C, |
46 | _C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C, |
47 | _C, _C, _C, _C, _C, _C, _C, _C, |
48 | _C, _C, _C, _C, _C, _C, _C, _C, |
49 | _S|_B, _P, _P, _P, _P, _P, _P, _P, |
50 | _P, _P, _P, _P, _P, _P, _P, _P, |
51 | _N, _N, _N, _N, _N, _N, _N, _N, |
52 | _N, _N, _P, _P, _P, _P, _P, _P, |
53 | _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, |
54 | _U, _U, _U, _U, _U, _U, _U, _U, |
55 | _U, _U, _U, _U, _U, _U, _U, _U, |
56 | _U, _U, _U, _P, _P, _P, _P, _P, |
57 | _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, |
58 | _L, _L, _L, _L, _L, _L, _L, _L, |
59 | _L, _L, _L, _L, _L, _L, _L, _L, |
60 | _L, _L, _L, _P, _P, _P, _P, _C |
61 | }; |
62 | |
63 | int Curl_isspace(int c) |
64 | { |
65 | if((c < 0) || (c >= 0x80)) |
66 | return FALSE; |
67 | return (ascii[c] & _S); |
68 | } |
69 | |
70 | int Curl_isdigit(int c) |
71 | { |
72 | if((c < 0) || (c >= 0x80)) |
73 | return FALSE; |
74 | return (ascii[c] & _N); |
75 | } |
76 | |
77 | int Curl_isalnum(int c) |
78 | { |
79 | if((c < 0) || (c >= 0x80)) |
80 | return FALSE; |
81 | return (ascii[c] & (_N|_U|_L)); |
82 | } |
83 | |
84 | int Curl_isxdigit(int c) |
85 | { |
86 | if((c < 0) || (c >= 0x80)) |
87 | return FALSE; |
88 | return (ascii[c] & (_N|_X)); |
89 | } |
90 | |
91 | int Curl_isgraph(int c) |
92 | { |
93 | if((c < 0) || (c >= 0x80) || (c == ' ')) |
94 | return FALSE; |
95 | return (ascii[c] & (_N|_X|_U|_L|_P|_S)); |
96 | } |
97 | |
98 | int Curl_isprint(int c) |
99 | { |
100 | if((c < 0) || (c >= 0x80)) |
101 | return FALSE; |
102 | return (ascii[c] & (_N|_X|_U|_L|_P|_S)); |
103 | } |
104 | |
105 | int Curl_isalpha(int c) |
106 | { |
107 | if((c < 0) || (c >= 0x80)) |
108 | return FALSE; |
109 | return (ascii[c] & (_U|_L)); |
110 | } |
111 | |
112 | int Curl_isupper(int c) |
113 | { |
114 | if((c < 0) || (c >= 0x80)) |
115 | return FALSE; |
116 | return (ascii[c] & (_U)); |
117 | } |
118 | |
119 | int Curl_islower(int c) |
120 | { |
121 | if((c < 0) || (c >= 0x80)) |
122 | return FALSE; |
123 | return (ascii[c] & (_L)); |
124 | } |
125 | |
126 | int Curl_iscntrl(int c) |
127 | { |
128 | if((c < 0) || (c >= 0x80)) |
129 | return FALSE; |
130 | return (ascii[c] & (_C)); |
131 | } |
132 | |
133 | #endif /* !CURL_DOES_CONVERSIONS */ |
134 | |