diff options
author | Matt Farina <[email protected]> | 2013-04-10 13:07:49 -0400 |
---|---|---|
committer | Matt Farina <[email protected]> | 2013-04-10 13:10:34 -0400 |
commit | f9590a91ad948db1449a3dc61d90e9c9a71c6ee3 (patch) | |
tree | 87006cac96ef39ee5336ea24ec38ea7785c1c9ac /src/HTML5/Parser/StringInputStream.php | |
parent | fe956dc6bdbf3e71336bbff250ddff7f370e1f93 (diff) |
Moved the scanner to the new Parser InputStream and updated the unit tests to use StringInputStream
Diffstat (limited to 'src/HTML5/Parser/StringInputStream.php')
-rw-r--r-- | src/HTML5/Parser/StringInputStream.php | 62 |
1 files changed, 45 insertions, 17 deletions
diff --git a/src/HTML5/Parser/StringInputStream.php b/src/HTML5/Parser/StringInputStream.php index 4ceae44..e26bb38 100644 --- a/src/HTML5/Parser/StringInputStream.php +++ b/src/HTML5/Parser/StringInputStream.php @@ -269,16 +269,40 @@ class StringInputStream implements InputStream { } /** - * Retrieve the currently consumed character. - * @note This performs bounds checking + * Get the current character. + * + * @return string + * The current character. + */ + public function current() { + return $this->data[$this->char]; + } + + /** + * Advance the pointer. This is part of the Iterator interface. + */ + public function next() { + $this->char++; + } + + /** + * Rewind to the start of the string. + */ + public function rewind() { + $this->char = 0; + } + + /** + * Is the current pointer location valid. + * + * @return bool + * Is the current pointer location valid. */ - public function char() { - // MPB: This appears to advance the pointer, which is not the same - // as "retrieving the currently consumed character". Calling char() - // twice will return two different results. - if ($this->char++ < $this->EOF) { - return $this->data[$this->char - 1]; + public function valid() { + if ($this->char < $this->EOF) { + return TRUE; } + return FALSE; } @@ -362,22 +386,26 @@ class StringInputStream implements InputStream { } /** - * Unconsume one character. + * Unconsume characters. + * + * @param int $howMany + * The number of characters to unconsume. */ - public function unconsume() { - if ($this->char > 0 && $this->char <= $this->EOF) { - $this->char--; + public function unconsume($howMany = 1) { + if (($this->char - $howMany) >= 0) { + $this->char = $this->char - $howMany; } } - public function unget() { - $this->unconsume(); - } public function peek() { - return $this->data[$this->char + 1]; + if (($this->char + 1) <= $this->EOF) { + return $this->data[$this->char + 1]; + } + + return FALSE; } - public function position() { + public function key() { return $this->char; } } |