1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 5 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2009 The PHP Group |
6 : +----------------------------------------------------------------------+
7 : | This source file is subject to version 3.01 of the PHP license, |
8 : | that is bundled with this package in the file LICENSE, and is |
9 : | available through the world-wide-web at the following url: |
10 : | http://www.php.net/license/3_01.txt |
11 : | If you did not receive a copy of the PHP license and are unable to |
12 : | obtain it through the world-wide-web, please send a note to |
13 : | license@php.net so we can mail you a copy immediately. |
14 : +----------------------------------------------------------------------+
15 : | Author: Hartmut Holzgraefe <hholzgra@php.net> |
16 : +----------------------------------------------------------------------+
17 : */
18 :
19 : #ifdef HAVE_CONFIG_H
20 : #include "config.h"
21 : #endif
22 :
23 : #include "php.h"
24 : #include "php_ini.h"
25 : #include "php_ctype.h"
26 : #include "SAPI.h"
27 : #include "ext/standard/info.h"
28 :
29 : #include <ctype.h>
30 :
31 : #if HAVE_CTYPE
32 :
33 : static PHP_MINFO_FUNCTION(ctype);
34 :
35 : static PHP_FUNCTION(ctype_alnum);
36 : static PHP_FUNCTION(ctype_alpha);
37 : static PHP_FUNCTION(ctype_cntrl);
38 : static PHP_FUNCTION(ctype_digit);
39 : static PHP_FUNCTION(ctype_lower);
40 : static PHP_FUNCTION(ctype_graph);
41 : static PHP_FUNCTION(ctype_print);
42 : static PHP_FUNCTION(ctype_punct);
43 : static PHP_FUNCTION(ctype_space);
44 : static PHP_FUNCTION(ctype_upper);
45 : static PHP_FUNCTION(ctype_xdigit);
46 :
47 : /* {{{ arginfo */
48 : static
49 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_alnum, 0)
50 : ZEND_ARG_INFO(0, text)
51 : ZEND_END_ARG_INFO()
52 :
53 : static
54 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_alpha, 0)
55 : ZEND_ARG_INFO(0, text)
56 : ZEND_END_ARG_INFO()
57 :
58 : static
59 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_cntrl, 0)
60 : ZEND_ARG_INFO(0, text)
61 : ZEND_END_ARG_INFO()
62 :
63 : static
64 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_digit, 0)
65 : ZEND_ARG_INFO(0, text)
66 : ZEND_END_ARG_INFO()
67 :
68 : static
69 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_lower, 0)
70 : ZEND_ARG_INFO(0, text)
71 : ZEND_END_ARG_INFO()
72 :
73 : static
74 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_graph, 0)
75 : ZEND_ARG_INFO(0, text)
76 : ZEND_END_ARG_INFO()
77 :
78 : static
79 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_print, 0)
80 : ZEND_ARG_INFO(0, text)
81 : ZEND_END_ARG_INFO()
82 :
83 : static
84 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_punct, 0)
85 : ZEND_ARG_INFO(0, text)
86 : ZEND_END_ARG_INFO()
87 :
88 : static
89 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_space, 0)
90 : ZEND_ARG_INFO(0, text)
91 : ZEND_END_ARG_INFO()
92 :
93 : static
94 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_upper, 0)
95 : ZEND_ARG_INFO(0, text)
96 : ZEND_END_ARG_INFO()
97 :
98 : static
99 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_xdigit, 0)
100 : ZEND_ARG_INFO(0, text)
101 : ZEND_END_ARG_INFO()
102 :
103 : /* }}} */
104 :
105 : /* {{{ ctype_functions[]
106 : * Every user visible function must have an entry in ctype_functions[].
107 : */
108 : static zend_function_entry ctype_functions[] = {
109 : PHP_FE(ctype_alnum, arginfo_ctype_alnum)
110 : PHP_FE(ctype_alpha, arginfo_ctype_alpha)
111 : PHP_FE(ctype_cntrl, arginfo_ctype_cntrl)
112 : PHP_FE(ctype_digit, arginfo_ctype_digit)
113 : PHP_FE(ctype_lower, arginfo_ctype_lower)
114 : PHP_FE(ctype_graph, arginfo_ctype_graph)
115 : PHP_FE(ctype_print, arginfo_ctype_print)
116 : PHP_FE(ctype_punct, arginfo_ctype_punct)
117 : PHP_FE(ctype_space, arginfo_ctype_space)
118 : PHP_FE(ctype_upper, arginfo_ctype_upper)
119 : PHP_FE(ctype_xdigit, arginfo_ctype_xdigit)
120 : {NULL, NULL, NULL} /* Must be the last line in ctype_functions[] */
121 : };
122 : /* }}} */
123 :
124 : /* {{{ ctype_module_entry
125 : */
126 : zend_module_entry ctype_module_entry = {
127 : STANDARD_MODULE_HEADER,
128 : "ctype",
129 : ctype_functions,
130 : NULL,
131 : NULL,
132 : NULL,
133 : NULL,
134 : PHP_MINFO(ctype),
135 : NO_VERSION_YET,
136 : STANDARD_MODULE_PROPERTIES
137 : };
138 : /* }}} */
139 :
140 : #ifdef COMPILE_DL_CTYPE
141 : ZEND_GET_MODULE(ctype)
142 : #endif
143 :
144 : /* {{{ PHP_MINFO_FUNCTION
145 : */
146 : static PHP_MINFO_FUNCTION(ctype)
147 6 : {
148 6 : php_info_print_table_start();
149 6 : php_info_print_table_row(2, "ctype functions", "enabled");
150 6 : php_info_print_table_end();
151 6 : }
152 : /* }}} */
153 :
154 : /* {{{ ctype
155 : */
156 : #define CTYPE(iswhat) \
157 : zval *c, tmp; \
158 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &c) == FAILURE) \
159 : return; \
160 : if (Z_TYPE_P(c) == IS_LONG) { \
161 : if (Z_LVAL_P(c) <= 255 && Z_LVAL_P(c) >= 0) { \
162 : RETURN_BOOL(iswhat(Z_LVAL_P(c))); \
163 : } else if (Z_LVAL_P(c) >= -128 && Z_LVAL_P(c) < 0) { \
164 : RETURN_BOOL(iswhat(Z_LVAL_P(c) + 256)); \
165 : } \
166 : tmp = *c; \
167 : zval_copy_ctor(&tmp); \
168 : convert_to_string(&tmp); \
169 : } else { \
170 : tmp = *c; \
171 : } \
172 : if (Z_TYPE(tmp) == IS_STRING) { \
173 : char *p = Z_STRVAL(tmp), *e = Z_STRVAL(tmp) + Z_STRLEN(tmp); \
174 : if (e == p) { \
175 : if (Z_TYPE_P(c) == IS_LONG) zval_dtor(&tmp); \
176 : RETURN_FALSE; \
177 : } \
178 : while (p < e) { \
179 : if(!iswhat((int)*(unsigned char *)(p++))) { \
180 : if (Z_TYPE_P(c) == IS_LONG) zval_dtor(&tmp); \
181 : RETURN_FALSE; \
182 : } \
183 : } \
184 : if (Z_TYPE_P(c) == IS_LONG) zval_dtor(&tmp); \
185 : RETURN_TRUE; \
186 : } else { \
187 : RETURN_FALSE; \
188 : } \
189 :
190 : /* }}} */
191 :
192 : /* {{{ proto bool ctype_alnum(mixed c)
193 : Checks for alphanumeric character(s) */
194 : static PHP_FUNCTION(ctype_alnum)
195 1468 : {
196 1468 : CTYPE(isalnum);
197 : }
198 : /* }}} */
199 :
200 : /* {{{ proto bool ctype_alpha(mixed c)
201 : Checks for alphabetic character(s) */
202 : static PHP_FUNCTION(ctype_alpha)
203 1468 : {
204 1468 : CTYPE(isalpha);
205 : }
206 : /* }}} */
207 :
208 : /* {{{ proto bool ctype_cntrl(mixed c)
209 : Checks for control character(s) */
210 : static PHP_FUNCTION(ctype_cntrl)
211 1475 : {
212 1475 : CTYPE(iscntrl);
213 : }
214 : /* }}} */
215 :
216 : /* {{{ proto bool ctype_digit(mixed c)
217 : Checks for numeric character(s) */
218 : static PHP_FUNCTION(ctype_digit)
219 1477 : {
220 1477 : CTYPE(isdigit);
221 : }
222 : /* }}} */
223 :
224 : /* {{{ proto bool ctype_lower(mixed c)
225 : Checks for lowercase character(s) */
226 : static PHP_FUNCTION(ctype_lower)
227 1471 : {
228 1471 : CTYPE(islower);
229 : }
230 : /* }}} */
231 :
232 : /* {{{ proto bool ctype_graph(mixed c)
233 : Checks for any printable character(s) except space */
234 : static PHP_FUNCTION(ctype_graph)
235 1473 : {
236 1473 : CTYPE(isgraph);
237 : }
238 : /* }}} */
239 :
240 : /* {{{ proto bool ctype_print(mixed c)
241 : Checks for printable character(s) */
242 : static PHP_FUNCTION(ctype_print)
243 1468 : {
244 1468 : CTYPE(isprint);
245 : }
246 : /* }}} */
247 :
248 : /* {{{ proto bool ctype_punct(mixed c)
249 : Checks for any printable character which is not whitespace or an alphanumeric character */
250 : static PHP_FUNCTION(ctype_punct)
251 1470 : {
252 1470 : CTYPE(ispunct);
253 : }
254 : /* }}} */
255 :
256 : /* {{{ proto bool ctype_space(mixed c)
257 : Checks for whitespace character(s)*/
258 : static PHP_FUNCTION(ctype_space)
259 1474 : {
260 1474 : CTYPE(isspace);
261 : }
262 : /* }}} */
263 :
264 : /* {{{ proto bool ctype_upper(mixed c)
265 : Checks for uppercase character(s) */
266 : static PHP_FUNCTION(ctype_upper)
267 1471 : {
268 1471 : CTYPE(isupper);
269 : }
270 : /* }}} */
271 :
272 : /* {{{ proto bool ctype_xdigit(mixed c)
273 : Checks for character(s) representing a hexadecimal digit */
274 : static PHP_FUNCTION(ctype_xdigit)
275 1478 : {
276 1478 : CTYPE(isxdigit);
277 : }
278 : /* }}} */
279 :
280 : #endif /* HAVE_CTYPE */
281 :
282 : /*
283 : * Local variables:
284 : * tab-width: 4
285 : * c-basic-offset: 4
286 : * End:
287 : * vim600: sw=4 ts=4 fdm=marker
288 : * vim<600: sw=4 ts=4
289 : */
|