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

Breadcrumb

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

function StringInputStream::columnOffset

Returns the current column of the current line that the tokenizer is at. Newlines are column 0. The first char after a newline is column 1.

Return value

int The column number.

Overrides InputStream::columnOffset

1 call to StringInputStream::columnOffset()
StringInputStream::getColumnOffset in vendor/masterminds/html5/src/HTML5/Parser/StringInputStream.php

File

vendor/masterminds/html5/src/HTML5/Parser/StringInputStream.php, line 147

Class

StringInputStream

Namespace

Masterminds\HTML5\Parser

Code

public function columnOffset() {
    // Short circuit for the first char.
    if (0 === $this->char) {
        return 0;
    }
    // strrpos is weird, and the offset needs to be negative for what we
    // want (i.e., the last \n before $this->char). This needs to not have
    // one (to make it point to the next character, the one we want the
    // position of) added to it because strrpos's behaviour includes the
    // final offset byte.
    $backwardFrom = $this->char - 1 - strlen($this->data);
    $lastLine = strrpos($this->data, "\n", $backwardFrom);
    // However, for here we want the length up until the next byte to be
    // processed, so add one to the current byte ($this->char).
    if (false !== $lastLine) {
        $findLengthOf = substr($this->data, $lastLine + 1, $this->char - 1 - $lastLine);
    }
    else {
        // After a newline.
        $findLengthOf = substr($this->data, 0, $this->char);
    }
    return UTF8Utils::countChars($findLengthOf);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal