| @@ -47,9 +47,9 @@ | ||
| 47 | 47 | if (self::$_mb_string_overload) { |
| 48 | 48 | return mb_strlen($string, '8bit'); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - return strlen((binary)$string); | |
| 51 | + return strlen((string)$string); | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | protected function _decode_digit($cp) |
| 55 | 55 | { |
| @@ -74,9 +74,9 @@ | ||
| 74 | 74 | $out_len = 0; |
| 75 | 75 | $inp_len = self::byteLength($input); |
| 76 | 76 | $mode = 'next'; |
| 77 | 77 | $test = 'none'; |
| 78 | - for ($k = 0 ; $k < $inp_len ; ++$k) { | |
| 78 | + for ($k = 0; $k < $inp_len; ++$k) { | |
| 79 | 79 | $v = ord($input[$k]); // Extract byte from input string |
| 80 | 80 | if ($v < 128) { // We found an ASCII char - put into stirng as is |
| 81 | 81 | $output[$out_len] = $v; |
| 82 | 82 | ++$out_len; |
| @@ -137,8 +137,9 @@ | ||
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | public function emailToUTF8($input, $one_time_encoding = false) |
| 140 | 140 | { |
| 141 | + // Optionally set | |
| 141 | 142 | if ($one_time_encoding) { |
| 142 | 143 | switch ($one_time_encoding) { |
| 143 | 144 | case 'utf8': |
| 144 | 145 | case 'ucs4_string': |
| @@ -152,12 +153,13 @@ | ||
| 152 | 153 | } |
| 153 | 154 | $input = trim($input); |
| 154 | 155 | |
| 155 | 156 | if (strpos($input, '@')) { // Maybe it is an email address |
| 157 | + // No no in strict mode | |
| 156 | 158 | if ($this->_strict_mode) { |
| 157 | 159 | return false; |
| 158 | 160 | } |
| 159 | - list ($email_pref, $input) = explode('@', $input, 2); | |
| 161 | + [$email_pref, $input] = explode('@', $input, 2); | |
| 160 | 162 | $arr = explode('.', $input); |
| 161 | 163 | foreach ($arr as $k => $v) { |
| 162 | 164 | if (preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $v)) { |
| 163 | 165 | $conv = $this->_decode($v); |
| @@ -177,9 +179,9 @@ | ||
| 177 | 179 | } elseif (preg_match('![:\./]!', $input)) { // Or a complete domain name (with or without paths / parameters) |
| 178 | 180 | if ($this->_strict_mode) { |
| 179 | 181 | return false; |
| 180 | 182 | } |
| 181 | - $parsed = parse_url($input); | |
| 183 | + $parsed = acym_parseUrl($input); | |
| 182 | 184 | if (isset($parsed['host'])) { |
| 183 | 185 | $arr = explode('.', $parsed['host']); |
| 184 | 186 | foreach ($arr as $k => $v) { |
| 185 | 187 | $conv = $this->_decode($v); |
| @@ -189,9 +191,13 @@ | ||
| 189 | 191 | $return = (empty($parsed['scheme']) |
| 190 | 192 | ? '' |
| 191 | 193 | : $parsed['scheme'].(strtolower( |
| 192 | 194 | $parsed['scheme'] |
| 193 | - ) == 'mailto' ? ':' : '://')).(empty($parsed['user']) ? '' : $parsed['user'].(empty($parsed['pass']) ? '' : ':'.$parsed['pass']).'@').$parsed['host'].(empty($parsed['port']) ? '' : ':'.$parsed['port']).(empty($parsed['path']) ? '' : $parsed['path']).(empty($parsed['query']) ? '' : '?'.$parsed['query']).(empty($parsed['fragment']) ? '' : '#'.$parsed['fragment']); | |
| 195 | + ) == 'mailto' ? ':' : '://')).(empty($parsed['user']) | |
| 196 | + ? '' | |
| 197 | + : $parsed['user'].(empty($parsed['pass']) ? '' | |
| 198 | + : ':'.$parsed['pass']).'@').$parsed['host'].(empty($parsed['port']) ? '' : ':'.$parsed['port']).(empty($parsed['path']) ? '' | |
| 199 | + : $parsed['path']).(empty($parsed['query']) ? '' : '?'.$parsed['query']).(empty($parsed['fragment']) ? '' : '#'.$parsed['fragment']); | |
| 194 | 200 | } else { |
| 195 | 201 | $arr = explode('.', $input); |
| 196 | 202 | foreach ($arr as $k => $v) { |
| 197 | 203 | $conv = $this->_decode($v); |
| @@ -231,9 +237,9 @@ | ||
| 231 | 237 | return false; |
| 232 | 238 | } |
| 233 | 239 | $delim_pos = strrpos($encoded, '-'); |
| 234 | 240 | if ($delim_pos > self::byteLength($this->_punycode_prefix)) { |
| 235 | - for ($k = self::byteLength($this->_punycode_prefix) ; $k < $delim_pos ; ++$k) { | |
| 241 | + for ($k = self::byteLength($this->_punycode_prefix); $k < $delim_pos; ++$k) { | |
| 236 | 242 | $decoded[] = ord($encoded[$k]); |
| 237 | 243 | } |
| 238 | 244 | } |
| 239 | 245 | $deco_len = count($decoded); |
| @@ -243,10 +249,10 @@ | ||
| 243 | 249 | $bias = $this->_initial_bias; |
| 244 | 250 | $idx = 0; |
| 245 | 251 | $char = $this->_initial_n; |
| 246 | 252 | |
| 247 | - for ($enco_idx = ($delim_pos) ? ($delim_pos + 1) : 0 ; $enco_idx < $enco_len ; ++$deco_len) { | |
| 248 | - for ($old_idx = $idx, $w = 1, $k = $this->_base ; 1 ; $k += $this->_base) { | |
| 253 | + for ($enco_idx = ($delim_pos) ? ($delim_pos + 1) : 0; $enco_idx < $enco_len; ++$deco_len) { | |
| 254 | + for ($old_idx = $idx, $w = 1, $k = $this->_base; 1; $k += $this->_base) { | |
| 249 | 255 | $digit = $this->_decode_digit($encoded[$enco_idx++]); |
| 250 | 256 | $idx += $digit * $w; |
| 251 | 257 | $t = ($k <= $bias) ? $this->_tmin : (($k >= $bias + $this->_tmax) ? $this->_tmax : ($k - $bias)); |
| 252 | 258 | if ($digit < $t) break; |
| @@ -256,9 +262,9 @@ | ||
| 256 | 262 | $is_first = false; |
| 257 | 263 | $char += (int)($idx / ($deco_len + 1)); |
| 258 | 264 | $idx %= ($deco_len + 1); |
| 259 | 265 | if ($deco_len > 0) { |
| 260 | - for ($i = $deco_len ; $i > $idx ; $i--) { | |
| 266 | + for ($i = $deco_len; $i > $idx; $i--) { | |
| 261 | 267 | $decoded[$i] = $decoded[($i - 1)]; |
| 262 | 268 | } |
| 263 | 269 | } |
| 264 | 270 | $decoded[$idx++] = $char; |
| @@ -274,8 +280,9 @@ | ||
| 274 | 280 | $decoded = $this->_utf8_to_ucs4($decoded); |
| 275 | 281 | break; |
| 276 | 282 | case 'ucs4_string': |
| 277 | 283 | $decoded = $this->_ucs4_string_to_ucs4($decoded); |
| 284 | + break; | |
| 278 | 285 | case 'ucs4_array': |
| 279 | 286 | break; |
| 280 | 287 | default: |
| 281 | 288 | $this->_error('Unsupported input format: '.($one_time_encoding ? $one_time_encoding : $this->_api_encoding)); |
| @@ -292,8 +299,9 @@ | ||
| 292 | 299 | case 0x3002: |
| 293 | 300 | case 0xFF0E: |
| 294 | 301 | case 0xFF61: |
| 295 | 302 | $decoded[$k] = 0x2E; |
| 303 | + // normal I guess | |
| 296 | 304 | case 0x2E: |
| 297 | 305 | case 0x2F: |
| 298 | 306 | case 0x3A: |
| 299 | 307 | case 0x3F: |
| @@ -314,9 +322,9 @@ | ||
| 314 | 322 | } |
| 315 | 323 | } |
| 316 | 324 | } |
| 317 | 325 | if ($last_begin) { |
| 318 | - $inp_len = sizeof($decoded); | |
| 326 | + $inp_len = count($decoded); | |
| 319 | 327 | $encoded = $this->_encode(array_slice($decoded, $last_begin, (($inp_len) - $last_begin))); |
| 320 | 328 | if ($encoded) { |
| 321 | 329 | $output .= $encoded; |
| 322 | 330 | } else { |
| @@ -354,9 +362,9 @@ | ||
| 354 | 362 | $deco_len = count($decoded); |
| 355 | 363 | if (!$deco_len) return false; // Empty array |
| 356 | 364 | $codecount = 0; // How many chars have been consumed |
| 357 | 365 | $encoded = ''; |
| 358 | - for ($i = 0 ; $i < $deco_len ; ++$i) { | |
| 366 | + for ($i = 0; $i < $deco_len; ++$i) { | |
| 359 | 367 | $test = $decoded[$i]; |
| 360 | 368 | if ((0x2F < $test && $test < 0x40) || (0x40 < $test && $test < 0x5B) || (0x60 < $test && $test <= 0x7B) || (0x2D == $test)) { |
| 361 | 369 | $encoded .= chr($decoded[$i]); |
| 362 | 370 | $codecount++; |
| @@ -370,9 +378,9 @@ | ||
| 370 | 378 | $cur_code = $this->_initial_n; |
| 371 | 379 | $bias = $this->_initial_bias; |
| 372 | 380 | $delta = 0; |
| 373 | 381 | while ($codecount < $deco_len) { |
| 374 | - for ($i = 0, $next_code = $this->_max_ucs ; $i < $deco_len ; $i++) { | |
| 382 | + for ($i = 0, $next_code = $this->_max_ucs; $i < $deco_len; $i++) { | |
| 375 | 383 | if ($decoded[$i] >= $cur_code && $decoded[$i] <= $next_code) { |
| 376 | 384 | $next_code = $decoded[$i]; |
| 377 | 385 | } |
| 378 | 386 | } |
| @@ -378,13 +386,13 @@ | ||
| 378 | 386 | } |
| 379 | 387 | $delta += ($next_code - $cur_code) * ($codecount + 1); |
| 380 | 388 | $cur_code = $next_code; |
| 381 | 389 | |
| 382 | - for ($i = 0 ; $i < $deco_len ; $i++) { | |
| 390 | + for ($i = 0; $i < $deco_len; $i++) { | |
| 383 | 391 | if ($decoded[$i] < $cur_code) { |
| 384 | 392 | $delta++; |
| 385 | 393 | } elseif ($decoded[$i] == $cur_code) { |
| 386 | - for ($q = $delta, $k = $this->_base ; 1 ; $k += $this->_base) { | |
| 394 | + for ($q = $delta, $k = $this->_base; 1; $k += $this->_base) { | |
| 387 | 395 | $t = ($k <= $bias) ? $this->_tmin : (($k >= $bias + $this->_tmax) ? $this->_tmax : $k - $bias); |
| 388 | 396 | if ($q < $t) break; |
| 389 | 397 | $encoded .= $this->_encode_digit(intval($t + (($q - $t) % ($this->_base - $t)))); //v0.4.5 Changed from ceil() to intval() |
| 390 | 398 | $q = (int)(($q - $t) / ($this->_base - $t)); |
| @@ -406,9 +414,9 @@ | ||
| 406 | 414 | protected function _adapt($delta, $npoints, $is_first) |
| 407 | 415 | { |
| 408 | 416 | $delta = intval($is_first ? ($delta / $this->_damp) : ($delta / 2)); |
| 409 | 417 | $delta += intval($delta / $npoints); |
| 410 | - for ($k = 0 ; $delta > (($this->_base - $this->_tmin) * $this->_tmax) / 2 ; $k += $this->_base) { | |
| 418 | + for ($k = 0; $delta > (($this->_base - $this->_tmin) * $this->_tmax) / 2; $k += $this->_base) { | |
| 411 | 419 | $delta = intval($delta / ($this->_base - $this->_tmin)); |
| 412 | 420 | } |
| 413 | 421 | |
| 414 | 422 | return intval($k + ($this->_base - $this->_tmin + 1) * $delta / ($delta + $this->_skew)); |
| @@ -448,9 +456,9 @@ | ||
| 448 | 456 | $output = $this->_hangul_compose($output); |
| 449 | 457 | $last_class = 0; |
| 450 | 458 | $last_starter = 0; |
| 451 | 459 | $out_len = count($output); |
| 452 | - for ($i = 0 ; $i < $out_len ; ++$i) { | |
| 460 | + for ($i = 0; $i < $out_len; ++$i) { | |
| 453 | 461 | $class = $this->_get_combining_class($output[$i]); |
| 454 | 462 | if ((!$last_class || $last_class > $class) && $class) { |
| 455 | 463 | $seq_len = $i - $last_starter; |
| 456 | 464 | $out = $this->_combine(array_slice($output, $last_starter, $seq_len)); |
| @@ -456,9 +464,9 @@ | ||
| 456 | 464 | $out = $this->_combine(array_slice($output, $last_starter, $seq_len)); |
| 457 | 465 | if ($out) { |
| 458 | 466 | $output[$last_starter] = $out; |
| 459 | 467 | if (count($out) != $seq_len) { |
| 460 | - for ($j = $i + 1 ; $j < $out_len ; ++$j) { | |
| 468 | + for ($j = $i + 1; $j < $out_len; ++$j) { | |
| 461 | 469 | $output[$j - 1] = $output[$j]; |
| 462 | 470 | } |
| 463 | 471 | unset($output[$out_len]); |
| 464 | 472 | } |
| @@ -495,9 +503,9 @@ | ||
| 495 | 503 | $result = []; |
| 496 | 504 | $last = (int)$input[0]; |
| 497 | 505 | $result[] = $last; // copy first char from input to output |
| 498 | 506 | |
| 499 | - for ($i = 1 ; $i < $inp_len ; ++$i) { | |
| 507 | + for ($i = 1; $i < $inp_len; ++$i) { | |
| 500 | 508 | $char = (int)$input[$i]; |
| 501 | 509 | $sindex = $last - $this->_sbase; |
| 502 | 510 | $lindex = $last - $this->_lbase; |
| 503 | 511 | $vindex = $char - $this->_vbase; |
| @@ -530,12 +538,12 @@ | ||
| 530 | 538 | $size = count($input); |
| 531 | 539 | while ($swap) { |
| 532 | 540 | $swap = false; |
| 533 | 541 | $last = $this->_get_combining_class(intval($input[0])); |
| 534 | - for ($i = 0 ; $i < $size - 1 ; ++$i) { | |
| 542 | + for ($i = 0; $i < $size - 1; ++$i) { | |
| 535 | 543 | $next = $this->_get_combining_class(intval($input[$i + 1])); |
| 536 | 544 | if ($next != 0 && $last > $next) { |
| 537 | - for ($j = $i + 1 ; $j > 0 ; --$j) { | |
| 545 | + for ($j = $i + 1; $j > 0; --$j) { | |
| 538 | 546 | if ($this->_get_combining_class(intval($input[$j - 1])) <= $next) break; |
| 539 | 547 | $t = intval($input[$j]); |
| 540 | 548 | $input[$j] = intval($input[$j - 1]); |
| 541 | 549 | $input[$j - 1] = $t; |
| @@ -600,9 +608,9 @@ | ||
| 600 | 608 | if ($inp_len % 4) { |
| 601 | 609 | return false; |
| 602 | 610 | } |
| 603 | 611 | if (!$inp_len) return $output; |
| 604 | - for ($i = 0, $out_len = -1 ; $i < $inp_len ; ++$i) { | |
| 612 | + for ($i = 0, $out_len = -1; $i < $inp_len; ++$i) { | |
| 605 | 613 | if (!($i % 4)) { |
| 606 | 614 | $out_len++; |
| 607 | 615 | $output[$out_len] = 0; |
| 608 | 616 | } |