Browse Source

Don't rely on PHP 8 signature changes

span
J. King 3 years ago
parent
commit
cc9c937810
  1. 38
      lib/Encoding/AbstractEncoding.php
  2. 40
      lib/Encoding/ISO2022JP.php

38
lib/Encoding/AbstractEncoding.php

@ -165,21 +165,37 @@ abstract class AbstractEncoding implements Decoder {
} }
public function asciiSpan(string $mask, int $length = null): string { public function asciiSpan(string $mask, int $length = null): string {
$mask = preg_replace('/[\x80-\xFF]/gs', "", $mask); $mask = preg_replace('/[\x80-\xFF]/s', "", $mask);
$len = strspn($this->string, $mask, $this->posByte, $length); if ($length !== null) {
$out = substr($this->string, $this->posByte, $len); $len = strspn($this->string, $mask, $this->posByte, $length);
$this->posByte += $len; } else {
$this->posChar += $len; $len = strspn($this->string, $mask, $this->posByte);
return $out; }
if ($len) {
$out = substr($this->string, $this->posByte, $len);
$this->posByte += $len;
$this->posChar += $len;
return $out;
} else {
return "";
}
} }
public function asciiSpanNot(string $mask, int $length = null): string { public function asciiSpanNot(string $mask, int $length = null): string {
$mask .= self::HIGH_BYTES; $mask .= self::HIGH_BYTES;
$len = strcspn($this->string, $mask, $this->posByte, $length); if ($length !== null) {
$out = substr($this->string, $this->posByte, $len); $len = strcspn($this->string, $mask, $this->posByte, $length);
$this->posByte += $len; } else {
$this->posChar += $len; $len = strcspn($this->string, $mask, $this->posByte);
return $out; }
if ($len) {
$out = substr($this->string, $this->posByte, $len);
$this->posByte += $len;
$this->posChar += $len;
return $out;
} else {
return "";
}
} }
/** Returns a copy of the decoder's state to keep in memory */ /** Returns a copy of the decoder's state to keep in memory */

40
lib/Encoding/ISO2022JP.php

@ -186,19 +186,27 @@ class ISO2022JP extends AbstractEncoding implements ModalCoder, Decoder {
public function asciiSpan(string $mask, int $length = null): string { public function asciiSpan(string $mask, int $length = null): string {
if ($this->mode === self::ASCII_STATE) { if ($this->mode === self::ASCII_STATE) {
$exc = '/[\x0E\x0F\x1B\x80-\xFF]/gs'; $exc = '/[\x0E\x0F\x1B\x80-\xFF]/s';
} elseif ($this->mode === self::ROMAN_STATE) { } elseif ($this->mode === self::ROMAN_STATE) {
$exc = '/[\x0E\x0F\x1B\x5C\x7E\x80-\xFF]/gs'; $exc = '/[\x0E\x0F\x1B\x5C\x7E\x80-\xFF]/s';
} else { } else {
// in other modes ASCII characters are never returned // in other modes ASCII characters are never returned
return ""; return "";
} }
$mask = preg_replace($exc, "", $mask); $mask = preg_replace($exc, "", $mask);
$len = strspn($this->string, $mask, $this->posByte, $length); if ($length !== null) {
$out = substr($this->string, $this->posByte, $len); $len = strspn($this->string, $mask, $this->posByte, $length);
$this->posByte += $len; } else {
$this->posChar += $len; $len = strspn($this->string, $mask, $this->posByte);
return $out; }
if ($len) {
$out = substr($this->string, $this->posByte, $len);
$this->posByte += $len;
$this->posChar += $len;
return $out;
} else {
return "";
}
} }
public function asciiSpanNot(string $mask, int $length = null): string { public function asciiSpanNot(string $mask, int $length = null): string {
@ -211,11 +219,19 @@ class ISO2022JP extends AbstractEncoding implements ModalCoder, Decoder {
return ""; return "";
} }
$mask .= self::HIGH_BYTES; $mask .= self::HIGH_BYTES;
$len = strcspn($this->string, $mask, $this->posByte, $length); if ($length !== null) {
$out = substr($this->string, $this->posByte, $len); $len = strcspn($this->string, $mask, $this->posByte, $length);
$this->posByte += $len; } else {
$this->posChar += $len; $len = strcspn($this->string, $mask, $this->posByte);
return $out; }
if ($len) {
$out = substr($this->string, $this->posByte, $len);
$this->posByte += $len;
$this->posChar += $len;
return $out;
} else {
return "";
}
} }
protected function stateSave(): array { protected function stateSave(): array {

Loading…
Cancel
Save