setString($string, $index); } /** @var string la chaine à lire */ private $string; /** @var int longueur de la chaine */ private $length; /** @var int position de lecture dans la chaine */ private $index; private static function fix_index(int $index, int $length): int { if ($index < 0) { if ($length > 0) { while ($index < 0) $index += $length; } else { $index = 0; } } if ($index > $length) $index = $length; return $index; } function setString(?string $string, int $index=0) { if ($string === null) $string = ""; $length = strlen($string); $index = self::fix_index($index, $length); $this->string = $string; $this->index = $index; $this->length = $length; } function close(bool $close=true): void { } function getResource() { return null; } function appendFilter(string $filterName, ?int $readWrite=null, $params=null): void { } function prependFilter(string $filterName, ?int $readWrite=null, $params=null): void { } function setEncodingFilter(string $from, string $to = "utf-8"): void { } function seek(int $index=0, int $whence=SEEK_SET): int { if ($whence == SEEK_CUR) { $index = $this->index + $index; } elseif ($whence == SEEK_END) { $index = $this->length - $index; } return $this->index = self::fix_index($index, $this->length); } function readLine(): string { $index = $this->index; $length = $this->length; if ($index == $length) throw EOFException::no_more_data(); [$line, $this->index] = self::next_line($this->string, $index, $length); return $line; } protected function _next(&$key) { return $this->readLine(); } function key() { return $this->_key(); } function current() { return $this->_current(); } function getContents(bool $close=true): string { $contents = substr($this->string, $this->index); $this->index = $this->length; return $contents; } }