Browse Source

Style fixes

multi-byte
J. King 4 years ago
parent
commit
a57dde6dbd
  1. 10
      lib/Encoding/Big5.php
  2. 6
      lib/Encoding/EUCJP.php
  3. 109
      lib/Encoding/Encoder.php
  4. 16
      lib/Encoding/ISO2022JP.php
  5. 2
      lib/Encoding/ShiftJIS.php
  6. 4
      lib/Encoding/UTF16BE.php
  7. 2
      lib/Encoding/UTF16LE.php
  8. 10
      lib/Encoding/UTF8.php
  9. 1
      tests/cases/Encoding/TestBig5.php
  10. 25
      tests/cases/Encoding/TestEUCJP.php
  11. 1
      tests/cases/Encoding/TestEUCKR.php
  12. 1
      tests/cases/Encoding/TestGB18030.php
  13. 31
      tests/cases/Encoding/TestISO2022JP.php
  14. 29
      tests/cases/Encoding/TestShiftJIS.php
  15. 1
      tests/cases/Encoding/TestSingleByte.php
  16. 1
      tests/cases/Encoding/TestUTF16LE.php
  17. 1
      tests/cases/Encoding/TestUTF8.php
  18. 1
      tests/cases/Encoding/TestXUserDefined.php
  19. 4
      tests/cases/TestEncoding.php
  20. 2
      tests/lib/DecoderTest.php
  21. 2
      tools/mkindex.php
  22. 4
      tools/mklabels.php

10
lib/Encoding/Big5.php

