Browse Source

Tweaks

split-manual
J. King 4 years ago
parent
commit
06e43504d0
  1. 8
      lib/Charset.php
  2. 2
      tests/cases/TestCharset.php

8
lib/Charset.php

@ -6,11 +6,11 @@ use MensBeam\Intl\Encoding;
abstract class Charset {
public static function fromBOM(string $data): ?string {
if (substr($data, 0, 3 ) === "\u{FEFF}") {
if (substr($data, 0, 3) === "\u{FEFF}") {
return "UTF-8";
} elseif ($data[0] === "\xFE" && $data[1] === "\xFF") {
} elseif (substr($data, 0, 2) === "\xFE\xFF") {
return "UTF-6BE";
} elseif ($data[0] === "\xFF" && $data[1] === "\xFE") {
} elseif (substr($data, 0, 2) === "\xFF\xFE") {
return "UTF-6LE";
} else {
return null;
@ -218,7 +218,7 @@ abstract class Charset {
}
# A sequence of bytes starting with a 0x3C byte (<), optionally a 0x2F byte (/),
# and finally a byte in the range 0x41-0x5A or 0x61-0x7A (A-Z or a-z)
elseif (($s[$pos] === "/" && ctype_alpha($s[$pos + 1])) || (ctype_alpha($s[$pos]))) {
elseif ((@$s[$pos] === "/" && ctype_alpha(@$s[$pos + 1])) || (ctype_alpha(@$s[$pos]))) {
# Advance the position pointer so that it points at the next
# 0x09 (HT), 0x0A (LF), 0x0C (FF), 0x0D (CR), 0x20 (SP), or 0x3E (>) byte.
while (!in_array(@$s[++$pos], ["\x09", "\x0A", "\x0C", "\x0D", " ", ">", ""]));

2
tests/cases/TestCharset.php

@ -99,7 +99,7 @@ class TestCharset extends \PHPUnit\Framework\TestCase {
if (in_array($testId,["tests1.dat #54", "tests1.dat #55"])) {
continue;
}
yield $testId => [$data, trim($test[$l++])];
yield $testId => [trim($data), trim($test[$l++])];
}
}
}

Loading…
Cancel
Save