/** * 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 int * The column number. */ 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); }