Chris@0: is = $input; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Get the current position. Chris@0: * Chris@0: * @return int The current intiger byte position. Chris@0: */ Chris@0: public function position() Chris@0: { Chris@0: return $this->is->key(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Take a peek at the next character in the data. Chris@0: * Chris@0: * @return string The next character. Chris@0: */ Chris@0: public function peek() Chris@0: { Chris@0: return $this->is->peek(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Get the next character. Chris@0: * Chris@0: * Note: This advances the pointer. Chris@0: * Chris@0: * @return string The next character. Chris@0: */ Chris@0: public function next() Chris@0: { Chris@0: $this->is->next(); Chris@0: if ($this->is->valid()) { Chris@0: if ($this->debug) Chris@0: fprintf(STDOUT, "> %s\n", $this->is->current()); Chris@0: return $this->is->current(); Chris@0: } Chris@0: Chris@0: return false; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Get the current character. Chris@0: * Chris@0: * Note, this does not advance the pointer. Chris@0: * Chris@0: * @return string The current character. Chris@0: */ Chris@0: public function current() Chris@0: { Chris@0: if ($this->is->valid()) { Chris@0: return $this->is->current(); Chris@0: } Chris@0: Chris@0: return false; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Silently consume N chars. Chris@0: */ Chris@0: public function consume($count = 1) Chris@0: { Chris@0: for ($i = 0; $i < $count; ++ $i) { Chris@0: $this->next(); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Unconsume some of the data. Chris@0: * This moves the data pointer backwards. Chris@0: * Chris@0: * @param int $howMany Chris@0: * The number of characters to move the pointer back. Chris@0: */ Chris@0: public function unconsume($howMany = 1) Chris@0: { Chris@0: $this->is->unconsume($howMany); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Get the next group of that contains hex characters. Chris@0: * Chris@0: * Note, along with getting the characters the pointer in the data will be Chris@0: * moved as well. Chris@0: * Chris@0: * @return string The next group that is hex characters. Chris@0: */ Chris@0: public function getHex() Chris@0: { Chris@0: return $this->is->charsWhile(static::CHARS_HEX); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Get the next group of characters that are ASCII Alpha characters. Chris@0: * Chris@0: * Note, along with getting the characters the pointer in the data will be Chris@0: * moved as well. Chris@0: * Chris@0: * @return string The next group of ASCII alpha characters. Chris@0: */ Chris@0: public function getAsciiAlpha() Chris@0: { Chris@0: return $this->is->charsWhile(static::CHARS_ALPHA); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Get the next group of characters that are ASCII Alpha characters and numbers. Chris@0: * Chris@0: * Note, along with getting the characters the pointer in the data will be Chris@0: * moved as well. Chris@0: * Chris@0: * @return string The next group of ASCII alpha characters and numbers. Chris@0: */ Chris@0: public function getAsciiAlphaNum() Chris@0: { Chris@0: return $this->is->charsWhile(static::CHARS_ALNUM); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Get the next group of numbers. Chris@0: * Chris@0: * Note, along with getting the characters the pointer in the data will be Chris@0: * moved as well. Chris@0: * Chris@0: * @return string The next group of numbers. Chris@0: */ Chris@0: public function getNumeric() Chris@0: { Chris@0: return $this->is->charsWhile('0123456789'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Consume whitespace. Chris@0: * Chris@0: * Whitespace in HTML5 is: formfeed, tab, newline, space. Chris@0: */ Chris@0: public function whitespace() Chris@0: { Chris@0: return $this->is->charsWhile("\n\t\f "); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the current line that is being consumed. Chris@0: * Chris@0: * @return int The current line number. Chris@0: */ Chris@0: public function currentLine() Chris@0: { Chris@0: return $this->is->currentLine(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Read chars until something in the mask is encountered. Chris@0: */ Chris@0: public function charsUntil($mask) Chris@0: { Chris@0: return $this->is->charsUntil($mask); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Read chars as long as the mask matches. Chris@0: */ Chris@0: public function charsWhile($mask) Chris@0: { Chris@0: return $this->is->charsWhile($mask); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the current column of the current line that the tokenizer is at. Chris@0: * Chris@0: * Newlines are column 0. The first char after a newline is column 1. Chris@0: * Chris@0: * @return int The column number. Chris@0: */ Chris@0: public function columnOffset() Chris@0: { Chris@0: return $this->is->columnOffset(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Get all characters until EOF. Chris@0: * Chris@0: * This consumes characters until the EOF. Chris@0: * Chris@0: * @return int The number of characters remaining. Chris@0: */ Chris@0: public function remainingChars() Chris@0: { Chris@0: return $this->is->remainingChars(); Chris@0: } Chris@0: }