@ -9,11 +9,11 @@ namespace MensBeam\Intl\Encoding;
class Big5 extends AbstractEncoding implements StatelessEncoding {
const NAME = "Big5";
const LABELS = [
"big5",
"big5-hkscs",
"cn-big5",
"csbig5",
"x-x-big5"
"big5",
"big5-hkscs",
"cn-big5",
"csbig5",
"x-x-big5",
];
const TABLE_DOUBLES = [
1133 => [0x00CA, 0x0304],

6
lib/Encoding/EUCJP.php

File diff suppressed because one or more lines are too long

109
lib/Encoding/Encoder.php

@ -22,7 +22,7 @@ class Encoder {
if (!$l || !$l['encoder']) {
throw new EncoderException("Label '$label' does not have an encoder", Encoder::E_UNAVAILABLE_ENCODER);
} else {
$this->name = $['name'];
$this->name = $s['name'];
$this->fatal = $fatal;
}
}
@ -32,41 +32,76 @@ class Encoder {
throw new EncoderException("Encountered code point outside Unicode range ($codePoint)", self::E_INVALID_CODE_POINT);
}
switch ($this->name) {
case "UTF-8": return return UTF8::encode($codePoint, $this->fatal);
case "Big5": return Big5::encode($codePoint, $this->fatal);
case "EUC-JP": return EUCJP::encode($codePoint, $this->fatal);
case "EUC-KR": return EUCKR::encode($codePoint, $this->fatal);
case "gb18030": return GB18030::encode($codePoint, $this->fatal);
case "GBK": return GBK::encode($codePoint, $this->fatal);
case "IBM866": return IBM866::encode($codePoint, $this->fatal);
case "ISO-8859-2": return ISO88592::encode($codePoint, $this->fatal);
case "ISO-8859-3": return ISO88593::encode($codePoint, $this->fatal);
case "ISO-8859-4": return ISO88594::encode($codePoint, $this->fatal);
case "ISO-8859-5": return ISO88595::encode($codePoint, $this->fatal);
case "ISO-8859-6": return ISO88596::encode($codePoint, $this->fatal);
case "ISO-8859-7": return ISO88597::encode($codePoint, $this->fatal);
case "ISO-8859-8": return ISO88598::encode($codePoint, $this->fatal);
case "ISO-8859-8-I": return ISO88598I::encode($codePoint, $this->fatal);
case "ISO-8859-10": return ISO885910::encode($codePoint, $this->fatal);
case "ISO-8859-13": return ISO885913::encode($codePoint, $this->fatal);
case "ISO-8859-14": return ISO885914::encode($codePoint, $this->fatal);
case "ISO-8859-15": return ISO885915::encode($codePoint, $this->fatal);
case "ISO-8859-16": return ISO885916::encode($codePoint, $this->fatal);
case "KOI8-R": return KOI8R::encode($codePoint, $this->fatal);
case "KOI8-U": return KOI8U::encode($codePoint, $this->fatal);
case "macintosh": return Macintosh::encode($codePoint, $this->fatal);
case "Shift_JIS": return ShiftJIS::encode($codePoint, $this->fatal);
case "windows1250": return Windows1250::encode($codePoint, $this->fatal);
case "windows1251": return Windows1251::encode($codePoint, $this->fatal);
case "windows1252": return Windows1252::encode($codePoint, $this->fatal);
case "windows1253": return Windows1253::encode($codePoint, $this->fatal);
case "windows1254": return Windows1254::encode($codePoint, $this->fatal);
case "windows1255": return Windows1255::encode($codePoint, $this->fatal);
case "windows1256": return Windows1256::encode($codePoint, $this->fatal);
case "windows1257": return Windows1257::encode($codePoint, $this->fatal);
case "windows874": return Windows874::encode($codePoint, $this->fatal);
case "x-mac-cyrillic": return XMacCyrillic::encode($codePoint, $this->fatal);
case "x-user-defined": return XUserDefined::encode($codePoint, $this->fatal);
case "UTF-8":
return UTF8::encode($codePoint, $this->fatal);
case "Big5":
return Big5::encode($codePoint, $this->fatal);
case "EUC-JP":
return EUCJP::encode($codePoint, $this->fatal);
case "EUC-KR":
return EUCKR::encode($codePoint, $this->fatal);
case "gb18030":
return GB18030::encode($codePoint, $this->fatal);
case "GBK":
return GBK::encode($codePoint, $this->fatal);
case "IBM866":
return IBM866::encode($codePoint, $this->fatal);
case "ISO-8859-2":
return ISO88592::encode($codePoint, $this->fatal);
case "ISO-8859-3":
return ISO88593::encode($codePoint, $this->fatal);
case "ISO-8859-4":
return ISO88594::encode($codePoint, $this->fatal);
case "ISO-8859-5":
return ISO88595::encode($codePoint, $this->fatal);
case "ISO-8859-6":
return ISO88596::encode($codePoint, $this->fatal);
case "ISO-8859-7":
return ISO88597::encode($codePoint, $this->fatal);
case "ISO-8859-8":
return ISO88598::encode($codePoint, $this->fatal);
case "ISO-8859-8-I":
return ISO88598I::encode($codePoint, $this->fatal);
case "ISO-8859-10":
return ISO885910::encode($codePoint, $this->fatal);
case "ISO-8859-13":
return ISO885913::encode($codePoint, $this->fatal);
case "ISO-8859-14":
return ISO885914::encode($codePoint, $this->fatal);
case "ISO-8859-15":
return ISO885915::encode($codePoint, $this->fatal);
case "ISO-8859-16":
return ISO885916::encode($codePoint, $this->fatal);
case "KOI8-R":
return KOI8R::encode($codePoint, $this->fatal);
case "KOI8-U":
return KOI8U::encode($codePoint, $this->fatal);
case "macintosh":
return Macintosh::encode($codePoint, $this->fatal);
case "Shift_JIS":
return ShiftJIS::encode($codePoint, $this->fatal);
case "windows1250":
return Windows1250::encode($codePoint, $this->fatal);
case "windows1251":
return Windows1251::encode($codePoint, $this->fatal);
case "windows1252":
return Windows1252::encode($codePoint, $this->fatal);
case "windows1253":
return Windows1253::encode($codePoint, $this->fatal);
case "windows1254":
return Windows1254::encode($codePoint, $this->fatal);
case "windows1255":
return Windows1255::encode($codePoint, $this->fatal);
case "windows1256":
return Windows1256::encode($codePoint, $this->fatal);
case "windows1257":
return Windows1257::encode($codePoint, $this->fatal);
case "windows874":
return Windows874::encode($codePoint, $this->fatal);
case "x-mac-cyrillic":
return XMacCyrillic::encode($codePoint, $this->fatal);
case "x-user-defined":
return XUserDefined::encode($codePoint, $this->fatal);
case "ISO-2022-JP":
if ($codePoint === 0xE || $codePoint === 0xF || $codePoint === 0x1B) {
return $this->err($codePoint, 0xFFFD);
@ -102,7 +137,7 @@ class Encoder {
return $lead.$trail;
}
return $this->err($codePoint);
}
}
}
}

