diff --git a/LZCompressor/LZContext.php b/LZCompressor/LZContext.php index 0e41a3e..413bb8b 100644 --- a/LZCompressor/LZContext.php +++ b/LZCompressor/LZContext.php @@ -6,12 +6,12 @@ class LZContext /** * @var array */ - public $dictionary = []; + public $dictionary = array(); /** * @var array */ - public $dictionaryToCreate = []; + public $dictionaryToCreate = array(); /** * @var string diff --git a/LZCompressor/LZString.php b/LZCompressor/LZString.php index 75791fa..5045ab5 100644 --- a/LZCompressor/LZString.php +++ b/LZCompressor/LZString.php @@ -25,6 +25,18 @@ class LZString }); } + public static function compressToUTF16($input) { + return self::_compress($input, 15, function($a) { + return LZUtil16::fromCharCode($a+32); + }) . LZUtil16::utf16_chr(32); + } + + public static function decompressFromUTF16($input) { + return self::_decompress($input, 16384, function($feed, $index) { + return LZUtil16::charCodeAt($feed, $index)-32; + }); + } + /** * @param string $uncompressed * @return string @@ -273,7 +285,7 @@ class LZString } $result .= $entry; - $dictionary->addEntry($w . $entry{0}); + $dictionary->addEntry($w . LZUtil::utf8_charAt($entry, 0)); $w = $entry; $enlargeIn--; diff --git a/LZCompressor/LZUtil.php b/LZCompressor/LZUtil.php index 4b27a1e..a0599b2 100644 --- a/LZCompressor/LZUtil.php +++ b/LZCompressor/LZUtil.php @@ -16,7 +16,7 @@ class LZUtil */ public static $keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; public static $keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$"; - private static $baseReverseDic = []; + private static $baseReverseDic = array(); /** * @param string $alphabet @@ -26,7 +26,7 @@ class LZUtil public static function getBaseValue($alphabet, $character) { if(!array_key_exists($alphabet, self::$baseReverseDic)) { - self::$baseReverseDic[$alphabet] = []; + self::$baseReverseDic[$alphabet] = array(); for($i=0; $i