php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
ctype.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: Hartmut Holzgraefe <hholzgra@php.net> |
14 +----------------------------------------------------------------------+
15 */
16
17#ifdef HAVE_CONFIG_H
18#include <config.h>
19#endif
20
21#include "php.h"
22#include "php_ctype.h"
23#include "ctype_arginfo.h"
24#include "ext/standard/info.h"
25
26#include <ctype.h>
27
28#ifdef HAVE_CTYPE
29
31
32/* }}} */
33
34/* {{{ ctype_module_entry */
35zend_module_entry ctype_module_entry = {
37 "ctype",
38 ext_functions,
39 NULL,
40 NULL,
41 NULL,
42 NULL,
46};
47/* }}} */
48
49#ifdef COMPILE_DL_CTYPE
51#endif
52
53/* {{{ PHP_MINFO_FUNCTION */
55{
57 php_info_print_table_row(2, "ctype functions", "enabled");
59}
60/* }}} */
61
62/* Slow fallback for deprecated cases defined in a no-inline function to not bloat code. */
63static zend_never_inline void ctype_fallback(zval *c, zval *return_value, int (*iswhat)(int), bool allow_digits, bool allow_minus)
64{
66 "Argument of type %s will be interpreted as string in the future", zend_zval_type_name(c));
67 if (Z_TYPE_P(c) == IS_LONG) {
68 if (Z_LVAL_P(c) <= 255 && Z_LVAL_P(c) >= 0) {
69 RETURN_BOOL(iswhat((int)Z_LVAL_P(c)));
70 } else if (Z_LVAL_P(c) >= -128 && Z_LVAL_P(c) < 0) {
71 RETURN_BOOL(iswhat((int)Z_LVAL_P(c) + 256));
72 } else if (Z_LVAL_P(c) >= 0) {
73 RETURN_BOOL(allow_digits);
74 } else {
75 RETURN_BOOL(allow_minus);
76 }
77 } else {
79 }
80}
81
82/* Define as a macro such that iswhat can use the macro version instead of the function version.
83 * This heavily reduces the overhead. (GH-11997) */
84#define ctype_impl(iswhat, allow_digits, allow_minus) do { \
85 zval *c; \
86 \
87 ZEND_PARSE_PARAMETERS_START(1, 1); \
88 Z_PARAM_ZVAL(c) \
89 ZEND_PARSE_PARAMETERS_END(); \
90 \
91 if (Z_TYPE_P(c) == IS_STRING) { \
92 char *p = Z_STRVAL_P(c), *e = Z_STRVAL_P(c) + Z_STRLEN_P(c); \
93 if (e == p) { \
94 RETURN_FALSE; \
95 } \
96 while (p < e) { \
97 if (!iswhat((int)*(unsigned char *)(p++))) { \
98 RETURN_FALSE; \
99 } \
100 } \
101 RETURN_TRUE; \
102 } \
103 \
104 ctype_fallback(c, return_value, iswhat, allow_digits, allow_minus); \
105 } while (0);
106
107/* {{{ Checks for alphanumeric character(s) */
109{
110 ctype_impl(isalnum, 1, 0);
111}
112/* }}} */
113
114/* {{{ Checks for alphabetic character(s) */
116{
117 ctype_impl(isalpha, 0, 0);
118}
119/* }}} */
120
121/* {{{ Checks for control character(s) */
123{
124 ctype_impl(iscntrl, 0, 0);
125}
126/* }}} */
127
128/* {{{ Checks for numeric character(s) */
130{
131 ctype_impl(isdigit, 1, 0);
132}
133/* }}} */
134
135/* {{{ Checks for lowercase character(s) */
137{
138 ctype_impl(islower, 0, 0);
139}
140/* }}} */
141
142/* {{{ Checks for any printable character(s) except space */
144{
145 ctype_impl(isgraph, 1, 1);
146}
147/* }}} */
148
149/* {{{ Checks for printable character(s) */
151{
152 ctype_impl(isprint, 1, 1);
153}
154/* }}} */
155
156/* {{{ Checks for any printable character which is not whitespace or an alphanumeric character */
158{
159 ctype_impl(ispunct, 0, 0);
160}
161/* }}} */
162
163/* {{{ Checks for whitespace character(s)*/
165{
166 ctype_impl(isspace, 0, 0);
167}
168/* }}} */
169
170/* {{{ Checks for uppercase character(s) */
172{
173 ctype_impl(isupper, 0, 0);
174}
175/* }}} */
176
177/* {{{ Checks for character(s) representing a hexadecimal digit */
179{
180 ctype_impl(isxdigit, 1, 0);
181}
182/* }}} */
183
184#endif /* HAVE_CTYPE */
ctype_print(mixed $text)
ctype_xdigit(mixed $text)
ctype_lower(mixed $text)
ctype_alpha(mixed $text)
Definition ctype.stub.php:7
ctype_punct(mixed $text)
ctype_cntrl(mixed $text)
Definition ctype.stub.php:9
ctype_graph(mixed $text)
ctype_alnum(mixed $text)
Definition ctype.stub.php:5
ctype_upper(mixed $text)
ctype
Definition ffi.c:4208
#define NULL
Definition gdcache.h:45
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
Definition main.c:1173
#define ctype_digit
#define ctype_space
php_info_print_table_start()
Definition info.c:1064
php_info_print_table_row(2, "PDO Driver for Firebird", "enabled")
php_info_print_table_end()
Definition info.c:1074
#define PHP_FUNCTION
Definition php.h:364
#define PHP_MINFO
Definition php.h:396
#define PHP_MINFO_FUNCTION
Definition php.h:404
#define PHP_CTYPE_VERSION
Definition php_ctype.h:21
ZEND_API const char * zend_zval_type_name(const zval *arg)
Definition zend_API.c:167
#define RETURN_FALSE
Definition zend_API.h:1058
#define ZEND_GET_MODULE(name)
Definition zend_API.h:241
#define RETURN_BOOL(b)
Definition zend_API.h:1035
struct _zval_struct zval
#define E_DEPRECATED
Definition zend_errors.h:37
#define STANDARD_MODULE_HEADER
struct _zend_module_entry zend_module_entry
#define STANDARD_MODULE_PROPERTIES
#define zend_never_inline
#define Z_TYPE_P(zval_p)
Definition zend_types.h:660
#define IS_LONG
Definition zend_types.h:604
#define Z_LVAL_P(zval_p)
Definition zend_types.h:966
zval * return_value