Imported Upstream version 7.59.0
[platform/upstream/curl.git] / lib / curl_ctype.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2018, 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.haxx.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 #undef _U
26 #define _U (1<<0) /* upper case */
27 #undef _L
28 #define _L (1<<1) /* lower case */
29 #undef _N
30 #define _N (1<<2) /* decimal numerical digit */
31 #undef _S
32 #define _S (1<<3) /* space */
33 #undef _P
34 #define _P (1<<4) /* punctuation */
35 #undef _C
36 #define _C (1<<5) /* control */
37 #undef _X
38 #define _X (1<<6) /* hexadecimal letter */
39 #undef _B
40 #define _B (1<<7) /* blank */
41
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
59 };
60
61 int Curl_isspace(int c)
62 {
63   if((c < 0) || (c >= 0x80))
64     return FALSE;
65   return (ascii[c] & _S);
66 }
67
68 int Curl_isdigit(int c)
69 {
70   if((c < 0) || (c >= 0x80))
71     return FALSE;
72   return (ascii[c] & _N);
73 }
74
75 int Curl_isalnum(int c)
76 {
77   if((c < 0) || (c >= 0x80))
78     return FALSE;
79   return (ascii[c] & (_N|_U|_L));
80 }
81
82 int Curl_isxdigit(int c)
83 {
84   if((c < 0) || (c >= 0x80))
85     return FALSE;
86   return (ascii[c] & (_N|_X));
87 }
88
89 int Curl_isgraph(int c)
90 {
91   if((c < 0) || (c >= 0x80) || (c == ' '))
92     return FALSE;
93   return (ascii[c] & (_N|_X|_U|_L|_P|_S));
94 }
95
96 int Curl_isprint(int c)
97 {
98   if((c < 0) || (c >= 0x80))
99     return FALSE;
100   return (ascii[c] & (_N|_X|_U|_L|_P|_S));
101 }
102
103 int Curl_isalpha(int c)
104 {
105   if((c < 0) || (c >= 0x80))
106     return FALSE;
107   return (ascii[c] & (_U|_L));
108 }
109
110 int Curl_isupper(int c)
111 {
112   if((c < 0) || (c >= 0x80))
113     return FALSE;
114   return (ascii[c] & (_U));
115 }
116
117 int Curl_islower(int c)
118 {
119   if((c < 0) || (c >= 0x80))
120     return FALSE;
121   return (ascii[c] & (_L));
122 }