You are here

public function StringInputStream::columnOffset in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/masterminds/html5/src/HTML5/Parser/StringInputStream.php \Masterminds\HTML5\Parser\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 139

Class

StringInputStream

Namespace

Masterminds\HTML5\Parser

Code

public function columnOffset() {

  // Short circuit for the first char.
  if ($this->char == 0) {
    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 ($lastLine !== false) {
    $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);
}