},
{
"name": "phpunit/php-token-stream",
- "version": "1.2.1",
+ "version": "1.2.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-token-stream.git",
- "reference": "5220af2a7929aa35cf663d97c89ad3d50cf5fa3e"
+ "reference": "ad4e1e23ae01b483c16f600ff1bebec184588e32"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/5220af2a7929aa35cf663d97c89ad3d50cf5fa3e",
- "reference": "5220af2a7929aa35cf663d97c89ad3d50cf5fa3e",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/ad4e1e23ae01b483c16f600ff1bebec184588e32",
+ "reference": "ad4e1e23ae01b483c16f600ff1bebec184588e32",
"shasum": ""
},
"require": {
"keywords": [
"tokenizer"
],
- "time": "2013-09-13 04:58:23"
+ "time": "2014-03-03 05:10:30"
},
{
"name": "phpunit/phpunit",
--- /dev/null
+<?php
+
+namespace PFF\IO;
+
+interface PushBackInputStream
+{
+ public function close();
+ public function getc();
+ public function ungetc($char);
+}
+
+class FileInputStream implements PushBackInputStream
+{
+ private $fd, $buffer = array();
+
+ public function __construct($path, $mode)
+ {
+ $this->fd = fopen($path, $mode);
+ }
+
+ public function __destruct()
+ {
+ $this->close();
+ }
+
+ public function close()
+ {
+ if ($this->fd) {
+ fclose($this->fd);
+ $this->fd = null;
+ }
+ }
+
+ public function getc()
+ {
+ if (count($this->buffer)) {
+ return array_shift($this->buffer);
+ } else {
+ return fgetc($this->fd);
+ }
+ }
+
+ public function ungetc($char)
+ {
+ array_unshift($this->buffer, $char);
+ }
+}
+
+class StringInputStream implements PushBackInputStream
+{
+ private $string, $position;
+
+ public function __construct($string)
+ {
+ $this->string = $string;
+ $this->position = 0;
+ }
+
+ public function close()
+ {
+ if ($this->string !== null)
+ $this->string = null;
+ }
+
+ public function getc()
+ {
+ if ($this->position >= strlen($this->string))
+ return false;
+ else
+ return $this->string[$this->position++];
+ }
+
+ public function ungetc($char)
+ {
+ --$this->position;
+ }
+}
+