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": {
"php": "^5.5|^7.0",
"ext-mbstring": "*",
"ext-iconv": "*",
"ext-xml": "*",
"ext-xmlwriter": "*"
},

View File

@ -38,7 +38,7 @@ class Autoloader
spl_autoload_register('__autoload');
}
// 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 function unicodeToOrd($c)
private static function unicodeToOrd($character)
{
if (ord($c{0}) >= 0 && ord($c{0}) <= 127) {
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;
return unpack('V', iconv('UTF-8', 'UCS-4LE', $character))[1];
}
/**
@ -64,11 +47,11 @@ class TextData
return Functions::VALUE();
}
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding('&#' . intval($character) . ';', 'UTF-8', 'HTML-ENTITIES');
} else {
return chr(intval($character));
if (function_exists('iconv')) {
return iconv('UCS-4LE', 'UTF-8', pack('V', $character));
}
return mb_convert_encoding('&#' . intval($character) . ';', 'UTF-8', 'HTML-ENTITIES');
}
/**

View File

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

View File

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