aboutsummaryrefslogtreecommitdiff
path: root/src/Search/CharSource.php
diff options
context:
space:
mode:
authorLaria Carolin Chabowski <laria@laria.me>2020-02-07 09:44:59 +0100
committerLaria Carolin Chabowski <laria@laria.me>2020-02-07 09:44:59 +0100
commit2eb5a432d2229788ce2fdb09f36c6f4bebdea813 (patch)
treeab57978bdda34c82b025b897cfb6825b1fd1e654 /src/Search/CharSource.php
downloadmicropoly-2eb5a432d2229788ce2fdb09f36c6f4bebdea813.tar.gz
micropoly-2eb5a432d2229788ce2fdb09f36c6f4bebdea813.tar.bz2
micropoly-2eb5a432d2229788ce2fdb09f36c6f4bebdea813.zip
Initial commit
Diffstat (limited to 'src/Search/CharSource.php')
-rw-r--r--src/Search/CharSource.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/Search/CharSource.php b/src/Search/CharSource.php
new file mode 100644
index 0000000..165e538
--- /dev/null
+++ b/src/Search/CharSource.php
@@ -0,0 +1,33 @@
+<?php
+
+
+namespace Micropoly\Search;
+
+
+class CharSource
+{
+ private string $s;
+ private int $i = 0;
+ private int $len;
+
+ public function __construct(string $s)
+ {
+ $this->s = $s;
+ $this->len = mb_strlen($s);
+ }
+
+ public function getNext(): ?string
+ {
+ if ($this->i >= $this->len)
+ return null;
+
+ $c = mb_substr($this->s, $this->i, 1);
+ $this->i++;
+ return $c;
+ }
+
+ public function unget(): void
+ {
+ $this->i = max(0, $this->i - 1);
+ }
+} \ No newline at end of file