|
@ -29,15 +29,13 @@ class Encoder { |
|
|
|
|
|
|
|
|
public function encode(iterable $codePoints): string { |
|
|
public function encode(iterable $codePoints): string { |
|
|
$oldMode = $this->mode; |
|
|
$oldMode = $this->mode; |
|
|
$this->reset(); |
|
|
$this->mode = self::MODE_ASCII; |
|
|
$out = ""; |
|
|
$out = ""; |
|
|
try { |
|
|
try { |
|
|
foreach ($codePoints as $codePoint) { |
|
|
foreach ($codePoints as $codePoint) { |
|
|
$out .= $this->encodeChar($codePoint); |
|
|
$out .= $this->encodeChar($codePoint); |
|
|
} |
|
|
} |
|
|
if ($this->name === "ISO-2022-JP" && $this->mode !== self::MODE_ASCII) { |
|
|
$out .= $this->finalize(); |
|
|
$out .= "\x1B\x28\x42"; |
|
|
|
|
|
} |
|
|
|
|
|
} finally { |
|
|
} finally { |
|
|
$this->mode = $oldMode; |
|
|
$this->mode = $oldMode; |
|
|
} |
|
|
} |
|
@ -178,7 +176,10 @@ class Encoder { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function reset() { |
|
|
public function finalize(): string { |
|
|
$this->mode = self::MODE_ASCII; |
|
|
if ($this->mode !== self::MODE_ASCII) { |
|
|
|
|
|
return $this->modeSet(self::MODE_ASCII, ""); |
|
|
|
|
|
} |
|
|
|
|
|
return ""; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |