file =& $f; if (is_string($this->file)) { $this->_mode = 1; } $this->reset(); } // Optionally move the file // pointer to a new location // and reset the buffered data public function reset($pos = null, $l = 100) { if ($this->_mode == 0) { if (!is_null($pos)) { fseek($this->file, $pos); } $this->buffer = $l > 0 ? fread($this->file, $l) : ''; $this->length = strlen($this->buffer); if ($this->length < $l) { $this->increase_length($l - $this->length); } } else { $this->buffer = $this->file; $this->length = strlen($this->buffer); } $this->offset = 0; $this->stack = array(); } // Make sure that there is at least one // character beyond the current offset in // the buffer to prevent the tokenizer // from attempting to access data that does // not exist public function ensure_content() { if ($this->offset >= $this->length - 1) { return $this->increase_length(); } else { return true; } } // Forcefully read more data into the buffer public function increase_length($l = 100) { if ($this->_mode == 0 && feof($this->file)) { return false; } elseif ($this->_mode == 0) { $totalLength = $this->length + $l; do { $this->buffer .= fread($this->file, $totalLength-$this->length); } while ((($this->length = strlen($this->buffer)) != $totalLength) && !feof($this->file)); return true; } else { return false; } } } }