public function copyUntil($string, $char = false, $escape = false)
{
if ($this->pos >= $this->size) {
// nothing left
return '';
}
if ($escape) {
$position = $this->pos;
$found = false;
while (!$found) {
$position = strpos($this->content, $string, $position);
if ($position === false) {
// reached the end
$found = true;
continue;
}
if ($this->char($position - 1) == '\\') {
// this character is escaped
++$position;
continue;
}
$found = true;
}
} elseif ($char) {
$position = strcspn($this->content, $string, $this->pos);
$position += $this->pos;
} else {
$position = strpos($this->content, $string, $this->pos);
}
if ($position === false) {
// could not find character, just return the remaining of the content
$return = substr($this->content, $this->pos, $this->size - $this->pos);
$this->pos = $this->size;
return $return;
}
if ($position == $this->pos) {
// we are at the right place
return '';
}
$return = substr($this->content, $this->pos, $position - $this->pos);
// set the new position
$this->pos = $position;
return $return;
}