@ -15,6 +15,7 @@ trait GenericEncoding {
protected $dirtyEOF = 0;
protected $errMode = self::MODE_REPLACE;
protected $allowSurrogates = false;
protected $selfSynchronizing = false;
public $posErr = 0;
@ -9,6 +9,8 @@ namespace MensBeam\Intl\Encoding;
abstract class SingleByteEncoding implements StatelessEncoding {
use GenericEncoding;
protected $selfSynchronizing = true;
public function nextChar(): string {
// get the byte at the current position
$b = @$this->string[$this->posChar];
abstract class UTF16 implements Encoding {
public function nextCode() {
$lead_b = null;
$lead_s = null;
@ -12,6 +12,8 @@ class UTF8 implements StatelessEncoding {
const NAME = "UTF-8";
const LABELS = ["unicode-1-1-utf-8", "utf-8", "utf8"];
// this function effectively implements https://encoding.spec.whatwg.org/#utf-8-decoder
// optimization for ASCII characters