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
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 08:18:22 +00:00
|
|
|
| Copyright (c) 1997-2004 The PHP Group |
|
2000-11-22 01:00:44 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2003-06-10 20:04:29 +00:00
|
|
|
| This source file is subject to version 3.0 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: |
|
|
|
|
| http://www.php.net/license/3_0.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>
|
|
|
|
|
|
|
|
/* You should tweak config.m4 so this symbol (or some else suitable)
|
|
|
|
gets defined.
|
|
|
|
*/
|
|
|
|
#if HAVE_CTYPE
|
|
|
|
|
|
|
|
/* If you declare any globals in php_ctype.h uncomment this:
|
|
|
|
ZEND_DECLARE_MODULE_GLOBALS(ctype)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* True global resources - no need for thread safety here */
|
2001-08-22 09:20:40 +00:00
|
|
|
/* static int le_ctype; */
|
2000-11-22 01:00:44 +00:00
|
|
|
|
2001-06-05 13:12:10 +00:00
|
|
|
/* {{{ ctype_functions[]
|
|
|
|
* Every user visible function must have an entry in ctype_functions[].
|
|
|
|
*/
|
2000-11-22 01:00:44 +00:00
|
|
|
function_entry ctype_functions[] = {
|
2000-12-19 11:50:30 +00:00
|
|
|
PHP_FE(ctype_alnum, NULL)
|
|
|
|
PHP_FE(ctype_alpha, NULL)
|
|
|
|
PHP_FE(ctype_cntrl, NULL)
|
|
|
|
PHP_FE(ctype_digit, NULL)
|
|
|
|
PHP_FE(ctype_lower, NULL)
|
|
|
|
PHP_FE(ctype_graph, NULL)
|
|
|
|
PHP_FE(ctype_print, NULL)
|
|
|
|
PHP_FE(ctype_punct, NULL)
|
|
|
|
PHP_FE(ctype_space, NULL)
|
|
|
|
PHP_FE(ctype_upper, NULL)
|
|
|
|
PHP_FE(ctype_xdigit, NULL)
|
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
|
|
|
|
*/
|
2000-11-22 01:00:44 +00:00
|
|
|
PHP_MINFO_FUNCTION(ctype)
|
|
|
|
{
|
|
|
|
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) \
|
|
|
|
zval *c; \
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &c) == FAILURE) \
|
|
|
|
return; \
|
|
|
|
switch (Z_TYPE_P(c)) { \
|
|
|
|
case 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-07-20 20:08:08 +00:00
|
|
|
} else if (Z_LVAL_P(c) >= -128) { \
|
|
|
|
RETURN_BOOL(iswhat(Z_LVAL_P(c) + 256)); \
|
|
|
|
} \
|
2004-07-20 01:03:16 +00:00
|
|
|
SEPARATE_ZVAL(&c); \
|
|
|
|
convert_to_string(c); \
|
2002-03-08 11:59:02 +00:00
|
|
|
case IS_STRING: \
|
|
|
|
{ \
|
|
|
|
char *p; \
|
|
|
|
int n, len; \
|
|
|
|
p=Z_STRVAL_P(c); \
|
|
|
|
len = Z_STRLEN_P(c); \
|
|
|
|
for(n=0;n<len;n++) { \
|
2003-10-03 15:50:01 +00:00
|
|
|
if(!iswhat((int)*(unsigned char *)(p++))) RETURN_FALSE; \
|
2002-03-08 11:59:02 +00:00
|
|
|
} \
|
|
|
|
RETURN_TRUE; \
|
|
|
|
} \
|
|
|
|
default: \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
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) */
|
2000-12-19 11:50:30 +00:00
|
|
|
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) */
|
2000-12-19 11:50:30 +00:00
|
|
|
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) */
|
2000-12-19 11:50:30 +00:00
|
|
|
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) */
|
2000-12-19 11:50:30 +00:00
|
|
|
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) */
|
2000-12-19 11:50:30 +00:00
|
|
|
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 */
|
2000-12-19 11:50:30 +00:00
|
|
|
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) */
|
2000-12-19 11:50:30 +00:00
|
|
|
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 */
|
2000-12-19 11:50:30 +00:00
|
|
|
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)*/
|
2000-12-19 11:50:30 +00:00
|
|
|
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) */
|
2000-12-19 11:50:30 +00:00
|
|
|
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 */
|
2000-12-19 11:50:30 +00:00
|
|
|
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
|
|
|
*/
|