Browse Source

Fix spanning with single-byte encodings

span
J. King 3 years ago
parent
commit
60a5487e46
  1. 7
      lib/Encoding/SingleByteEncoding.php
  2. 8
      lib/Encoding/XUserDefined.php

7
lib/Encoding/SingleByteEncoding.php

@ -16,6 +16,7 @@ abstract class SingleByteEncoding extends AbstractEncoding implements Coder, Dec
return "";
}
$this->posChar++;
$this->posByte++;
$p = ord($b);
if ($p < 0x80) {
// if the byte is an ASCII character or end of input, simply return it
@ -32,6 +33,7 @@ abstract class SingleByteEncoding extends AbstractEncoding implements Coder, Dec
return false;
}
$this->posChar++;
$this->posByte++;
$p = ord($b);
if ($p < 0x80) {
// if the byte is an ASCII character or end of input, simply return it
@ -62,6 +64,7 @@ abstract class SingleByteEncoding extends AbstractEncoding implements Coder, Dec
$distance = abs($distance);
while ($this->posChar > 0 && $distance > 0) {
$this->posChar--;
$this->posByte--;
$distance--;
}
return $distance;
@ -76,10 +79,6 @@ abstract class SingleByteEncoding extends AbstractEncoding implements Coder, Dec
return 0;
}
public function posByte(): int {
return $this->posChar;
}
public function lenChar(): int {
return $this->lenByte;
}

8
lib/Encoding/XUserDefined.php

@ -21,6 +21,7 @@ class XUserDefined extends AbstractEncoding implements Coder, Decoder {
return "";
}
$this->posChar++;
$this->posByte++;
$p = ord($b);
if ($p < 0x80) {
// if the byte is an ASCII character or end of input, simply return it
@ -43,6 +44,7 @@ class XUserDefined extends AbstractEncoding implements Coder, Decoder {
return false;
}
$this->posChar++;
$this->posByte++;
$p = ord($b);
if ($p < 0x80) {
// if the byte is an ASCII character or end of input, simply return it
@ -69,6 +71,7 @@ class XUserDefined extends AbstractEncoding implements Coder, Decoder {
$distance = abs($distance);
while ($this->posChar > 0 && $distance > 0) {
$this->posChar--;
$this->posByte--;
$distance--;
}
return $distance;
@ -95,11 +98,6 @@ class XUserDefined extends AbstractEncoding implements Coder, Decoder {
return 0;
}
/** Returns the current byte position of the decoder */
public function posByte(): int {
return $this->posChar;
}
/** Calculates the length of the string in code points
*
* Note that this may involve processing to the end of the string

Loading…
Cancel
Save