As iconv is now enabled by default in PHP, make it a requirement, and modify strig functions to use it where appropriate

This commit is contained in:
MarkBaker 2016-08-31 21:52:42 +01:00
parent e0a9f9e1ec
commit fae27a6d63
5 changed files with 36 additions and 88 deletions

View File

@ -25,6 +25,7 @@
"require": { "require": {
"php": "^5.5|^7.0", "php": "^5.5|^7.0",
"ext-mbstring": "*", "ext-mbstring": "*",
"ext-iconv": "*",
"ext-xml": "*", "ext-xml": "*",
"ext-xmlwriter": "*" "ext-xmlwriter": "*"
}, },

View File

@ -38,7 +38,7 @@ class Autoloader
spl_autoload_register('__autoload'); spl_autoload_register('__autoload');
} }
// Register ourselves with SPL // Register ourselves with SPL
return spl_autoload_register([\PhpSpreadsheet\Autoloader::class, 'load']); return spl_autoload_register([\PhpSpreadsheet\Autoloader::class, 'load'], true, true);
} }
/** /**

View File

@ -28,26 +28,9 @@ class TextData
{ {
private static $invalidChars; private static $invalidChars;
private static function unicodeToOrd($c) private static function unicodeToOrd($character)
{ {
if (ord($c{0}) >= 0 && ord($c{0}) <= 127) { return unpack('V', iconv('UTF-8', 'UCS-4LE', $character))[1];
return ord($c{0});
} elseif (ord($c{0}) >= 192 && ord($c{0}) <= 223) {
return (ord($c{0}) - 192) * 64 + (ord($c{1}) - 128);
} elseif (ord($c{0}) >= 224 && ord($c{0}) <= 239) {
return (ord($c{0}) - 224) * 4096 + (ord($c{1}) - 128) * 64 + (ord($c{2}) - 128);
} elseif (ord($c{0}) >= 240 && ord($c{0}) <= 247) {
return (ord($c{0}) - 240) * 262144 + (ord($c{1}) - 128) * 4096 + (ord($c{2}) - 128) * 64 + (ord($c{3}) - 128);
} elseif (ord($c{0}) >= 248 && ord($c{0}) <= 251) {
return (ord($c{0}) - 248) * 16777216 + (ord($c{1}) - 128) * 262144 + (ord($c{2}) - 128) * 4096 + (ord($c{3}) - 128) * 64 + (ord($c{4}) - 128);
} elseif (ord($c{0}) >= 252 && ord($c{0}) <= 253) {
return (ord($c{0}) - 252) * 1073741824 + (ord($c{1}) - 128) * 16777216 + (ord($c{2}) - 128) * 262144 + (ord($c{3}) - 128) * 4096 + (ord($c{4}) - 128) * 64 + (ord($c{5}) - 128);
} elseif (ord($c{0}) >= 254 && ord($c{0}) <= 255) {
// error
return Functions::VALUE();
}
return 0;
} }
/** /**
@ -64,11 +47,11 @@ class TextData
return Functions::VALUE(); return Functions::VALUE();
} }
if (function_exists('mb_convert_encoding')) { if (function_exists('iconv')) {
return mb_convert_encoding('&#' . intval($character) . ';', 'UTF-8', 'HTML-ENTITIES'); return iconv('UCS-4LE', 'UTF-8', pack('V', $character));
} else {
return chr(intval($character));
} }
return mb_convert_encoding('&#' . intval($character) . ';', 'UTF-8', 'HTML-ENTITIES');
} }
/** /**

View File

@ -1,24 +1,15 @@
<?php <?php
return [ return [
[ [ 'ABC', '#VALUE!' ],
'ABC', [ -5, '#VALUE!' ],
'#VALUE!', [ 65, 'A' ],
], [ 123, '{' ],
[ [ 126, '~' ],
-5, [ 12103, "" ],
'#VALUE!', [ 0x153, 'œ' ],
], [ 0x192, 'ƒ' ],
[ [ 0x2105, '℅' ],
65, [ 0x2211, '∑' ],
'A', [ 0x2020, '†' ],
],
[
123,
'{',
],
[
126,
'~',
],
]; ];

View File

@ -1,48 +1,21 @@
<?php <?php
return [ return [
[ [ null, '#VALUE!' ],
null, [ '', '#VALUE!', ],
'#VALUE!', [ 'ABC', 65 ],
], [ 123, 49 ],
[ [ true, 84 ],
'', [ 'DEF', 68 ],
'#VALUE!', [ 'PhpSpreadsheet', 80 ],
], [ 1.5, 49 ],
[ [ 'Mark Baker', 77 ],
'ABC', [ 'mark baker', 109 ],
65, [ '£125.00', 163 ],
], [ "", 12103],
[ [ 'œ', 0x153 ],
123, [ 'ƒ', 0x192 ],
49, [ '℅', 0x2105 ],
], [ '∑', 0x2211 ],
[ [ '†', 0x2020 ],
true,
84,
],
[
'DEF',
68,
],
[
'PhpSpreadsheet',
80,
],
[
1.5,
49,
],
[
'Mark Baker',
77,
],
[
'mark baker',
109,
],
[
'£125.00',
163,
],
]; ];