16
lib/Encoding/ISO2022JP.php

@ -27,7 +27,7 @@ class ISO2022JP extends AbstractEncoding implements StatefulEncoding {
protected $modeMark = \PHP_INT_MIN;
protected $modeStack = [];
protected $dirtyEOF = 0;
public function __construct(string $string, bool $fatal = false, bool $allowSurrogates = false) {
parent::__construct($string, $fatal, $allowSurrogates);
$this->stateProps[] = "dirtyEOF";
@ -44,7 +44,7 @@ class ISO2022JP extends AbstractEncoding implements StatefulEncoding {
public function nextCode() {
$this->posChar++;
$state = $this->mode;
while (true) {
while (true) {
$b = @$this->string[$this->posByte++];
$eof = ($b === "");
$b = ord($b);
@ -142,7 +142,7 @@ class ISO2022JP extends AbstractEncoding implements StatefulEncoding {
$this->modeMark = $this->posByte;
return $mode;
}
public static function encode(array $codePoints, bool $fatal = true): string {
return "";
}
@ -167,7 +167,7 @@ class ISO2022JP extends AbstractEncoding implements StatefulEncoding {
} else {
$this->posByte -= ($this->mode === self::LEAD_BYTE_STATE ? 2 : 1);
}
// check for a mode change that is not also an error character
// check for a mode change that is not also an error character
if ($this->posByte === $this->modeMark && $this->posByte !== $this->errMark) {
$this->posByte -= 3;
list($this->modeMark, $this->mode) = array_pop($this->modeStack);
@ -175,13 +175,13 @@ class ISO2022JP extends AbstractEncoding implements StatefulEncoding {
}
return $distance;
}
protected function stateSave(): array {
$out = parent::stateSave();
$out['modeCount'] = sizeof($this->modeStack);
return $out;
}
protected function stateApply(array $state) {
while (sizeof($this->modeStack) > $state['modeCount']) {
list($this->modeMark, $this->mode) = array_pop($this->modeStack);
@ -189,7 +189,7 @@ class ISO2022JP extends AbstractEncoding implements StatefulEncoding {
unset($state['modeCount']);
parent::stateApply($state);
}
public function rewind() {
$this->modeStack = [];
$this->modeMark = \PHP_INT_MIN;
@ -197,7 +197,7 @@ class ISO2022JP extends AbstractEncoding implements StatefulEncoding {
$this->dirtyEOF = 0;
parent::rewind();
}
public function eof(): bool {
return $this->posByte === $this->lenByte || ($this->posByte === ($this->lenByte - 3) && $this->peekCode() === false);
}

2
lib/Encoding/ShiftJIS.php

@ -50,7 +50,7 @@ class ShiftJIS extends AbstractEncoding implements StatelessEncoding {
if ($pointer >= 8836 && $pointer <= 10715) {
return 0xE000 - 8836 + $pointer;
} else {
$codePoint = self::TABLE_CODES[$pointer] ?? self::TABLE_CODES_EXTRA[$pointer] ?? null;
$codePoint = self::TABLE_CODES[$pointer] ?? self::TABLE_CODES_EXTRA[$pointer] ?? null;
}
}
if ($codePoint === null) {

4
lib/Encoding/UTF16BE.php

@ -10,7 +10,7 @@ class UTF16BE extends UTF16 {
const BE = true;
const NAME = "UTF-16BE";
const LABELS = [
"unicodefffe",
"utf-16be"
"unicodefffe",
"utf-16be",
];
}

2
lib/Encoding/UTF16LE.php

@ -16,6 +16,6 @@ class UTF16LE extends UTF16 {
"unicode",
"unicodefeff",
"utf-16",
"utf-16le"
"utf-16le",
];
}

10
lib/Encoding/UTF8.php

@ -9,12 +9,12 @@ namespace MensBeam\Intl\Encoding;
class UTF8 extends AbstractEncoding implements StatelessEncoding {
const NAME = "UTF-8";
const LABELS = [
"unicode-1-1-utf-8",
"unicode11utf8",
"unicode-1-1-utf-8",
"unicode11utf8",
"unicode20utf8",
"utf-8",
"utf8",
"x-unicode20utf8"
"utf-8",
"utf8",
"x-unicode20utf8",
];
protected $selfSynchronizing = true;

1
tests/cases/Encoding/TestBig5.php

@ -136,7 +136,6 @@ class TestBig5 extends \MensBeam\Intl\Test\CoderDecoderTest {
return parent::testIterateThroughAStringAllowingSurrogates($input, $strictExp, $relaxedExp);
}
/**
* @covers MensBeam\Intl\Encoding\Big5::seekBack
*/

25
tests/cases/Encoding/TestEUCJP.php

File diff suppressed because one or more lines are too long

1
tests/cases/Encoding/TestEUCKR.php

@ -136,7 +136,6 @@ class TestEUCKR extends \MensBeam\Intl\Test\CoderDecoderTest {
return parent::testIterateThroughAStringAllowingSurrogates($input, $strictExp, $relaxedExp);
}
/**
* @covers MensBeam\Intl\Encoding\EUCKR::seekBack
*/

1
tests/cases/Encoding/TestGB18030.php

@ -144,7 +144,6 @@ class TestGB18030 extends \MensBeam\Intl\Test\CoderDecoderTest {
return parent::testIterateThroughAStringAllowingSurrogates($input, $strictExp, $relaxedExp);
}
/**
* @covers MensBeam\Intl\Encoding\GB18030::seekBack
*/

31
tests/cases/Encoding/TestISO2022JP.php

@ -7,8 +7,6 @@ declare(strict_types=1);
namespace MensBeam\Intl\TestCase\Encoding;
use MensBeam\Intl\Encoding\ISO2022JP;
use MensBeam\Intl\Encoding\Encoding;
use MensBeam\Intl\Encoding\EncoderException;
class TestISO2022JP extends \MensBeam\Intl\Test\CoderDecoderTest {
protected $testedClass = ISO2022JP::class;
@ -64,7 +62,7 @@ class TestISO2022JP extends \MensBeam\Intl\Test\CoderDecoderTest {
* @dataProvider provideCodePoints
* @covers MensBeam\Intl\Encoding\ISO2022JP::encode
* @covers MensBeam\Intl\Encoding\ISO2022JP::errEnc
*/
*/
public function testEncodeCodePoints(bool $fatal, $input, $exp) {
return parent::testEncodeCodePoints($fatal, $input, $exp);
}
@ -74,7 +72,7 @@ class TestISO2022JP extends \MensBeam\Intl\Test\CoderDecoderTest {
* @covers MensBeam\Intl\Encoding\ISO2022JP::__construct
* @covers MensBeam\Intl\Encoding\ISO2022JP::nextCode
* @covers MensBeam\Intl\Encoding\ISO2022JP::modeSet
*/
*/
public function testDecodeMultipleCharactersAsCodePoints(string $input, array $exp) {
return parent::testDecodeMultipleCharactersAsCodePoints($input, $exp);
}
@ -84,7 +82,7 @@ class TestISO2022JP extends \MensBeam\Intl\Test\CoderDecoderTest {
* @covers MensBeam\Intl\Encoding\ISO2022JP::__construct
* @covers MensBeam\Intl\Encoding\ISO2022JP::nextChar
* @covers MensBeam\Intl\Encoding\ISO2022JP::modeSet
*/
*/
public function testDecodeMultipleCharactersAsStrings(string $input, array $exp) {
return parent::testDecodeMultipleCharactersAsStrings($input, $exp);
}
@ -92,7 +90,7 @@ class TestISO2022JP extends \MensBeam\Intl\Test\CoderDecoderTest {
/**
* @dataProvider provideStrings
* @covers MensBeam\Intl\Encoding\ISO2022JP::seekBack
*/
*/
public function testSTepBackThroughAString(string $input, array $exp) {
return parent::testSTepBackThroughAString($input, $exp);
}
@ -102,7 +100,7 @@ class TestISO2022JP extends \MensBeam\Intl\Test\CoderDecoderTest {
* @covers MensBeam\Intl\Encoding\ISO2022JP::posChar
* @covers MensBeam\Intl\Encoding\ISO2022JP::posByte
* @covers MensBeam\Intl\Encoding\ISO2022JP::rewind
*/
*/
public function testSeekThroughAString() {
return parent::testSeekThroughAString();
}
@ -111,7 +109,7 @@ class TestISO2022JP extends \MensBeam\Intl\Test\CoderDecoderTest {
* @covers MensBeam\Intl\Encoding\ISO2022JP::posChar
* @covers MensBeam\Intl\Encoding\ISO2022JP::posByte
* @covers MensBeam\Intl\Encoding\ISO2022JP::eof
*/
*/
public function testTraversePastTheEndOfAString() {
return parent::testTraversePastTheEndOfAString();
}
@ -120,7 +118,7 @@ class TestISO2022JP extends \MensBeam\Intl\Test\CoderDecoderTest {
* @covers MensBeam\Intl\Encoding\ISO2022JP::peekChar
* @covers MensBeam\Intl\Encoding\ISO2022JP::stateSave
* @covers MensBeam\Intl\Encoding\ISO2022JP::stateApply
*/
*/
public function testPeekAtCharacters() {
return parent::testPeekAtCharacters();
}
@ -129,7 +127,7 @@ class TestISO2022JP extends \MensBeam\Intl\Test\CoderDecoderTest {
* @covers MensBeam\Intl\Encoding\ISO2022JP::peekCode
* @covers MensBeam\Intl\Encoding\ISO2022JP::stateSave
* @covers MensBeam\Intl\Encoding\ISO2022JP::stateApply
*/
*/
public function testPeekAtCodePoints() {
return parent::testPeekAtCodePoints();
}
@ -140,14 +138,14 @@ class TestISO2022JP extends \MensBeam\Intl\Test\CoderDecoderTest {
* @covers MensBeam\Intl\Encoding\ISO2022JP::lenByte
* @covers MensBeam\Intl\Encoding\ISO2022JP::stateSave
* @covers MensBeam\Intl\Encoding\ISO2022JP::stateApply
*/
*/
public function testGetStringLength(string $input, array $points) {
return parent::testGetStringLength($input, $points);
}
/**
* @covers MensBeam\Intl\Encoding\ISO2022JP::errDec
*/
*/
public function testReplacementModes() {
return parent::testReplacementModes();
}
@ -157,7 +155,7 @@ class TestISO2022JP extends \MensBeam\Intl\Test\CoderDecoderTest {
* @covers MensBeam\Intl\Encoding\ISO2022JP::rewind
* @covers MensBeam\Intl\Encoding\ISO2022JP::chars
* @covers MensBeam\Intl\Encoding\ISO2022JP::codes
*/
*/
public function testIterateThroughAString(string $input, array $exp) {
return parent::testIterateThroughAString($input, $exp);
}
@ -165,12 +163,11 @@ class TestISO2022JP extends \MensBeam\Intl\Test\CoderDecoderTest {
/**
* @dataProvider provideStrings
* @coversNothing
*/
*/
public function testIterateThroughAStringAllowingSurrogates(string $input, array $strictExp, array $relaxedExp = null) {
return parent::testIterateThroughAStringAllowingSurrogates($input, $strictExp, $relaxedExp);
}
/**
* @covers MensBeam\Intl\Encoding\ISO2022JP::seekBack
*/
@ -180,7 +177,7 @@ class TestISO2022JP extends \MensBeam\Intl\Test\CoderDecoderTest {
/**
* @group optional
*/
*/
public function testPedanticallyDecodeSingleCharactersAsCodePoint() {
$series = [
];
@ -196,5 +193,3 @@ class TestISO2022JP extends \MensBeam\Intl\Test\CoderDecoderTest {
}
}
}

29
tests/cases/Encoding/TestShiftJIS.php

File diff suppressed because one or more lines are too long

1
tests/cases/Encoding/TestSingleByte.php

@ -214,7 +214,6 @@ class TestSingleByte extends \MensBeam\Intl\Test\CoderDecoderTest {
return parent::testIterateThroughAStringAllowingSurrogates($input, $exp, $exp);
}
/**
* @dataProvider provideClasses
* @coversNothing

1
tests/cases/Encoding/TestUTF16LE.php

@ -126,7 +126,6 @@ class TestUTF16LE extends \MensBeam\Intl\Test\DecoderTest {
return parent::testIterateThroughAStringAllowingSurrogates($input, $strictExp, $relaxedExp);
}
/**
* @covers MensBeam\Intl\Encoding\UTF16::seekBack
*/

1
tests/cases/Encoding/TestUTF8.php

@ -136,7 +136,6 @@ class TestUTF8 extends \MensBeam\Intl\Test\CoderDecoderTest {
return parent::testIterateThroughAStringAllowingSurrogates($input, $strictExp, $relaxedExp);
}
/**
* @covers MensBeam\Intl\Encoding\UTF8::seekBack
*/

1
tests/cases/Encoding/TestXUserDefined.php

@ -117,7 +117,6 @@ class TestXUserDefined extends \MensBeam\Intl\Test\DecoderTest {
return parent::testIterateThroughAStringAllowingSurrogates($input, $strictExp, $relaxedExp);
}
/**
* @coversNothing
*/

4
tests/cases/TestEncoding.php

@ -49,7 +49,9 @@ class TestEncoding extends \PHPUnit\Framework\TestCase {
}
$out = [];
foreach ($labels as $label => $name) {
$out[] = [(string) $label, ['label' => (string) $label, 'name' => $name, 'class' => $names[$name]]];
$class = $names[$name];
$encoder = !in_array($name, ["UTF-16LE", "UTF-16BE", "replacement"]);
$out[] = [(string) $label, ['label' => (string) $label, 'name' => $name, 'encoder' => $encoder, 'class' => $class]];
}
return $out;
}

2
tests/lib/DecoderTest.php

@ -94,7 +94,7 @@ abstract class DecoderTest extends \PHPUnit\Framework\TestCase {
$this->assertSame(0, $s->seek(4));
$this->assertSame(7, $s->posChar());
$this->assertSame($off[7], $s->posByte());
$this->assertSame(1, $s->seek(1));
$this->assertSame(7, $s->posChar());
if ($this->testedClass !== ISO2022JP::class) {

2
tools/mkindex.php

@ -111,7 +111,7 @@ ARRAY_LITERAL;
// search the Big5 rump for duplicates
$dupes = make_override_array($nhk);
// remove those duplicates which should use the last code point
foreach([0x2550, 0x255E, 0x2561, 0x256A, 0x5341, 0x5345] as $code) {
foreach ([0x2550, 0x255E, 0x2561, 0x256A, 0x5341, 0x5345] as $code) {
unset($dupes[$code]);
}
// serialize and print; Hong Kong characters are kept separate as they are not used in encoding

4
tools/mklabels.php

@ -1,6 +1,6 @@
<?php
// this script read and names and labels from each concrete
// class in the Encoding set and generates tables mapping labels
// this script read and names and labels from each concrete
// class in the Encoding set and generates tables mapping labels
// to names and names to classes
use MensBeam\Intl\Encoding\Encoding;

Loading…
Cancel
Save