2000-11-22 01:00:44 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 08:18:22 +00:00
|
|
|
| PHP Version 5 |
|
2000-11-22 01:00:44 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2007-12-31 07:17:19 +00:00
|
|
|
| Copyright (c) 1997-2008 The PHP Group |
|
2000-11-22 01:00:44 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 12:51:34 +00:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
2000-11-22 01:00:44 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-10 20:04:29 +00:00
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 12:51:34 +00:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
2000-11-22 01:00:44 +00:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
2002-11-25 12:30:28 +00:00
|
|
|
| Author: Hartmut Holzgraefe <hholzgra@php.net> |
|
2000-11-22 01:00:44 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2001-05-24 10:07:29 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2000-11-22 01:00:44 +00:00
|
|
|
#include "php.h"
|
|
|
|
#include "php_ini.h"
|
|
|
|
#include "php_ctype.h"
|
|
|
|
#include "SAPI.h"
|
|
|
|
#include "ext/standard/info.h"
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#if HAVE_CTYPE
|
|
|
|
|
2006-08-14 20:08:18 +00:00
|
|
|
static PHP_MINFO_FUNCTION(ctype);
|
|
|
|
|
|
|
|
static PHP_FUNCTION(ctype_alnum);
|
|
|
|
static PHP_FUNCTION(ctype_alpha);
|
|
|
|
static PHP_FUNCTION(ctype_cntrl);
|
|
|
|
static PHP_FUNCTION(ctype_digit);
|
|
|
|
static PHP_FUNCTION(ctype_lower);
|
|
|
|
static PHP_FUNCTION(ctype_graph);
|
|
|
|
static PHP_FUNCTION(ctype_print);
|
|
|
|
static PHP_FUNCTION(ctype_punct);
|
|
|
|
static PHP_FUNCTION(ctype_space);
|
|
|
|
static PHP_FUNCTION(ctype_upper);
|
|
|
|
static PHP_FUNCTION(ctype_xdigit);
|
|
|
|
|
2006-06-11 01:42:17 +00:00
|
|
|
/* {{{ arginfo */
|
|
|
|
static
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ctype_alnum, 0)
|
|
|
|
ZEND_ARG_INFO(0, text)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
static
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ctype_alpha, 0)
|
|
|
|
ZEND_ARG_INFO(0, text)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
static
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ctype_cntrl, 0)
|
|
|
|
ZEND_ARG_INFO(0, text)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
static
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ctype_digit, 0)
|
|
|
|
ZEND_ARG_INFO(0, text)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
static
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ctype_lower, 0)
|
|
|
|
ZEND_ARG_INFO(0, text)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
static
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ctype_graph, 0)
|
|
|
|
ZEND_ARG_INFO(0, text)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
static
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ctype_print, 0)
|
|
|
|
ZEND_ARG_INFO(0, text)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
static
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ctype_punct, 0)
|
|
|
|
ZEND_ARG_INFO(0, text)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
static
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ctype_space, 0)
|
|
|
|
ZEND_ARG_INFO(0, text)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
static
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ctype_upper, 0)
|
|
|
|
ZEND_ARG_INFO(0, text)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
static
|
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ctype_xdigit, 0)
|
|
|
|
ZEND_ARG_INFO(0, text)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
2001-06-05 13:12:10 +00:00
|
|
|
/* {{{ ctype_functions[]
|
|
|
|
* Every user visible function must have an entry in ctype_functions[].
|
|
|
|
*/
|
2007-09-27 18:00:48 +00:00
|
|
|
static const zend_function_entry ctype_functions[] = {
|
2006-06-11 01:42:17 +00:00
|
|
|
PHP_FE(ctype_alnum, arginfo_ctype_alnum)
|
|
|
|
PHP_FE(ctype_alpha, arginfo_ctype_alpha)
|
|
|
|
PHP_FE(ctype_cntrl, arginfo_ctype_cntrl)
|
|
|
|
PHP_FE(ctype_digit, arginfo_ctype_digit)
|
|
|
|
PHP_FE(ctype_lower, arginfo_ctype_lower)
|
|
|
|
PHP_FE(ctype_graph, arginfo_ctype_graph)
|
|
|
|
PHP_FE(ctype_print, arginfo_ctype_print)
|
|
|
|
PHP_FE(ctype_punct, arginfo_ctype_punct)
|
|
|
|
PHP_FE(ctype_space, arginfo_ctype_space)
|
|
|
|
PHP_FE(ctype_upper, arginfo_ctype_upper)
|
|
|
|
PHP_FE(ctype_xdigit, arginfo_ctype_xdigit)
|
2000-11-22 01:00:44 +00:00
|
|
|
{NULL, NULL, NULL} /* Must be the last line in ctype_functions[] */
|
|
|
|
};
|
2001-06-05 13:12:10 +00:00
|
|
|
/* }}} */
|
2000-11-22 01:00:44 +00:00
|
|
|
|
2003-01-09 20:23:36 +00:00
|
|
|
/* {{{ ctype_module_entry
|
2001-06-05 13:12:10 +00:00
|
|
|
*/
|
2000-11-22 01:00:44 +00:00
|
|
|
zend_module_entry ctype_module_entry = {
|
2001-10-11 23:33:59 +00:00
|
|
|
STANDARD_MODULE_HEADER,
|
2000-11-22 01:00:44 +00:00
|
|
|
"ctype",
|
|
|
|
ctype_functions,
|
2000-12-19 11:50:30 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2000-11-22 01:00:44 +00:00
|
|
|
PHP_MINFO(ctype),
|
2001-10-11 23:33:59 +00:00
|
|
|
NO_VERSION_YET,
|
2000-11-22 01:00:44 +00:00
|
|
|
STANDARD_MODULE_PROPERTIES
|
|
|
|
};
|
2001-06-05 13:12:10 +00:00
|
|
|
/* }}} */
|
2000-11-22 01:00:44 +00:00
|
|
|
|
|
|
|
#ifdef COMPILE_DL_CTYPE
|
|
|
|
ZEND_GET_MODULE(ctype)
|
|
|
|
#endif
|
|
|
|
|
2001-06-05 13:12:10 +00:00
|
|
|
/* {{{ PHP_MINFO_FUNCTION
|
|
|
|
*/
|
2006-08-14 14:53:23 +00:00
|
|
|
static PHP_MINFO_FUNCTION(ctype)
|
2000-11-22 01:00:44 +00:00
|
|
|
{
|
|
|
|
php_info_print_table_start();
|
2002-05-15 05:25:16 +00:00
|
|
|
php_info_print_table_row(2, "ctype functions", "enabled");
|
2000-11-22 01:00:44 +00:00
|
|
|
php_info_print_table_end();
|
|
|
|
}
|
2001-06-05 13:12:10 +00:00
|
|
|
/* }}} */
|
2000-11-22 01:00:44 +00:00
|
|
|
|
2001-06-05 13:12:10 +00:00
|
|
|
/* {{{ ctype
|
|
|
|
*/
|
2002-03-08 11:59:02 +00:00
|
|
|
#define CTYPE(iswhat) \
|
2005-09-26 15:14:19 +00:00
|
|
|
zval *c, tmp; \
|
2002-03-08 11:59:02 +00:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &c) == FAILURE) \
|
|
|
|
return; \
|
2005-09-26 15:14:19 +00:00
|
|
|
if (Z_TYPE_P(c) == IS_LONG) { \
|
2004-07-20 20:08:08 +00:00
|
|
|
if (Z_LVAL_P(c) <= 255 && Z_LVAL_P(c) >= 0) { \
|
2004-07-20 01:03:16 +00:00
|
|
|
RETURN_BOOL(iswhat(Z_LVAL_P(c))); \
|
2004-09-30 01:22:56 +00:00
|
|
|
} else if (Z_LVAL_P(c) >= -128 && Z_LVAL_P(c) < 0) { \
|
2004-07-20 20:08:08 +00:00
|
|
|
RETURN_BOOL(iswhat(Z_LVAL_P(c) + 256)); \
|
|
|
|
} \
|
2005-09-26 15:14:19 +00:00
|
|
|
tmp = *c; \
|
|
|
|
zval_copy_ctor(&tmp); \
|
|
|
|
convert_to_string(&tmp); \
|
|
|
|
} else { \
|
|
|
|
tmp = *c; \
|
|
|
|
} \
|
|
|
|
if (Z_TYPE(tmp) == IS_STRING) { \
|
|
|
|
char *p = Z_STRVAL(tmp), *e = Z_STRVAL(tmp) + Z_STRLEN(tmp); \
|
|
|
|
if (e == p) { \
|
|
|
|
if (Z_TYPE_P(c) == IS_LONG) zval_dtor(&tmp); \
|
|
|
|
RETURN_FALSE; \
|
|
|
|
} \
|
|
|
|
while (p < e) { \
|
|
|
|
if(!iswhat((int)*(unsigned char *)(p++))) { \
|
|
|
|
if (Z_TYPE_P(c) == IS_LONG) zval_dtor(&tmp); \
|
|
|
|
RETURN_FALSE; \
|
2002-03-08 11:59:02 +00:00
|
|
|
} \
|
|
|
|
} \
|
2005-09-26 15:14:19 +00:00
|
|
|
if (Z_TYPE_P(c) == IS_LONG) zval_dtor(&tmp); \
|
|
|
|
RETURN_TRUE; \
|
|
|
|
} else { \
|
|
|
|
RETURN_FALSE; \
|
2002-03-08 11:59:02 +00:00
|
|
|
} \
|
2005-09-26 15:14:19 +00:00
|
|
|
|
2001-06-05 13:12:10 +00:00
|
|
|
/* }}} */
|
2000-11-22 01:00:44 +00:00
|
|
|
|
2001-12-04 21:18:26 +00:00
|
|
|
/* {{{ proto bool ctype_alnum(mixed c)
|
2001-09-04 21:46:27 +00:00
|
|
|
Checks for alphanumeric character(s) */
|
2006-08-14 14:53:23 +00:00
|
|
|
static PHP_FUNCTION(ctype_alnum)
|
2000-11-22 01:00:44 +00:00
|
|
|
{
|
2002-03-08 11:59:02 +00:00
|
|
|
CTYPE(isalnum);
|
2000-11-22 01:00:44 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-04 21:18:26 +00:00
|
|
|
/* {{{ proto bool ctype_alpha(mixed c)
|
2001-09-04 21:46:27 +00:00
|
|
|
Checks for alphabetic character(s) */
|
2006-08-14 14:53:23 +00:00
|
|
|
static PHP_FUNCTION(ctype_alpha)
|
2000-11-22 01:00:44 +00:00
|
|
|
{
|
2002-03-08 11:59:02 +00:00
|
|
|
CTYPE(isalpha);
|
2000-11-22 01:00:44 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-04 21:18:26 +00:00
|
|
|
/* {{{ proto bool ctype_cntrl(mixed c)
|
2001-09-04 21:46:27 +00:00
|
|
|
Checks for control character(s) */
|
2006-08-14 14:53:23 +00:00
|
|
|
static PHP_FUNCTION(ctype_cntrl)
|
2000-11-22 01:00:44 +00:00
|
|
|
{
|
2002-03-08 11:59:02 +00:00
|
|
|
CTYPE(iscntrl);
|
2000-11-22 01:00:44 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-04 21:18:26 +00:00
|
|
|
/* {{{ proto bool ctype_digit(mixed c)
|
2001-09-04 21:46:27 +00:00
|
|
|
Checks for numeric character(s) */
|
2006-08-14 14:53:23 +00:00
|
|
|
static PHP_FUNCTION(ctype_digit)
|
2000-11-22 01:00:44 +00:00
|
|
|
{
|
2002-03-08 11:59:02 +00:00
|
|
|
CTYPE(isdigit);
|
2000-11-22 01:00:44 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-04 21:18:26 +00:00
|
|
|
/* {{{ proto bool ctype_lower(mixed c)
|
2001-09-04 21:46:27 +00:00
|
|
|
Checks for lowercase character(s) */
|
2006-08-14 14:53:23 +00:00
|
|
|
static PHP_FUNCTION(ctype_lower)
|
2000-11-22 01:00:44 +00:00
|
|
|
{
|
2002-03-08 11:59:02 +00:00
|
|
|
CTYPE(islower);
|
2000-11-22 01:00:44 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-04 21:18:26 +00:00
|
|
|
/* {{{ proto bool ctype_graph(mixed c)
|
2001-09-04 21:46:27 +00:00
|
|
|
Checks for any printable character(s) except space */
|
2006-08-14 14:53:23 +00:00
|
|
|
static PHP_FUNCTION(ctype_graph)
|
2000-11-22 01:00:44 +00:00
|
|
|
{
|
2002-03-08 11:59:02 +00:00
|
|
|
CTYPE(isgraph);
|
2000-11-22 01:00:44 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-04 21:18:26 +00:00
|
|
|
/* {{{ proto bool ctype_print(mixed c)
|
2001-09-04 21:46:27 +00:00
|
|
|
Checks for printable character(s) */
|
2006-08-14 14:53:23 +00:00
|
|
|
static PHP_FUNCTION(ctype_print)
|
2000-11-22 01:00:44 +00:00
|
|
|
{
|
2002-03-08 11:59:02 +00:00
|
|
|
CTYPE(isprint);
|
2000-11-22 01:00:44 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-04 21:18:26 +00:00
|
|
|
/* {{{ proto bool ctype_punct(mixed c)
|
2001-09-04 21:46:27 +00:00
|
|
|
Checks for any printable character which is not whitespace or an alphanumeric character */
|
2006-08-14 14:53:23 +00:00
|
|
|
static PHP_FUNCTION(ctype_punct)
|
2000-11-22 01:00:44 +00:00
|
|
|
{
|
2002-03-08 11:59:02 +00:00
|
|
|
CTYPE(ispunct);
|
2000-11-22 01:00:44 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-04 21:18:26 +00:00
|
|
|
/* {{{ proto bool ctype_space(mixed c)
|
2001-09-04 21:46:27 +00:00
|
|
|
Checks for whitespace character(s)*/
|
2006-08-14 14:53:23 +00:00
|
|
|
static PHP_FUNCTION(ctype_space)
|
2000-11-22 01:00:44 +00:00
|
|
|
{
|
2002-03-08 11:59:02 +00:00
|
|
|
CTYPE(isspace);
|
2000-11-22 01:00:44 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-04 21:18:26 +00:00
|
|
|
/* {{{ proto bool ctype_upper(mixed c)
|
2001-09-04 21:46:27 +00:00
|
|
|
Checks for uppercase character(s) */
|
2006-08-14 14:53:23 +00:00
|
|
|
static PHP_FUNCTION(ctype_upper)
|
2000-11-22 01:00:44 +00:00
|
|
|
{
|
2002-03-08 11:59:02 +00:00
|
|
|
CTYPE(isupper);
|
2000-11-22 01:00:44 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-12-04 21:18:26 +00:00
|
|
|
/* {{{ proto bool ctype_xdigit(mixed c)
|
2001-09-04 21:46:27 +00:00
|
|
|
Checks for character(s) representing a hexadecimal digit */
|
2006-08-14 14:53:23 +00:00
|
|
|
static PHP_FUNCTION(ctype_xdigit)
|
2000-11-22 01:00:44 +00:00
|
|
|
{
|
2002-03-08 11:59:02 +00:00
|
|
|
CTYPE(isxdigit);
|
2000-11-22 01:00:44 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
#endif /* HAVE_CTYPE */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-09-09 13:29:31 +00:00
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4
|
2000-11-22 01:00:44 +00:00
|
|
|
*/
|