Skip to content

Commit 3d02e3a

Browse files
authored
Merge pull request #206 from alecpl/drop-ctype
Get rid of ctype
2 parents 8eddcaa + f73ff86 commit 3d02e3a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
}
2121
],
2222
"require" : {
23-
"ext-ctype": "*",
2423
"ext-dom": "*",
2524
"php" : ">=5.3.0"
2625
},

src/HTML5/Parser/Tokenizer.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected function consumeData()
137137
$this->endTag();
138138
} elseif ('?' === $tok) {
139139
$this->processingInstruction();
140-
} elseif (ctype_alpha($tok)) {
140+
} elseif ($this->is_alpha($tok)) {
141141
$this->tagName();
142142
} else {
143143
$this->parseError('Illegal tag opening');
@@ -347,7 +347,7 @@ protected function endTag()
347347
// > -> parse error
348348
// EOF -> parse error
349349
// -> parse error
350-
if (!ctype_alpha($tok)) {
350+
if (!$this->is_alpha($tok)) {
351351
$this->parseError("Expected tag name, got '%s'", $tok);
352352
if ("\0" == $tok || false === $tok) {
353353
return false;
@@ -1194,4 +1194,18 @@ protected function decodeCharacterReference($inAttribute = false)
11941194

11951195
return '&';
11961196
}
1197+
1198+
/**
1199+
* Checks whether a (single-byte) character is an ASCII letter or not.
1200+
*
1201+
* @param string $input A single-byte string
1202+
*
1203+
* @return bool True if it is a letter, False otherwise
1204+
*/
1205+
protected function is_alpha($input)
1206+
{
1207+
$code = ord($input);
1208+
1209+
return ($code >= 97 && $code <= 122) || ($code >= 65 && $code <= 90);
1210+
}
11971211
}

0 commit comments

Comments
 (0)