Back to index

php5  5.3.10
ctype.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Author: Hartmut Holzgraefe <hholzgra@php.net>                        |
00016    +----------------------------------------------------------------------+
00017  */
00018 
00019 #ifdef HAVE_CONFIG_H
00020 #include "config.h"
00021 #endif
00022 
00023 #include "php.h"
00024 #include "php_ini.h"
00025 #include "php_ctype.h"
00026 #include "SAPI.h"
00027 #include "ext/standard/info.h"
00028 
00029 #include <ctype.h>
00030 
00031 #if HAVE_CTYPE
00032 
00033 static PHP_MINFO_FUNCTION(ctype);
00034 
00035 static PHP_FUNCTION(ctype_alnum);
00036 static PHP_FUNCTION(ctype_alpha);
00037 static PHP_FUNCTION(ctype_cntrl);
00038 static PHP_FUNCTION(ctype_digit);
00039 static PHP_FUNCTION(ctype_lower);
00040 static PHP_FUNCTION(ctype_graph);
00041 static PHP_FUNCTION(ctype_print);
00042 static PHP_FUNCTION(ctype_punct);
00043 static PHP_FUNCTION(ctype_space);
00044 static PHP_FUNCTION(ctype_upper);
00045 static PHP_FUNCTION(ctype_xdigit);
00046 
00047 /* {{{ arginfo */
00048 ZEND_BEGIN_ARG_INFO(arginfo_ctype_alnum, 0)
00049        ZEND_ARG_INFO(0, text)
00050 ZEND_END_ARG_INFO()
00051 
00052 ZEND_BEGIN_ARG_INFO(arginfo_ctype_alpha, 0)
00053        ZEND_ARG_INFO(0, text)
00054 ZEND_END_ARG_INFO()
00055 
00056 ZEND_BEGIN_ARG_INFO(arginfo_ctype_cntrl, 0)
00057        ZEND_ARG_INFO(0, text)
00058 ZEND_END_ARG_INFO()
00059 
00060 ZEND_BEGIN_ARG_INFO(arginfo_ctype_digit, 0)
00061        ZEND_ARG_INFO(0, text)
00062 ZEND_END_ARG_INFO()
00063 
00064 ZEND_BEGIN_ARG_INFO(arginfo_ctype_lower, 0)
00065        ZEND_ARG_INFO(0, text)
00066 ZEND_END_ARG_INFO()
00067 
00068 ZEND_BEGIN_ARG_INFO(arginfo_ctype_graph, 0)
00069        ZEND_ARG_INFO(0, text)
00070 ZEND_END_ARG_INFO()
00071 
00072 ZEND_BEGIN_ARG_INFO(arginfo_ctype_print, 0)
00073        ZEND_ARG_INFO(0, text)
00074 ZEND_END_ARG_INFO()
00075 
00076 ZEND_BEGIN_ARG_INFO(arginfo_ctype_punct, 0)
00077        ZEND_ARG_INFO(0, text)
00078 ZEND_END_ARG_INFO()
00079 
00080 ZEND_BEGIN_ARG_INFO(arginfo_ctype_space, 0)
00081        ZEND_ARG_INFO(0, text)
00082 ZEND_END_ARG_INFO()
00083 
00084 ZEND_BEGIN_ARG_INFO(arginfo_ctype_upper, 0)
00085        ZEND_ARG_INFO(0, text)
00086 ZEND_END_ARG_INFO()
00087 
00088 ZEND_BEGIN_ARG_INFO(arginfo_ctype_xdigit, 0)
00089        ZEND_ARG_INFO(0, text)
00090 ZEND_END_ARG_INFO()
00091 
00092 /* }}} */
00093 
00094 /* {{{ ctype_functions[]
00095  * Every user visible function must have an entry in ctype_functions[].
00096  */
00097 static const zend_function_entry ctype_functions[] = {
00098        PHP_FE(ctype_alnum,  arginfo_ctype_alnum)
00099        PHP_FE(ctype_alpha,  arginfo_ctype_alpha)
00100        PHP_FE(ctype_cntrl,  arginfo_ctype_cntrl)
00101        PHP_FE(ctype_digit,  arginfo_ctype_digit)
00102        PHP_FE(ctype_lower,  arginfo_ctype_lower)
00103        PHP_FE(ctype_graph,  arginfo_ctype_graph)
00104        PHP_FE(ctype_print,  arginfo_ctype_print)
00105        PHP_FE(ctype_punct,  arginfo_ctype_punct)
00106        PHP_FE(ctype_space,  arginfo_ctype_space)
00107        PHP_FE(ctype_upper,  arginfo_ctype_upper)
00108        PHP_FE(ctype_xdigit, arginfo_ctype_xdigit)
00109        PHP_FE_END
00110 };
00111 /* }}} */
00112 
00113 /* {{{ ctype_module_entry
00114  */
00115 zend_module_entry ctype_module_entry = {
00116        STANDARD_MODULE_HEADER,
00117        "ctype",
00118        ctype_functions,
00119        NULL,
00120        NULL,
00121        NULL,
00122        NULL,
00123        PHP_MINFO(ctype),
00124     NO_VERSION_YET,
00125        STANDARD_MODULE_PROPERTIES
00126 };
00127 /* }}} */
00128 
00129 #ifdef COMPILE_DL_CTYPE
00130 ZEND_GET_MODULE(ctype)
00131 #endif
00132 
00133 /* {{{ PHP_MINFO_FUNCTION
00134  */
00135 static PHP_MINFO_FUNCTION(ctype)
00136 {
00137        php_info_print_table_start();
00138        php_info_print_table_row(2, "ctype functions", "enabled");
00139        php_info_print_table_end();
00140 }
00141 /* }}} */
00142 
00143 /* {{{ ctype
00144  */
00145 #define CTYPE(iswhat) \
00146        zval *c, tmp; \
00147        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &c) == FAILURE) \
00148               return; \
00149        if (Z_TYPE_P(c) == IS_LONG) { \
00150               if (Z_LVAL_P(c) <= 255 && Z_LVAL_P(c) >= 0) { \
00151                      RETURN_BOOL(iswhat(Z_LVAL_P(c))); \
00152               } else if (Z_LVAL_P(c) >= -128 && Z_LVAL_P(c) < 0) { \
00153                      RETURN_BOOL(iswhat(Z_LVAL_P(c) + 256)); \
00154               } \
00155               tmp = *c; \
00156               zval_copy_ctor(&tmp); \
00157               convert_to_string(&tmp); \
00158        } else { \
00159               tmp = *c; \
00160        } \
00161        if (Z_TYPE(tmp) == IS_STRING) { \
00162               char *p = Z_STRVAL(tmp), *e = Z_STRVAL(tmp) + Z_STRLEN(tmp); \
00163               if (e == p) { \
00164                      if (Z_TYPE_P(c) == IS_LONG) zval_dtor(&tmp); \
00165                      RETURN_FALSE; \
00166               }      \
00167               while (p < e) { \
00168                      if(!iswhat((int)*(unsigned char *)(p++))) { \
00169                             if (Z_TYPE_P(c) == IS_LONG) zval_dtor(&tmp); \
00170                             RETURN_FALSE; \
00171                      } \
00172               } \
00173               if (Z_TYPE_P(c) == IS_LONG) zval_dtor(&tmp); \
00174               RETURN_TRUE; \
00175        } else { \
00176               RETURN_FALSE; \
00177        } \
00178 
00179 /* }}} */
00180 
00181 /* {{{ proto bool ctype_alnum(mixed c)
00182    Checks for alphanumeric character(s) */
00183 static PHP_FUNCTION(ctype_alnum)
00184 {
00185        CTYPE(isalnum);
00186 }
00187 /* }}} */
00188 
00189 /* {{{ proto bool ctype_alpha(mixed c)
00190    Checks for alphabetic character(s) */
00191 static PHP_FUNCTION(ctype_alpha)
00192 {
00193        CTYPE(isalpha);
00194 }
00195 /* }}} */
00196 
00197 /* {{{ proto bool ctype_cntrl(mixed c)
00198    Checks for control character(s) */
00199 static PHP_FUNCTION(ctype_cntrl)
00200 {
00201        CTYPE(iscntrl);
00202 }
00203 /* }}} */
00204 
00205 /* {{{ proto bool ctype_digit(mixed c)
00206    Checks for numeric character(s) */
00207 static PHP_FUNCTION(ctype_digit)
00208 {
00209        CTYPE(isdigit);
00210 }
00211 /* }}} */
00212 
00213 /* {{{ proto bool ctype_lower(mixed c)
00214    Checks for lowercase character(s)  */
00215 static PHP_FUNCTION(ctype_lower)
00216 {
00217        CTYPE(islower);
00218 }
00219 /* }}} */
00220 
00221 /* {{{ proto bool ctype_graph(mixed c)
00222    Checks for any printable character(s) except space */
00223 static PHP_FUNCTION(ctype_graph)
00224 {
00225        CTYPE(isgraph);
00226 }
00227 /* }}} */
00228 
00229 /* {{{ proto bool ctype_print(mixed c)
00230    Checks for printable character(s) */
00231 static PHP_FUNCTION(ctype_print)
00232 {
00233        CTYPE(isprint);
00234 }
00235 /* }}} */
00236 
00237 /* {{{ proto bool ctype_punct(mixed c)
00238    Checks for any printable character which is not whitespace or an alphanumeric character */
00239 static PHP_FUNCTION(ctype_punct)
00240 {
00241        CTYPE(ispunct);
00242 }
00243 /* }}} */
00244 
00245 /* {{{ proto bool ctype_space(mixed c)
00246    Checks for whitespace character(s)*/
00247 static PHP_FUNCTION(ctype_space)
00248 {
00249        CTYPE(isspace);
00250 }
00251 /* }}} */
00252 
00253 /* {{{ proto bool ctype_upper(mixed c)
00254    Checks for uppercase character(s) */
00255 static PHP_FUNCTION(ctype_upper)
00256 {
00257        CTYPE(isupper);
00258 }
00259 /* }}} */
00260 
00261 /* {{{ proto bool ctype_xdigit(mixed c)
00262    Checks for character(s) representing a hexadecimal digit */
00263 static PHP_FUNCTION(ctype_xdigit)
00264 {
00265        CTYPE(isxdigit);
00266 }
00267 /* }}} */
00268 
00269 #endif /* HAVE_CTYPE */
00270 
00271 /*
00272  * Local variables:
00273  * tab-width: 4
00274  * c-basic-offset: 4
00275  * End:
00276  * vim600: sw=4 ts=4 fdm=marker
00277  * vim<600: sw=4 ts=4
00278  */