@@ 979-1001 (lines=23) @@ | ||
976 | * @param string $input |
|
977 | * @return array |
|
978 | */ |
|
979 | protected function _ucs4_string_to_ucs4($input) |
|
980 | { |
|
981 | $output = array(); |
|
982 | $inp_len = self::byteLength($input); |
|
983 | // Input length must be dividable by 4 |
|
984 | if ($inp_len % 4) { |
|
985 | $this->_error('Input UCS4 string is broken'); |
|
986 | return false; |
|
987 | } |
|
988 | // Empty input - return empty output |
|
989 | if (!$inp_len) { |
|
990 | return $output; |
|
991 | } |
|
992 | for ($i = 0, $out_len = -1; $i < $inp_len; ++$i) { |
|
993 | // Increment output position every 4 input bytes |
|
994 | if (!($i % 4)) { |
|
995 | $out_len++; |
|
996 | $output[$out_len] = 0; |
|
997 | } |
|
998 | $output[$out_len] += ord($input{$i}) << (8 * (3 - ($i % 4) ) ); |
|
999 | } |
|
1000 | return $output; |
|
1001 | } |
|
1002 | ||
1003 | /** |
|
1004 | * Gets the length of a string in bytes even if mbstring function |
@@ 278-298 (lines=21) @@ | ||
275 | * Convert UCS-4 string (LE in the moment) into UCS-4 garray |
|
276 | * @access private |
|
277 | */ |
|
278 | private static function ucs4_ucs4array($input) |
|
279 | { |
|
280 | $output = array(); |
|
281 | ||
282 | $inp_len = strlen($input); |
|
283 | // Input length must be dividable by 4 |
|
284 | if ($inp_len % 4) { |
|
285 | throw new Exception('Input UCS4 string is broken'); |
|
286 | } |
|
287 | // Empty input - return empty output |
|
288 | if (!$inp_len) return $output; |
|
289 | ||
290 | for ($i = 0, $out_len = -1; $i < $inp_len; ++$i) { |
|
291 | if (!($i % 4)) { // Increment output position every 4 input bytes |
|
292 | $out_len++; |
|
293 | $output[$out_len] = 0; |
|
294 | } |
|
295 | $output[$out_len] += ord($input{$i}) << (8 * (3 - ($i % 4) ) ); |
|
296 | } |
|
297 | return $output; |
|
298 | } |
|
299 | } |
|
300 | ?> |