diff --git a/src/LTDBeget/stringstream/StringStream.php b/src/LTDBeget/stringstream/StringStream.php index addc4c2..872e55b 100644 --- a/src/LTDBeget/stringstream/StringStream.php +++ b/src/LTDBeget/stringstream/StringStream.php @@ -30,11 +30,11 @@ public function __construct(string $string) /** * Current char of stream - * @return string + * @return string|null */ - public function current() : string + public function current() { - return current($this->stream); + return $this->stream->current(); } /** @@ -62,7 +62,7 @@ public function currentAscii() : AsciiChar */ public function position() : int { - return key($this->stream); + return $this->stream->key(); } /** @@ -71,7 +71,12 @@ public function position() : int public function next() { $this->pointerAtStart = false; - $this->pointerAtEnd = next($this->stream) === false; + if ($this->stream->key() === $this->stream->count() - 1) { + $this->pointerAtEnd = true; + } else { + $this->pointerAtEnd = false; + $this->stream->next(); + } } /** @@ -80,7 +85,13 @@ public function next() public function previous() { $this->pointerAtEnd = false; - $this->pointerAtStart = prev($this->stream) === false; + $this->pointerAtStart = false; + if ($this->stream->key() == 0) { + $this->pointerAtStart = true; + } else { + $prevPos = $this->stream->key() - 1; + $this->stream->seek($prevPos); + } } /** @@ -88,7 +99,7 @@ public function previous() */ public function start() { - reset($this->stream); + $this->stream->rewind(); } /** @@ -105,7 +116,7 @@ public function isStart() : bool */ public function end() { - end($this->stream); + $this->stream->seek($this->stream->count() - 1); } /** @@ -169,7 +180,7 @@ private function makeIterator(string $string) : ArrayIterator } /** - * @var array + * @var ArrayIterator */ private $stream;