2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2014 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 +----------------------------------------------------------------------+
25 #include "php_ctype.h"
27 #include "ext/standard/info.h"
33 static PHP_MINFO_FUNCTION(ctype
);
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
);
48 ZEND_BEGIN_ARG_INFO(arginfo_ctype_alnum
, 0)
49 ZEND_ARG_INFO(0, text
)
52 ZEND_BEGIN_ARG_INFO(arginfo_ctype_alpha
, 0)
53 ZEND_ARG_INFO(0, text
)
56 ZEND_BEGIN_ARG_INFO(arginfo_ctype_cntrl
, 0)
57 ZEND_ARG_INFO(0, text
)
60 ZEND_BEGIN_ARG_INFO(arginfo_ctype_digit
, 0)
61 ZEND_ARG_INFO(0, text
)
64 ZEND_BEGIN_ARG_INFO(arginfo_ctype_lower
, 0)
65 ZEND_ARG_INFO(0, text
)
68 ZEND_BEGIN_ARG_INFO(arginfo_ctype_graph
, 0)
69 ZEND_ARG_INFO(0, text
)
72 ZEND_BEGIN_ARG_INFO(arginfo_ctype_print
, 0)
73 ZEND_ARG_INFO(0, text
)
76 ZEND_BEGIN_ARG_INFO(arginfo_ctype_punct
, 0)
77 ZEND_ARG_INFO(0, text
)
80 ZEND_BEGIN_ARG_INFO(arginfo_ctype_space
, 0)
81 ZEND_ARG_INFO(0, text
)
84 ZEND_BEGIN_ARG_INFO(arginfo_ctype_upper
, 0)
85 ZEND_ARG_INFO(0, text
)
88 ZEND_BEGIN_ARG_INFO(arginfo_ctype_xdigit
, 0)
89 ZEND_ARG_INFO(0, text
)
94 /* {{{ ctype_functions[]
95 * Every user visible function must have an entry in ctype_functions[].
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
)
113 /* {{{ ctype_module_entry
115 zend_module_entry ctype_module_entry
= {
116 STANDARD_MODULE_HEADER
,
125 STANDARD_MODULE_PROPERTIES
129 #ifdef COMPILE_DL_CTYPE
130 ZEND_GET_MODULE(ctype
)
133 /* {{{ PHP_MINFO_FUNCTION
135 static PHP_MINFO_FUNCTION(ctype
)
137 php_info_print_table_start();
138 php_info_print_table_row(2, "ctype functions", "enabled");
139 php_info_print_table_end();
145 #define CTYPE(iswhat) \
147 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &c) == FAILURE) \
149 if (Z_TYPE_P(c) == IS_LONG) { \
150 if (Z_LVAL_P(c) <= 255 && Z_LVAL_P(c) >= 0) { \
151 RETURN_BOOL(iswhat(Z_LVAL_P(c))); \
152 } else if (Z_LVAL_P(c) >= -128 && Z_LVAL_P(c) < 0) { \
153 RETURN_BOOL(iswhat(Z_LVAL_P(c) + 256)); \
156 zval_copy_ctor(&tmp); \
157 convert_to_string(&tmp); \
161 if (Z_TYPE(tmp) == IS_STRING) { \
162 char *p = Z_STRVAL(tmp), *e = Z_STRVAL(tmp) + Z_STRLEN(tmp); \
164 if (Z_TYPE_P(c) == IS_LONG) zval_dtor(&tmp); \
168 if(!iswhat((int)*(unsigned char *)(p++))) { \
169 if (Z_TYPE_P(c) == IS_LONG) zval_dtor(&tmp); \
173 if (Z_TYPE_P(c) == IS_LONG) zval_dtor(&tmp); \
181 /* {{{ proto bool ctype_alnum(mixed c)
182 Checks for alphanumeric character(s) */
183 static PHP_FUNCTION(ctype_alnum
)
189 /* {{{ proto bool ctype_alpha(mixed c)
190 Checks for alphabetic character(s) */
191 static PHP_FUNCTION(ctype_alpha
)
197 /* {{{ proto bool ctype_cntrl(mixed c)
198 Checks for control character(s) */
199 static PHP_FUNCTION(ctype_cntrl
)
205 /* {{{ proto bool ctype_digit(mixed c)
206 Checks for numeric character(s) */
207 static PHP_FUNCTION(ctype_digit
)
213 /* {{{ proto bool ctype_lower(mixed c)
214 Checks for lowercase character(s) */
215 static PHP_FUNCTION(ctype_lower
)
221 /* {{{ proto bool ctype_graph(mixed c)
222 Checks for any printable character(s) except space */
223 static PHP_FUNCTION(ctype_graph
)
229 /* {{{ proto bool ctype_print(mixed c)
230 Checks for printable character(s) */
231 static PHP_FUNCTION(ctype_print
)
237 /* {{{ proto bool ctype_punct(mixed c)
238 Checks for any printable character which is not whitespace or an alphanumeric character */
239 static PHP_FUNCTION(ctype_punct
)
245 /* {{{ proto bool ctype_space(mixed c)
246 Checks for whitespace character(s)*/
247 static PHP_FUNCTION(ctype_space
)
253 /* {{{ proto bool ctype_upper(mixed c)
254 Checks for uppercase character(s) */
255 static PHP_FUNCTION(ctype_upper
)
261 /* {{{ proto bool ctype_xdigit(mixed c)
262 Checks for character(s) representing a hexadecimal digit */
263 static PHP_FUNCTION(ctype_xdigit
)
269 #endif /* HAVE_CTYPE */
276 * vim600: sw=4 ts=4 fdm=marker