Changeset View
Changeset View
Standalone View
Standalone View
src/filesystem/linesofalarge/LinesOfALarge.php
Context not available. | |||||
* | * | ||||
* If your stream is not large, it is generally more efficient (and certainly | * If your stream is not large, it is generally more efficient (and certainly | ||||
* simpler) to read the entire stream first and then process it (e.g., with | * simpler) to read the entire stream first and then process it (e.g., with | ||||
* `explode()`). | * `@explode()`). | ||||
* | * | ||||
* This class is abstract. The concrete implementations available are: | * This class is abstract. The concrete implementations available are: | ||||
* | * | ||||
Context not available. | |||||
* @task config | * @task config | ||||
*/ | */ | ||||
final public function setDelimiter($character) { | final public function setDelimiter($character) { | ||||
if (($character !== null) && (strlen($character) !== 1)) { | if (($character !== null) && (@strlen($character) !== 1)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht('Delimiter character must be one byte in length or null.')); | pht('Delimiter character must be one byte in length or null.')); | ||||
} | } | ||||
Context not available. | |||||
// case the size of a line is very large compared to the chunk size we | // case the size of a line is very large compared to the chunk size we | ||||
// read. | // read. | ||||
while (true) { | while (true) { | ||||
if (strlen($this->buf)) { | if (@strlen($this->buf)) { | ||||
// If we don't have a delimiter, return the entire buffer. | // If we don't have a delimiter, return the entire buffer. | ||||
if ($this->delimiter === null) { | if ($this->delimiter === null) { | ||||
$this->num++; | $this->num++; | ||||
$this->line = substr($this->buf, $this->pos); | $this->line = @substr($this->buf, $this->pos); | ||||
$this->buf = ''; | $this->buf = ''; | ||||
$this->pos = 0; | $this->pos = 0; | ||||
return; | return; | ||||
Context not available. | |||||
// If we already have some data buffered, try to get the next line from | // If we already have some data buffered, try to get the next line from | ||||
// the buffer. Search through the buffer for a delimiter. This should be | // the buffer. Search through the buffer for a delimiter. This should be | ||||
// the common case. | // the common case. | ||||
$endl = strpos($this->buf, $this->delimiter, $this->pos); | $endl = @strpos($this->buf, $this->delimiter, $this->pos); | ||||
if ($endl !== false) { | if ($endl !== false) { | ||||
// We found a delimiter, so return the line it delimits. We leave | // We found a delimiter, so return the line it delimits. We leave | ||||
Context not available. | |||||
// large relative to the size of a line. Instead, we move our cursor | // large relative to the size of a line. Instead, we move our cursor | ||||
// within the buffer forward. | // within the buffer forward. | ||||
$this->num++; | $this->num++; | ||||
$this->line = substr($this->buf, $this->pos, ($endl - $this->pos)); | $this->line = @substr($this->buf, $this->pos, ($endl - $this->pos)); | ||||
$this->pos = $endl + 1; | $this->pos = $endl + 1; | ||||
return; | return; | ||||
} | } | ||||
Context not available. | |||||
// We only have part of a line left in the buffer (no delimiter in the | // We only have part of a line left in the buffer (no delimiter in the | ||||
// remaining piece), so throw away the part we've already emitted and | // remaining piece), so throw away the part we've already emitted and | ||||
// continue below. | // continue below. | ||||
$this->buf = substr($this->buf, $this->pos); | $this->buf = @substr($this->buf, $this->pos); | ||||
$this->pos = 0; | $this->pos = 0; | ||||
} | } | ||||
Context not available. | |||||
$more = $this->readMore(); | $more = $this->readMore(); | ||||
} | } | ||||
if (strlen($more)) { | if (@strlen($more)) { | ||||
// We got some bytes, so add them to the buffer and then try again. | // We got some bytes, so add them to the buffer and then try again. | ||||
$this->buf .= $more; | $this->buf .= $more; | ||||
continue; | continue; | ||||
Context not available. | |||||
// delimiter, but that currently seems reasonable as a default | // delimiter, but that currently seems reasonable as a default | ||||
// behavior. If we don't have a buffer, we're done. | // behavior. If we don't have a buffer, we're done. | ||||
$this->eof = true; | $this->eof = true; | ||||
if (strlen($this->buf)) { | if (@strlen($this->buf)) { | ||||
$this->num++; | $this->num++; | ||||
$this->line = $this->buf; | $this->line = $this->buf; | ||||
$this->buf = null; | $this->buf = null; | ||||
Context not available. |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0