2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 | Copyright (c) 1997-2010 The PHP Group |
7 +----------------------------------------------------------------------+
8 | This source file is subject to version 3.01 of the PHP license, |
9 | that is bundled with this package in the file LICENSE, and is |
10 | available through the world-wide-web at the following url: |
11 | http://www.php.net/license/3_01.txt |
12 | If you did not receive a copy of the PHP license and are unable to |
13 | obtain it through the world-wide-web, please send a note to |
14 | license@php.net so we can mail you a copy immediately. |
15 +----------------------------------------------------------------------+
18 #include "hphp/runtime/ext/extension.h"
22 ///////////////////////////////////////////////////////////////////////////////
24 static bool ctype(const Variant
& v
, int (*iswhat
)(int)) {
26 int64_t n
= v
.toInt64();
27 if (n
<= 255 && n
>= 0) {
31 if (n
>= -128 && n
< 0) {
32 return iswhat(n
+ 256);
35 return ctype(v
.toString(), iswhat
);
39 String s
= v
.toString();
41 const char *p
= s
.data();
42 const char *e
= s
.data() + s
.size();
44 if (!iswhat((int)*(unsigned char *)(p
++))) {
54 // Use lambdas wrapping the ctype.h functions because of linker weirdness on
57 bool HHVM_FUNCTION(ctype_alnum
, const Variant
& text
) {
58 return ctype(text
, [] (int i
) -> int { return isalnum(i
); });
61 bool HHVM_FUNCTION(ctype_alpha
, const Variant
& text
) {
62 return ctype(text
, [] (int i
) -> int { return isalpha(i
); });
65 bool HHVM_FUNCTION(ctype_cntrl
, const Variant
& text
) {
66 return ctype(text
, [] (int i
) -> int { return iscntrl(i
); });
69 bool HHVM_FUNCTION(ctype_digit
, const Variant
& text
) {
70 return ctype(text
, [] (int i
) -> int { return isdigit(i
); });
73 bool HHVM_FUNCTION(ctype_graph
, const Variant
& text
) {
74 return ctype(text
, [] (int i
) -> int { return isgraph(i
); });
77 bool HHVM_FUNCTION(ctype_lower
, const Variant
& text
) {
78 return ctype(text
, [] (int i
) -> int { return islower(i
); });
81 bool HHVM_FUNCTION(ctype_print
, const Variant
& text
) {
82 return ctype(text
, [] (int i
) -> int { return isprint(i
); });
85 bool HHVM_FUNCTION(ctype_punct
, const Variant
& text
) {
86 return ctype(text
, [] (int i
) -> int { return ispunct(i
); });
89 bool HHVM_FUNCTION(ctype_space
, const Variant
& text
) {
90 return ctype(text
, [] (int i
) -> int { return isspace(i
); });
93 bool HHVM_FUNCTION(ctype_upper
, const Variant
& text
) {
94 return ctype(text
, [] (int i
) -> int { return isupper(i
); });
97 bool HHVM_FUNCTION(ctype_xdigit
, const Variant
& text
) {
98 return ctype(text
, [] (int i
) -> int { return isxdigit(i
); });
101 ///////////////////////////////////////////////////////////////////////////////
103 struct CtypeExtension final
: Extension
{
104 CtypeExtension() : Extension("ctype") {}
105 void moduleInit() override
{
106 HHVM_FE(ctype_alnum
);
107 HHVM_FE(ctype_alpha
);
108 HHVM_FE(ctype_cntrl
);
109 HHVM_FE(ctype_digit
);
110 HHVM_FE(ctype_graph
);
111 HHVM_FE(ctype_lower
);
112 HHVM_FE(ctype_print
);
113 HHVM_FE(ctype_punct
);
114 HHVM_FE(ctype_space
);
115 HHVM_FE(ctype_upper
);
116 HHVM_FE(ctype_xdigit
);
122 ///////////////////////////////////////////////////////////////////////////////