comparison vendor/symfony/polyfill-iconv/Iconv.php @ 16:c2387f117808

Routine composer update
author Chris Cannam
date Tue, 10 Jul 2018 15:07:59 +0100
parents 7a779792577d
children 129ea1e6d783
comparison
equal deleted inserted replaced
15:e200cb7efeb3 16:c2387f117808
246 if (false === $str) { 246 if (false === $str) {
247 return false; 247 return false;
248 } 248 }
249 $str = explode(':', $str, 2); 249 $str = explode(':', $str, 2);
250 250
251 if (2 === count($str)) { 251 if (2 === \count($str)) {
252 if (isset($headers[$str[0]])) { 252 if (isset($headers[$str[0]])) {
253 if (!is_array($headers[$str[0]])) { 253 if (!\is_array($headers[$str[0]])) {
254 $headers[$str[0]] = array($headers[$str[0]]); 254 $headers[$str[0]] = array($headers[$str[0]]);
255 } 255 }
256 $headers[$str[0]][] = ltrim($str[1]); 256 $headers[$str[0]][] = ltrim($str[1]);
257 } else { 257 } else {
258 $headers[$str[0]] = ltrim($str[1]); 258 $headers[$str[0]] = ltrim($str[1]);
283 if (false === $result) { 283 if (false === $result) {
284 return false; 284 return false;
285 } 285 }
286 286
287 $i = 1; 287 $i = 1;
288 $len = count($str); 288 $len = \count($str);
289 289
290 while ($i < $len) { 290 while ($i < $len) {
291 $c = strtolower($str[$i]); 291 $c = strtolower($str[$i]);
292 if ((ICONV_MIME_DECODE_CONTINUE_ON_ERROR & $mode) 292 if ((ICONV_MIME_DECODE_CONTINUE_ON_ERROR & $mode)
293 && 'utf-8' !== $c 293 && 'utf-8' !== $c
353 return true; 353 return true;
354 } 354 }
355 355
356 public static function iconv_mime_encode($fieldName, $fieldValue, $pref = null) 356 public static function iconv_mime_encode($fieldName, $fieldValue, $pref = null)
357 { 357 {
358 if (!is_array($pref)) { 358 if (!\is_array($pref)) {
359 $pref = array(); 359 $pref = array();
360 } 360 }
361 361
362 $pref += array( 362 $pref += array(
363 'scheme' => 'B', 363 'scheme' => 'B',
383 383
384 $chars = isset($chars[0]) ? $chars[0] : array(); 384 $chars = isset($chars[0]) ? $chars[0] : array();
385 385
386 $lineBreak = (int) $pref['line-length']; 386 $lineBreak = (int) $pref['line-length'];
387 $lineStart = "=?{$pref['output-charset']}?{$scheme}?"; 387 $lineStart = "=?{$pref['output-charset']}?{$scheme}?";
388 $lineLength = strlen($fieldName) + 2 + strlen($lineStart) + 2; 388 $lineLength = \strlen($fieldName) + 2 + \strlen($lineStart) + 2;
389 $lineOffset = strlen($lineStart) + 3; 389 $lineOffset = \strlen($lineStart) + 3;
390 $lineData = ''; 390 $lineData = '';
391 391
392 $fieldValue = array(); 392 $fieldValue = array();
393 393
394 $Q = 'Q' === $scheme; 394 $Q = 'Q' === $scheme;
414 $lineLength = $lineOffset; 414 $lineLength = $lineOffset;
415 $lineData = ''; 415 $lineData = '';
416 } 416 }
417 417
418 $lineData .= $c; 418 $lineData .= $c;
419 $Q && $lineLength += strlen($c); 419 $Q && $lineLength += \strlen($c);
420 } 420 }
421 421
422 if ('' !== $lineData) { 422 if ('' !== $lineData) {
423 if (!$Q) { 423 if (!$Q) {
424 $lineData = base64_encode($lineData); 424 $lineData = base64_encode($lineData);
450 } 450 }
451 if (0 !== stripos($encoding, 'utf-8') && false === $s = self::iconv($encoding, 'utf-8', $s)) { 451 if (0 !== stripos($encoding, 'utf-8') && false === $s = self::iconv($encoding, 'utf-8', $s)) {
452 return false; 452 return false;
453 } 453 }
454 454
455 return strlen(utf8_decode($s)); 455 return \strlen(utf8_decode($s));
456 } 456 }
457 457
458 public static function strlen2($s, $encoding = null) 458 public static function strlen2($s, $encoding = null)
459 { 459 {
460 if (null === $encoding) { 460 if (null === $encoding) {
466 466
467 $ulenMask = self::$ulenMask; 467 $ulenMask = self::$ulenMask;
468 468
469 $i = 0; 469 $i = 0;
470 $j = 0; 470 $j = 0;
471 $len = strlen($s); 471 $len = \strlen($s);
472 472
473 while ($i < $len) { 473 while ($i < $len) {
474 $u = $s[$i] & "\xF0"; 474 $u = $s[$i] & "\xF0";
475 $i += isset($ulenMask[$u]) ? $ulenMask[$u] : 1; 475 $i += isset($ulenMask[$u]) ? $ulenMask[$u] : 1;
476 ++$j; 476 ++$j;
598 $ulenMask = self::$ulenMask; 598 $ulenMask = self::$ulenMask;
599 $valid = self::$isValidUtf8; 599 $valid = self::$isValidUtf8;
600 600
601 $u = $str; 601 $u = $str;
602 $i = $j = 0; 602 $i = $j = 0;
603 $len = strlen($str); 603 $len = \strlen($str);
604 604
605 while ($i < $len) { 605 while ($i < $len) {
606 if ($str[$i] < "\x80") { 606 if ($str[$i] < "\x80") {
607 $u[$j++] = $str[$i++]; 607 $u[$j++] = $str[$i++];
608 } else { 608 } else {
634 return substr($u, 0, $j); 634 return substr($u, 0, $j);
635 } 635 }
636 636
637 private static function mapToUtf8(&$result, array $map, $str, $ignore) 637 private static function mapToUtf8(&$result, array $map, $str, $ignore)
638 { 638 {
639 $len = strlen($str); 639 $len = \strlen($str);
640 for ($i = 0; $i < $len; ++$i) { 640 for ($i = 0; $i < $len; ++$i) {
641 if (isset($str[$i + 1], $map[$str[$i].$str[$i + 1]])) { 641 if (isset($str[$i + 1], $map[$str[$i].$str[$i + 1]])) {
642 $result .= $map[$str[$i].$str[++$i]]; 642 $result .= $map[$str[$i].$str[++$i]];
643 } elseif (isset($map[$str[$i]])) { 643 } elseif (isset($map[$str[$i]])) {
644 $result .= $map[$str[$i]]; 644 $result .= $map[$str[$i]];
660 if ($translit && !self::$translitMap) { 660 if ($translit && !self::$translitMap) {
661 self::$translitMap = self::getData('translit'); 661 self::$translitMap = self::getData('translit');
662 } 662 }
663 663
664 $i = 0; 664 $i = 0;
665 $len = strlen($str); 665 $len = \strlen($str);
666 666
667 while ($i < $len) { 667 while ($i < $len) {
668 if ($str[$i] < "\x80") { 668 if ($str[$i] < "\x80") {
669 $uchr = $str[$i++]; 669 $uchr = $str[$i++];
670 } else { 670 } else {
696 return false; 696 return false;
697 } 697 }
698 } 698 }
699 699
700 $str = $uchr.substr($str, $i); 700 $str = $uchr.substr($str, $i);
701 $len = strlen($str); 701 $len = \strlen($str);
702 $i = 0; 702 $i = 0;
703 } elseif (!$ignore) { 703 } elseif (!$ignore) {
704 return false; 704 return false;
705 } 705 }
706 } 706 }
708 return true; 708 return true;
709 } 709 }
710 710
711 private static function qpByteCallback(array $m) 711 private static function qpByteCallback(array $m)
712 { 712 {
713 return '='.strtoupper(dechex(ord($m[0]))); 713 return '='.strtoupper(dechex(\ord($m[0])));
714 } 714 }
715 715
716 private static function pregOffset($offset) 716 private static function pregOffset($offset)
717 { 717 {
718 $rx = array(); 718 $rx = array();