Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Tokenizer.php

function Tokenizer::consumeData

Consume a character and make a move. HTML5 8.2.4.1.

1 call to Tokenizer::consumeData()
Tokenizer::parse in vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php
Begin parsing.

File

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

Class

Tokenizer
The HTML5 tokenizer.

Namespace

Masterminds\HTML5\Parser

Code

protected function consumeData() {
    $tok = $this->scanner
        ->current();
    if ('&' === $tok) {
        // Character reference
        $ref = $this->decodeCharacterReference();
        $this->buffer($ref);
        $tok = $this->scanner
            ->current();
    }
    // Parse tag
    if ('<' === $tok) {
        // Any buffered text data can go out now.
        $this->flushBuffer();
        $tok = $this->scanner
            ->next();
        if (false === $tok) {
            // end of string
            $this->parseError('Illegal tag opening');
        }
        elseif ('!' === $tok) {
            $this->markupDeclaration();
        }
        elseif ('/' === $tok) {
            $this->endTag();
        }
        elseif ('?' === $tok) {
            $this->processingInstruction();
        }
        elseif ($this->is_alpha($tok)) {
            $this->tagName();
        }
        else {
            $this->parseError('Illegal tag opening');
            // TODO is this necessary ?
            $this->characterData();
        }
        $tok = $this->scanner
            ->current();
    }
    if (false === $tok) {
        // Handle end of document
        $this->eof();
    }
    else {
        // Parse character
        switch ($this->textMode) {
            case Elements::TEXT_RAW:
                $this->rawText($tok);
                break;
            case Elements::TEXT_RCDATA:
                $this->rcdata($tok);
                break;
            default:
                if ('<' === $tok || '&' === $tok) {
                    break;
                }
                // NULL character
                if ("\x00" === $tok) {
                    $this->parseError('Received null character.');
                    $this->text .= $tok;
                    $this->scanner
                        ->consume();
                    break;
                }
                $this->text .= $this->scanner
                    ->charsUntil("<&\x00");
        }
    }
    return $this->carryOn;
}
RSS feed
Powered by Drupal