1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 6 |
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 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_alnum, 0)
49 : ZEND_ARG_INFO(0, text)
50 : ZEND_END_ARG_INFO()
51 :
52 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_alpha, 0)
53 : ZEND_ARG_INFO(0, text)
54 : ZEND_END_ARG_INFO()
55 :
56 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_cntrl, 0)
57 : ZEND_ARG_INFO(0, text)
58 : ZEND_END_ARG_INFO()
59 :
60 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_digit, 0)
61 : ZEND_ARG_INFO(0, text)
62 : ZEND_END_ARG_INFO()
63 :
64 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_lower, 0)
65 : ZEND_ARG_INFO(0, text)
66 : ZEND_END_ARG_INFO()
67 :
68 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_graph, 0)
69 : ZEND_ARG_INFO(0, text)
70 : ZEND_END_ARG_INFO()
71 :
72 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_print, 0)
73 : ZEND_ARG_INFO(0, text)
74 : ZEND_END_ARG_INFO()
75 :
76 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_punct, 0)
77 : ZEND_ARG_INFO(0, text)
78 : ZEND_END_ARG_INFO()
79 :
80 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_space, 0)
81 : ZEND_ARG_INFO(0, text)
82 : ZEND_END_ARG_INFO()
83 :
84 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_upper, 0)
85 : ZEND_ARG_INFO(0, text)
86 : ZEND_END_ARG_INFO()
87 :
88 : ZEND_BEGIN_ARG_INFO(arginfo_ctype_xdigit, 0)
89 : ZEND_ARG_INFO(0, text)
90 : ZEND_END_ARG_INFO()
91 :
92 : /* }}} */
93 :
94 : /* {{{ ctype_functions[]
95 : * Every user visible function must have an entry in ctype_functions[].
96 : */
97 : static const zend_function_entry ctype_functions[] = {
98 : PHP_FE(ctype_alnum, arginfo_ctype_alnum)
99 : PHP_FE(ctype_alpha, arginfo_ctype_alpha)
100 : PHP_FE(ctype_cntrl, arginfo_ctype_cntrl)
101 : PHP_FE(ctype_digit, arginfo_ctype_digit)
102 : PHP_FE(ctype_lower, arginfo_ctype_lower)
103 : PHP_FE(ctype_graph, arginfo_ctype_graph)
104 : PHP_FE(ctype_print, arginfo_ctype_print)
105 : PHP_FE(ctype_punct, arginfo_ctype_punct)
106 : PHP_FE(ctype_space, arginfo_ctype_space)
107 : PHP_FE(ctype_upper, arginfo_ctype_upper)
108 : PHP_FE(ctype_xdigit, arginfo_ctype_xdigit)
109 : {NULL, NULL, NULL} /* Must be the last line in ctype_functions[] */
110 : };
111 : /* }}} */
112 :
113 : /* {{{ ctype_module_entry
114 : */
115 : zend_module_entry ctype_module_entry = {
116 : STANDARD_MODULE_HEADER,
117 : "ctype",
118 : ctype_functions,
119 : NULL,
120 : NULL,
121 : NULL,
122 : NULL,
123 : PHP_MINFO(ctype),
124 : NO_VERSION_YET,
125 : STANDARD_MODULE_PROPERTIES
126 : };
127 : /* }}} */
128 :
129 : #ifdef COMPILE_DL_CTYPE
130 : ZEND_GET_MODULE(ctype)
131 : #endif
132 :
133 : /* {{{ PHP_MINFO_FUNCTION
134 : */
135 : static PHP_MINFO_FUNCTION(ctype)
136 43 : {
137 43 : php_info_print_table_start();
138 43 : php_info_print_table_row(2, "ctype functions", "enabled");
139 43 : php_info_print_table_end();
140 43 : }
141 : /* }}} */
142 :
143 : /* {{{ ctype
144 : */
145 : #define CTYPE(iswhat) \
146 : zval *c, tmp; \
147 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &c) == FAILURE) \
148 : return; \
149 : switch (Z_TYPE_P(c)) { \
150 : case IS_LONG: \
151 : RETURN_BOOL(u_##iswhat(Z_LVAL_P(c))); \
152 : break; \
153 : case IS_UNICODE: \
154 : { \
155 : int ofs = 0; \
156 : while (ofs < Z_USTRLEN_P(c)) { \
157 : UChar32 ch; \
158 : U16_GET(Z_USTRVAL_P(c), 0, ofs, Z_USTRLEN_P(c), ch); \
159 : if (!u_##iswhat(ch)) { \
160 : RETURN_FALSE; \
161 : } \
162 : U16_FWD_1(Z_USTRVAL_P(c), ofs, Z_USTRLEN_P(c)); \
163 : } \
164 : RETURN_TRUE; \
165 : } \
166 : case IS_STRING: \
167 : { \
168 : char *p = Z_STRVAL_P(c), *e = Z_STRVAL_P(c) + Z_STRLEN_P(c); \
169 : if (e == p) { \
170 : if (c == &tmp) zval_dtor(&tmp); \
171 : RETURN_FALSE; \
172 : } \
173 : while (p < e) { \
174 : if(!iswhat((int)*(unsigned char *)(p++))) { \
175 : if (c == &tmp) zval_dtor(&tmp); \
176 : RETURN_FALSE; \
177 : } \
178 : } \
179 : if (c == &tmp) zval_dtor(&tmp); \
180 : RETURN_TRUE; \
181 : } \
182 : default: \
183 : break; \
184 : } \
185 : RETURN_FALSE;
186 :
187 : /* }}} */
188 :
189 : /* {{{ proto bool ctype_alnum(mixed c) U
190 : Checks for alphanumeric character(s) */
191 : static PHP_FUNCTION(ctype_alnum)
192 1152 : {
193 1152 : CTYPE(isalnum);
194 : }
195 : /* }}} */
196 :
197 : /* {{{ proto bool ctype_alpha(mixed c) U
198 : Checks for alphabetic character(s) */
199 : static PHP_FUNCTION(ctype_alpha)
200 1152 : {
201 1152 : CTYPE(isalpha);
202 : }
203 : /* }}} */
204 :
205 : /* {{{ proto bool ctype_cntrl(mixed c) U
206 : Checks for control character(s) */
207 : static PHP_FUNCTION(ctype_cntrl)
208 1152 : {
209 1152 : CTYPE(iscntrl);
210 : }
211 : /* }}} */
212 :
213 : /* {{{ proto bool ctype_digit(mixed c) U
214 : Checks for numeric character(s) */
215 : static PHP_FUNCTION(ctype_digit)
216 1153 : {
217 1153 : CTYPE(isdigit);
218 : }
219 : /* }}} */
220 :
221 : /* {{{ proto bool ctype_lower(mixed c) U
222 : Checks for lowercase character(s) */
223 : static PHP_FUNCTION(ctype_lower)
224 1152 : {
225 1152 : CTYPE(islower);
226 : }
227 : /* }}} */
228 :
229 : /* {{{ proto bool ctype_graph(mixed c) U
230 : Checks for any printable character(s) except space */
231 : static PHP_FUNCTION(ctype_graph)
232 1152 : {
233 1152 : CTYPE(isgraph);
234 : }
235 : /* }}} */
236 :
237 : /* {{{ proto bool ctype_print(mixed c) U
238 : Checks for printable character(s) */
239 : static PHP_FUNCTION(ctype_print)
240 1152 : {
241 1152 : CTYPE(isprint);
242 : }
243 : /* }}} */
244 :
245 : /* {{{ proto bool ctype_punct(mixed c) U
246 : Checks for any printable character which is not whitespace or an alphanumeric character */
247 : static PHP_FUNCTION(ctype_punct)
248 1152 : {
249 1152 : CTYPE(ispunct);
250 : }
251 : /* }}} */
252 :
253 : /* {{{ proto bool ctype_space(mixed c) U
254 : Checks for whitespace character(s)*/
255 : static PHP_FUNCTION(ctype_space)
256 1152 : {
257 1152 : CTYPE(isspace);
258 : }
259 : /* }}} */
260 :
261 : /* {{{ proto bool ctype_upper(mixed c) U
262 : Checks for uppercase character(s) */
263 : static PHP_FUNCTION(ctype_upper)
264 1152 : {
265 1152 : CTYPE(isupper);
266 : }
267 : /* }}} */
268 :
269 : /* {{{ proto bool ctype_xdigit(mixed c) U
270 : Checks for character(s) representing a hexadecimal digit */
271 : static PHP_FUNCTION(ctype_xdigit)
272 1152 : {
273 1152 : CTYPE(isxdigit);
274 : }
275 : /* }}} */
276 :
277 : #endif /* HAVE_CTYPE */
278 :
279 : /*
280 : * Local variables:
281 : * tab-width: 4
282 : * c-basic-offset: 4
283 : * End:
284 : * vim600: sw=4 ts=4 fdm=marker
285 : * vim<600: sw=4 ts=4
286 : */
|