Skip to content

Commit

Permalink
Merge pull request #206 from alecpl/drop-ctype
Browse files Browse the repository at this point in the history
Get rid of ctype
  • Loading branch information
goetas committed Jan 19, 2023
2 parents 8eddcaa + f73ff86 commit 3d02e3a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
}
],
"require" : {
"ext-ctype": "*",
"ext-dom": "*",
"php" : ">=5.3.0"
},
Expand Down
18 changes: 16 additions & 2 deletions src/HTML5/Parser/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected function consumeData()
$this->endTag();
} elseif ('?' === $tok) {
$this->processingInstruction();
} elseif (ctype_alpha($tok)) {
} elseif ($this->is_alpha($tok)) {
$this->tagName();
} else {
$this->parseError('Illegal tag opening');
Expand Down Expand Up @@ -347,7 +347,7 @@ protected function endTag()
// > -> parse error
// EOF -> parse error
// -> parse error
if (!ctype_alpha($tok)) {
if (!$this->is_alpha($tok)) {
$this->parseError("Expected tag name, got '%s'", $tok);
if ("\0" == $tok || false === $tok) {
return false;
Expand Down Expand Up @@ -1194,4 +1194,18 @@ protected function decodeCharacterReference($inAttribute = false)

return '&';
}

/**
* Checks whether a (single-byte) character is an ASCII letter or not.
*
* @param string $input A single-byte string
*
* @return bool True if it is a letter, False otherwise
*/
protected function is_alpha($input)
{
$code = ord($input);

return ($code >= 97 && $code <= 122) || ($code >= 65 && $code <= 90);
}
}

0 comments on commit 3d02e3a

Please sign in to comment.