This repository has been archived on 2023-10-21. You can view files and clone it, but cannot push or open issues or pull requests.
patchouli/lib/FWIF/FWIFDecodeStream.php
2020-12-24 03:25:10 +00:00

43 lines
1 KiB
PHP

<?php
namespace FWIF;
class FWIFDecodeStream {
private string $body;
private int $length;
private int $position = 0;
public function __construct(string $body) {
$this->body = $body;
$this->length = strlen($body);
}
public function getLength(): int {
return $this->length;
}
public function getPosition(): int {
return $this->position;
}
public function stepBack(): void {
$this->position = max(0, $this->position - 1);
}
public function readByte(): int {
if($this->position + 1 >= $this->length)
return FWIF::TRAILER;
return ord($this->body[$this->position++]);
}
public function readChar(): string {
return chr($this->readByte());
}
public function readString(int $length): string {
// Bounds checks? What are those?
$string = substr($this->body, $this->position, $length);
$this->position += $length;
return $string;
}
}