|
@ -11,6 +11,8 @@ abstract class AbstractEncoding implements Decoder { |
|
|
protected const MODE_REPLACE = 1; |
|
|
protected const MODE_REPLACE = 1; |
|
|
protected const MODE_FATAL = 2; |
|
|
protected const MODE_FATAL = 2; |
|
|
|
|
|
|
|
|
|
|
|
protected const HIGH_BYTES = "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF"; |
|
|
|
|
|
|
|
|
/** @var string $string The string being decoded */ |
|
|
/** @var string $string The string being decoded */ |
|
|
protected $string; |
|
|
protected $string; |
|
|
/** @var int $posByte The current byte position in the string */ |
|
|
/** @var int $posByte The current byte position in the string */ |
|
@ -162,6 +164,24 @@ abstract class AbstractEncoding implements Decoder { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function asciiSpan(string $mask, int $length = null): string { |
|
|
|
|
|
$mask = preg_replace('/[\x80-\xFF]/gs', "", $mask); |
|
|
|
|
|
$len = strspn($this->string, $mask, $this->posByte, $length); |
|
|
|
|
|
$out = substr($this->string, $this->posByte, $len); |
|
|
|
|
|
$this->posByte += $len; |
|
|
|
|
|
$this->posChar += $len; |
|
|
|
|
|
return $out; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function asciiSpanNot(string $mask, int $length = null): string { |
|
|
|
|
|
$mask .= self::HIGH_BYTES; |
|
|
|
|
|
$len = strcspn($this->string, $mask, $this->posByte, $length); |
|
|
|
|
|
$out = substr($this->string, $this->posByte, $len); |
|
|
|
|
|
$this->posByte += $len; |
|
|
|
|
|
$this->posChar += $len; |
|
|
|
|
|
return $out; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** Returns a copy of the decoder's state to keep in memory */ |
|
|
/** Returns a copy of the decoder's state to keep in memory */ |
|
|
protected function stateSave(): array { |
|
|
protected function stateSave(): array { |
|
|
$out = ['errCount' => sizeof($this->errStack)]; |
|
|
$out = ['errCount' => sizeof($this->errStack)]; |
|
|