xref: /plugin/totext/vendor/prinsfrank/pdfparser/src/Document/Generic/Parsing/InfiniteBuffer.php (revision 0fbee1892eb8b7339ce48e27e48e3fc821a8695f)
1<?php
2declare(strict_types=1);
3
4namespace PrinsFrank\PdfParser\Document\Generic\Parsing;
5
6use Override;
7
8/** @internal */
9class InfiniteBuffer {
10    private string $buffer = '';
11
12    public function addChar(string $char): self {
13        $this->buffer .= $char;
14
15        return $this;
16    }
17
18    public function flush(): self {
19        return $this->setValue('');
20    }
21
22    #[Override]
23    public function __toString(): string {
24        return $this->buffer;
25    }
26
27    public function getLength(): int {
28        return strlen($this->buffer);
29    }
30
31    public function isEmpty(): bool {
32        return $this->getLength() === 0;
33    }
34
35    public function setValue(string $buffer): self {
36        $this->buffer = $buffer;
37
38        return $this;
39    }
40
41    public function removeChar(int $nChars): self {
42        if ($this->buffer !== '') {
43            $this->buffer = substr($this->buffer, 0, -$nChars);
44        }
45
46        return $this;
47    }
48}
49