-
Notifications
You must be signed in to change notification settings - Fork 1
/
ctype.php
189 lines (158 loc) · 6.19 KB
/
ctype.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?hh // strict
namespace HackUtils;
class TestCtype extends Test {
public function run(): void {
self::assertEqual(all_alnum(''), true);
self::assertEqual(all_blank(''), true);
self::assertEqual(all_alpha(''), true);
self::assertEqual(all_cntrl(''), true);
self::assertEqual(all_digit(''), true);
self::assertEqual(all_graph(''), true);
self::assertEqual(all_lower(''), true);
self::assertEqual(all_print(''), true);
self::assertEqual(all_punct(''), true);
self::assertEqual(all_space(''), true);
self::assertEqual(all_upper(''), true);
self::assertEqual(all_xdigit(''), true);
self::assertEqual(all_alnum("\x00"), false);
self::assertEqual(all_blank("\x00"), false);
self::assertEqual(all_alpha("\x00"), false);
self::assertEqual(all_cntrl("\x00"), true);
self::assertEqual(all_digit("\x00"), false);
self::assertEqual(all_graph("\x00"), false);
self::assertEqual(all_lower("\x00"), false);
self::assertEqual(all_print("\x00"), false);
self::assertEqual(all_punct("\x00"), false);
self::assertEqual(all_space("\x00"), false);
self::assertEqual(all_upper("\x00"), false);
self::assertEqual(all_xdigit("\x00"), false);
self::assertEqual(all_alnum("hd8whASDe1"), true);
self::assertEqual(all_blank(" \t\t \t"), true);
self::assertEqual(all_alpha("jashbAUJSHYBDef"), true);
self::assertEqual(all_cntrl("\x00\r\v\f\t\n\r"), true);
self::assertEqual(all_digit("24976230"), true);
self::assertEqual(all_graph("$%&'(56?@NO]^bclmn|"), true);
self::assertEqual(all_lower("jefjwehfasd"), true);
self::assertEqual(all_print("$%&'(56?@NO]^bclmn| "), true);
self::assertEqual(all_punct("$%&'(?@]^|"), true);
self::assertEqual(all_space("\r\v\f\t\n\r "), true);
self::assertEqual(all_upper("AHBFJHEBFOIAS"), true);
self::assertEqual(all_xdigit("98234ABCabdfDEF"), true);
self::assertEqual(all_alnum("hd8,whASDe1"), false);
self::assertEqual(all_blank(" \t\td \t"), false);
self::assertEqual(all_alpha("jashbA|UJSHYBDef"), false);
self::assertEqual(all_cntrl("\x00\rf\v\f\t\n\r"), false);
self::assertEqual(all_digit("24976d230"), false);
self::assertEqual(all_graph("$%&'(5 6?@\tNO]^bclmn|"), false);
self::assertEqual(all_lower("jefjwehfDasd"), false);
self::assertEqual(all_print("$%&'(56?@\r\tNO]^bclmn| "), false);
self::assertEqual(all_punct("$%&'(?@da]^|"), false);
self::assertEqual(all_space("\r\v\f\tp\n\r "), false);
self::assertEqual(all_upper("AHBFJHEBasdFOIAS"), false);
self::assertEqual(all_xdigit("98234ABCDEFGHIJklm"), false);
self::assertEqual(is_alnum("hd8,whASDe1", 3), false);
self::assertEqual(is_blank(" \t\td \t", 5), false);
self::assertEqual(is_alpha("jashbA|UJSHYBDef", 6), false);
self::assertEqual(is_cntrl("\x00\rf\v\f\t\n\r", 2), false);
self::assertEqual(is_digit("24976d230", 5), false);
self::assertEqual(is_graph("$%&'(5 6?@\tNO]^bclmn|", 6), false);
self::assertEqual(is_lower("jefjwehfDasd", 8), false);
self::assertEqual(is_print("$%&'(56?@\r\tNO]^bclmn| ", 9), false);
self::assertEqual(is_punct("$%&'(?@da]^|", 8), false);
self::assertEqual(is_space("\r\v\f\tp\n\r ", 4), false);
self::assertEqual(is_upper("AHBFJHEBasdFOIAS", 10), false);
self::assertEqual(is_xdigit("98234ABCDEFGHIJklm", 11), false);
self::assertEqual(is_alnum("hd8,whASDe1", 2), true);
self::assertEqual(is_blank(" \t\td \t", 8), true);
self::assertEqual(is_alpha("jashbA|UJSHYBDef", 2), true);
self::assertEqual(is_cntrl("\x00\rf\v\f\t\n\r", 6), true);
self::assertEqual(is_digit("24976d230", 3), true);
self::assertEqual(is_graph("$%&'(5 6?@\tNO]^bclmn|", 8), true);
self::assertEqual(is_lower("jefjwehfDasd", 5), true);
self::assertEqual(is_print("$%&'(56?@\r\tNO]^bclmn| ", 13), true);
self::assertEqual(is_punct("$%&'(?@da]^|", 4), true);
self::assertEqual(is_space("\r\v\f\tp\n\r ", 6), true);
self::assertEqual(is_upper("AHBFJHEBasdFOIAS", 4), true);
self::assertEqual(is_xdigit("98234ABCDEFGHIJklm", 5), true);
}
}
function all_alnum(string $s): bool {
return $s === '' || \ctype_alnum($s);
}
function all_blank(string $s): bool {
$l = \strlen($s);
for ($i = 0; $i < $l; $i++) {
$c = $s[$i];
if ($c !== "\t" && $c !== " ") {
return false;
}
}
return true;
}
function all_alpha(string $s): bool {
return $s === '' || \ctype_alpha($s);
}
function all_cntrl(string $s): bool {
return $s === '' || \ctype_cntrl($s);
}
function all_digit(string $s): bool {
return $s === '' || \ctype_digit($s);
}
function all_graph(string $s): bool {
return $s === '' || \ctype_graph($s);
}
function all_lower(string $s): bool {
return $s === '' || \ctype_lower($s);
}
function all_print(string $s): bool {
return $s === '' || \ctype_print($s);
}
function all_punct(string $s): bool {
return $s === '' || \ctype_punct($s);
}
function all_space(string $s): bool {
return $s === '' || \ctype_space($s);
}
function all_upper(string $s): bool {
return $s === '' || \ctype_upper($s);
}
function all_xdigit(string $s): bool {
return $s === '' || \ctype_xdigit($s);
}
function is_alnum(string $s, int $i = 0): bool {
return \ctype_alnum(char_at($s, $i));
}
function is_blank(string $s, int $i = 0): bool {
$c = char_at($s, $i);
return $c === ' ' || $c === "\t";
}
function is_alpha(string $s, int $i = 0): bool {
return \ctype_alpha(char_at($s, $i));
}
function is_cntrl(string $s, int $i = 0): bool {
return \ctype_cntrl(char_at($s, $i));
}
function is_digit(string $s, int $i = 0): bool {
return \ctype_digit(char_at($s, $i));
}
function is_graph(string $s, int $i = 0): bool {
return \ctype_graph(char_at($s, $i));
}
function is_lower(string $s, int $i = 0): bool {
return \ctype_lower(char_at($s, $i));
}
function is_print(string $s, int $i = 0): bool {
return \ctype_print(char_at($s, $i));
}
function is_punct(string $s, int $i = 0): bool {
return \ctype_punct(char_at($s, $i));
}
function is_space(string $s, int $i = 0): bool {
return \ctype_space(char_at($s, $i));
}
function is_upper(string $s, int $i = 0): bool {
return \ctype_upper(char_at($s, $i));
}
function is_xdigit(string $s, int $i = 0): bool {
return \ctype_xdigit(char_at($s, $i));
}