Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/LTDBeget/stringstream/StringStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ public function currentAscii() : AsciiChar
*/
public function position() : int
{
return key($this->stream);
return $this->stream->key();
}

/**
Expand All @@ -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();
}
}

/**
Expand All @@ -80,15 +85,21 @@ 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);
}
}

/**
* go to start of stream
*/
public function start()
{
reset($this->stream);
$this->stream->rewind();
}

/**
Expand All @@ -105,7 +116,7 @@ public function isStart() : bool
*/
public function end()
{
end($this->stream);
$this->stream->seek($this->stream->count() - 1);
}

/**
Expand Down Expand Up @@ -169,7 +180,7 @@ private function makeIterator(string $string) : ArrayIterator
}

/**
* @var array
* @var ArrayIterator
*/
private $stream;

Expand Down