You are here

protected function Tokenizer::sequenceMatches in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php \Masterminds\HTML5\Parser\Tokenizer::sequenceMatches()

Check if upcomming chars match the given sequence.

This will read the stream for the $sequence. If it's found, this will return true. If not, return false. Since this unconsumes any chars it reads, the caller will still need to read the next sequence, even if this returns true.

Example: $this->sequenceMatches('</script>') will see if the input stream is at the start of a '</script>' string.

3 calls to Tokenizer::sequenceMatches()
Tokenizer::cdataSection in vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php
Handle a CDATA section.
Tokenizer::rcdata in vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php
Read text in RCDATA mode.
Tokenizer::readUntilSequence in vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php
Read from the input stream until we get to the desired sequene or hit the end of the input stream.

File

vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php, line 928

Class

Tokenizer
The HTML5 tokenizer.

Namespace

Masterminds\HTML5\Parser

Code

protected function sequenceMatches($sequence, $caseSensitive = true) {
  $len = strlen($sequence);
  $buffer = '';
  for ($i = 0; $i < $len; ++$i) {
    $buffer .= $this->scanner
      ->current();

    // EOF. Rewind and let the caller handle it.
    if ($this->scanner
      ->current() === false) {
      $this->scanner
        ->unconsume($i);
      return false;
    }
    $this->scanner
      ->next();
  }
  $this->scanner
    ->unconsume($len);
  return $caseSensitive ? $buffer == $sequence : strcasecmp($buffer, $sequence) === 0;
}