Skip to content

Commit

Permalink
read_bytes_term(): follow the Ruby implementation more
Browse files Browse the repository at this point in the history
  • Loading branch information
generalmimon committed Jul 31, 2024
1 parent 4047fd9 commit c0b39b0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/Kaitai/Struct/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,27 +325,27 @@ public function readBytesTerm($term, bool $includeTerm, bool $consumeTerm, bool
if (is_int($term)) {
$term = chr($term);
}
$bytes = '';
$r = '';
while (true) {
if ($this->isEof()) {
$c = fgetc($this->stream);
if ($c === false) {
if ($eosError) {
throw new NoTerminatorFoundError($term);
}
break;
}
$byte = $this->readBytes(1);
if ($byte === $term) {
if ($c === $term) {
if ($includeTerm) {
$bytes .= $byte;
$r .= $c;
}
if (!$consumeTerm) {
$this->seek($this->pos() - 1);
}
break;
}
$bytes .= $byte;
$r .= $c;
}
return $bytes;
return $r;
}

/**
Expand Down

0 comments on commit c0b39b0

Please sign in to comment.