From 4c337c89096d9acb798f68201d2b124860d1616e Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sat, 24 Nov 2018 18:35:02 +0100 Subject: Simplify the doctype matching - the doctype() function is only called for a D or d token, so there is no need to check again inside the method - checking that we have the DOCTYPE string can use a sequence matching --- src/HTML5/Parser/Tokenizer.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/HTML5') diff --git a/src/HTML5/Parser/Tokenizer.php b/src/HTML5/Parser/Tokenizer.php index 74d86a3..bba6ff2 100644 --- a/src/HTML5/Parser/Tokenizer.php +++ b/src/HTML5/Parser/Tokenizer.php @@ -721,12 +721,11 @@ class Tokenizer */ protected function doctype() { - if (strcasecmp($this->scanner->current(), 'D')) { - return false; - } // Check that string is DOCTYPE. - $chars = $this->scanner->charsWhile('DOCTYPEdoctype'); - if (strcasecmp($chars, 'DOCTYPE')) { + if ($this->scanner->sequenceMatches('DOCTYPE', false)) { + $this->scanner->consume(7); + } else { + $chars = $this->scanner->charsWhile('DOCTYPEdoctype'); $this->parseError('Expected DOCTYPE, got %s', $chars); return $this->bogusComment('