Completed
Push — master ( 3623fb...b828c0 )
by Lars
03:58
created
src/voku/helper/UTF8.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
   public static function add_bom_to_string($str)
835 835
   {
836 836
     if (self::string_has_bom($str) === false) {
837
-      $str = self::bom() . $str;
837
+      $str = self::bom().$str;
838 838
     }
839 839
 
840 840
     return $str;
@@ -931,20 +931,20 @@  discard block
 block discarded – undo
931 931
     }
932 932
 
933 933
     if ($code_point <= 0x7ff) {
934
-      return $cache[$code_point] = chr(0xc0 | ($code_point >> 6)) .
934
+      return $cache[$code_point] = chr(0xc0 | ($code_point >> 6)).
935 935
                                    chr(0x80 | ($code_point & 0x3f));
936 936
     }
937 937
 
938 938
     if ($code_point <= 0xffff) {
939
-      return $cache[$code_point] = chr(0xe0 | ($code_point >> 12)) .
940
-                                   chr(0x80 | (($code_point >> 6) & 0x3f)) .
939
+      return $cache[$code_point] = chr(0xe0 | ($code_point >> 12)).
940
+                                   chr(0x80 | (($code_point >> 6) & 0x3f)).
941 941
                                    chr(0x80 | ($code_point & 0x3f));
942 942
     }
943 943
 
944 944
     if ($code_point <= 0x10ffff) {
945
-      return $cache[$code_point] = chr(0xf0 | ($code_point >> 18)) .
946
-                                   chr(0x80 | (($code_point >> 12) & 0x3f)) .
947
-                                   chr(0x80 | (($code_point >> 6) & 0x3f)) .
945
+      return $cache[$code_point] = chr(0xf0 | ($code_point >> 18)).
946
+                                   chr(0x80 | (($code_point >> 12) & 0x3f)).
947
+                                   chr(0x80 | (($code_point >> 6) & 0x3f)).
948 948
                                    chr(0x80 | ($code_point & 0x3f));
949 949
     }
950 950
 
@@ -1194,7 +1194,7 @@  discard block
 block discarded – undo
1194 1194
   public static function decimal_to_chr($code)
1195 1195
   {
1196 1196
     return \mb_convert_encoding(
1197
-        '&#x' . dechex($code) . ';',
1197
+        '&#x'.dechex($code).';',
1198 1198
         'UTF-8',
1199 1199
         'HTML-ENTITIES'
1200 1200
     );
@@ -1458,7 +1458,7 @@  discard block
 block discarded – undo
1458 1458
           ) {
1459 1459
             // Prevent leading combining chars
1460 1460
             // for NFC-safe concatenations.
1461
-            $var = $leading_combining . $var;
1461
+            $var = $leading_combining.$var;
1462 1462
           }
1463 1463
         }
1464 1464
         break;
@@ -1751,7 +1751,7 @@  discard block
 block discarded – undo
1751 1751
    */
1752 1752
   private static function getData($file)
1753 1753
   {
1754
-    $file = __DIR__ . '/data/' . $file . '.php';
1754
+    $file = __DIR__.'/data/'.$file.'.php';
1755 1755
     if (file_exists($file)) {
1756 1756
       /** @noinspection PhpIncludeInspection */
1757 1757
       return require $file;
@@ -1832,7 +1832,7 @@  discard block
 block discarded – undo
1832 1832
 
1833 1833
     return implode(
1834 1834
         array_map(
1835
-            function ($data) use ($keepAsciiChars) {
1835
+            function($data) use ($keepAsciiChars) {
1836 1836
               return UTF8::single_chr_html_encode($data, $keepAsciiChars);
1837 1837
             },
1838 1838
             self::split($str)
@@ -1946,7 +1946,7 @@  discard block
 block discarded – undo
1946 1946
 
1947 1947
       $str = preg_replace_callback(
1948 1948
           "/&#\d{2,5};/",
1949
-          function ($matches) use ($encoding) {
1949
+          function($matches) use ($encoding) {
1950 1950
             $returnTmp = \mb_convert_encoding($matches[0], $encoding, 'HTML-ENTITIES');
1951 1951
 
1952 1952
             if ($returnTmp !== '"' && $returnTmp !== "'") {
@@ -2245,9 +2245,9 @@  discard block
 block discarded – undo
2245 2245
     if (ctype_digit((string)$int)) {
2246 2246
       $hex = dechex((int)$int);
2247 2247
 
2248
-      $hex = (strlen($hex) < 4 ? substr('0000' . $hex, -4) : $hex);
2248
+      $hex = (strlen($hex) < 4 ? substr('0000'.$hex, -4) : $hex);
2249 2249
 
2250
-      return $pfix . $hex;
2250
+      return $pfix.$hex;
2251 2251
     }
2252 2252
 
2253 2253
     return '';
@@ -2933,7 +2933,7 @@  discard block
 block discarded – undo
2933 2933
    */
2934 2934
   public static function lcfirst($str)
2935 2935
   {
2936
-    return self::strtolower(self::substr($str, 0, 1)) . self::substr($str, 1);
2936
+    return self::strtolower(self::substr($str, 0, 1)).self::substr($str, 1);
2937 2937
   }
2938 2938
 
2939 2939
   /**
@@ -3383,7 +3383,7 @@  discard block
 block discarded – undo
3383 3383
 
3384 3384
     if (is_array($what)) {
3385 3385
       foreach ($what as $item) {
3386
-        $str = preg_replace('/(' . preg_quote($item, '/') . ')+/', $item, $str);
3386
+        $str = preg_replace('/('.preg_quote($item, '/').')+/', $item, $str);
3387 3387
       }
3388 3388
     }
3389 3389
 
@@ -3485,7 +3485,7 @@  discard block
 block discarded – undo
3485 3485
   {
3486 3486
     static $rxClassCache = array();
3487 3487
 
3488
-    $cacheKey = $s . $class;
3488
+    $cacheKey = $s.$class;
3489 3489
 
3490 3490
     if (isset($rxClassCache[$cacheKey])) {
3491 3491
       return $rxClassCache[$cacheKey];
@@ -3496,7 +3496,7 @@  discard block
 block discarded – undo
3496 3496
     /** @noinspection SuspiciousLoopInspection */
3497 3497
     foreach (self::str_split($s) as $s) {
3498 3498
       if ('-' === $s) {
3499
-        $class[0] = '-' . $class[0];
3499
+        $class[0] = '-'.$class[0];
3500 3500
       } elseif (!isset($s[2])) {
3501 3501
         $class[0] .= preg_quote($s, '/');
3502 3502
       } elseif (1 === self::strlen($s)) {
@@ -3507,13 +3507,13 @@  discard block
 block discarded – undo
3507 3507
     }
3508 3508
 
3509 3509
     if ($class[0]) {
3510
-      $class[0] = '[' . $class[0] . ']';
3510
+      $class[0] = '['.$class[0].']';
3511 3511
     }
3512 3512
 
3513 3513
     if (1 === count($class)) {
3514 3514
       $return = $class[0];
3515 3515
     } else {
3516
-      $return = '(?:' . implode('|', $class) . ')';
3516
+      $return = '(?:'.implode('|', $class).')';
3517 3517
     }
3518 3518
 
3519 3519
     $rxClassCache[$cacheKey] = $return;
@@ -3527,7 +3527,7 @@  discard block
 block discarded – undo
3527 3527
   public static function showSupport()
3528 3528
   {
3529 3529
     foreach (self::$support as $utf8Support) {
3530
-      echo $utf8Support . "\n<br>";
3530
+      echo $utf8Support."\n<br>";
3531 3531
     }
3532 3532
   }
3533 3533
 
@@ -3553,7 +3553,7 @@  discard block
 block discarded – undo
3553 3553
       return $char;
3554 3554
     }
3555 3555
 
3556
-    return '&#' . self::ord($char) . ';';
3556
+    return '&#'.self::ord($char).';';
3557 3557
   }
3558 3558
 
3559 3559
   /**
@@ -3605,19 +3605,19 @@  discard block
 block discarded – undo
3605 3605
           $ret[] = $str[$i];
3606 3606
         } elseif ((($str[$i] & "\xE0") === "\xC0") && isset($str[$i + 1])) {
3607 3607
           if (($str[$i + 1] & "\xC0") === "\x80") {
3608
-            $ret[] = $str[$i] . $str[$i + 1];
3608
+            $ret[] = $str[$i].$str[$i + 1];
3609 3609
 
3610 3610
             $i++;
3611 3611
           }
3612 3612
         } elseif ((($str[$i] & "\xF0") === "\xE0") && isset($str[$i + 2])) {
3613 3613
           if ((($str[$i + 1] & "\xC0") === "\x80") && (($str[$i + 2] & "\xC0") === "\x80")) {
3614
-            $ret[] = $str[$i] . $str[$i + 1] . $str[$i + 2];
3614
+            $ret[] = $str[$i].$str[$i + 1].$str[$i + 2];
3615 3615
 
3616 3616
             $i += 2;
3617 3617
           }
3618 3618
         } elseif ((($str[$i] & "\xF8") === "\xF0") && isset($str[$i + 3])) {
3619 3619
           if ((($str[$i + 1] & "\xC0") === "\x80") && (($str[$i + 2] & "\xC0") === "\x80") && (($str[$i + 3] & "\xC0") === "\x80")) {
3620
-            $ret[] = $str[$i] . $str[$i + 1] . $str[$i + 2] . $str[$i + 3];
3620
+            $ret[] = $str[$i].$str[$i + 1].$str[$i + 2].$str[$i + 3];
3621 3621
 
3622 3622
             $i += 3;
3623 3623
           }
@@ -3766,7 +3766,7 @@  discard block
 block discarded – undo
3766 3766
       if ('' === $s .= '') {
3767 3767
         $s = '/^(?<=.)$/';
3768 3768
       } else {
3769
-        $s = '/' . preg_quote($s, '/') . '/ui';
3769
+        $s = '/'.preg_quote($s, '/').'/ui';
3770 3770
       }
3771 3771
     }
3772 3772
 
@@ -3800,7 +3800,7 @@  discard block
 block discarded – undo
3800 3800
     }
3801 3801
 
3802 3802
     if (self::substr($str, $length - 1, 1) === ' ') {
3803
-      return self::substr($str, 0, $length - 1) . $strAddOn;
3803
+      return self::substr($str, 0, $length - 1).$strAddOn;
3804 3804
     }
3805 3805
 
3806 3806
     $str = self::substr($str, 0, $length);
@@ -3809,9 +3809,9 @@  discard block
 block discarded – undo
3809 3809
     $new_str = implode(' ', $array);
3810 3810
 
3811 3811
     if ($new_str === '') {
3812
-      $str = self::substr($str, 0, $length - 1) . $strAddOn;
3812
+      $str = self::substr($str, 0, $length - 1).$strAddOn;
3813 3813
     } else {
3814
-      $str = $new_str . $strAddOn;
3814
+      $str = $new_str.$strAddOn;
3815 3815
     }
3816 3816
 
3817 3817
     return $str;
@@ -3866,7 +3866,7 @@  discard block
 block discarded – undo
3866 3866
           $pre = '';
3867 3867
       }
3868 3868
 
3869
-      return $pre . $str . $post;
3869
+      return $pre.$str.$post;
3870 3870
     }
3871 3871
 
3872 3872
     return $str;
@@ -3995,7 +3995,7 @@  discard block
 block discarded – undo
3995 3995
       return str_split($str, $len);
3996 3996
     }
3997 3997
 
3998
-    preg_match_all('/' . Grapheme::GRAPHEME_CLUSTER_RX . '/u', $str, $a);
3998
+    preg_match_all('/'.Grapheme::GRAPHEME_CLUSTER_RX.'/u', $str, $a);
3999 3999
     $a = $a[0];
4000 4000
 
4001 4001
     if ($len === 1) {
@@ -4128,7 +4128,7 @@  discard block
 block discarded – undo
4128 4128
    */
4129 4129
   public static function strcmp($str1, $str2)
4130 4130
   {
4131
-    return $str1 . '' === $str2 . '' ? 0 : strcmp(
4131
+    return $str1.'' === $str2.'' ? 0 : strcmp(
4132 4132
         \Normalizer::normalize($str1, \Normalizer::NFD),
4133 4133
         \Normalizer::normalize($str2, \Normalizer::NFD)
4134 4134
     );
@@ -4159,7 +4159,7 @@  discard block
 block discarded – undo
4159 4159
       return null;
4160 4160
     }
4161 4161
 
4162
-    if (preg_match('/^(.*?)' . self::rxClass($charList) . '/us', $str, $length)) {
4162
+    if (preg_match('/^(.*?)'.self::rxClass($charList).'/us', $str, $length)) {
4163 4163
       /** @noinspection OffsetOperationsInspection */
4164 4164
       return self::strlen($length[1]);
4165 4165
     }
@@ -4401,7 +4401,7 @@  discard block
 block discarded – undo
4401 4401
    */
4402 4402
   public static function strnatcmp($str1, $str2)
4403 4403
   {
4404
-    return $str1 . '' === $str2 . '' ? 0 : strnatcmp(self::strtonatfold($str1), self::strtonatfold($str2));
4404
+    return $str1.'' === $str2.'' ? 0 : strnatcmp(self::strtonatfold($str1), self::strtonatfold($str2));
4405 4405
   }
4406 4406
 
4407 4407
   /**
@@ -4462,7 +4462,7 @@  discard block
 block discarded – undo
4462 4462
       return false;
4463 4463
     }
4464 4464
 
4465
-    if (preg_match('/' . self::rxClass($char_list) . '/us', $haystack, $m)) {
4465
+    if (preg_match('/'.self::rxClass($char_list).'/us', $haystack, $m)) {
4466 4466
       return substr($haystack, strpos($haystack, $m[0]));
4467 4467
     } else {
4468 4468
       return false;
@@ -4776,7 +4776,7 @@  discard block
 block discarded – undo
4776 4776
       return '';
4777 4777
     }
4778 4778
 
4779
-    return preg_match('/^' . self::rxClass($mask) . '+/u', $str, $str) ? self::strlen($str[0]) : 0;
4779
+    return preg_match('/^'.self::rxClass($mask).'+/u', $str, $str) ? self::strlen($str[0]) : 0;
4780 4780
   }
4781 4781
 
4782 4782
   /**
@@ -5213,7 +5213,7 @@  discard block
 block discarded – undo
5213 5213
 
5214 5214
     $strSwappedCase = preg_replace_callback(
5215 5215
         '/[\S]/u',
5216
-        function ($match) use ($encoding) {
5216
+        function($match) use ($encoding) {
5217 5217
           $marchToUpper = UTF8::strtoupper($match[0], $encoding);
5218 5218
 
5219 5219
           if ($match[0] === $marchToUpper) {
@@ -5381,7 +5381,7 @@  discard block
 block discarded – undo
5381 5381
 
5382 5382
       $bank = $ord >> 8;
5383 5383
       if (!array_key_exists($bank, (array)$UTF8_TO_ASCII)) {
5384
-        $bankfile = __DIR__ . '/data/' . sprintf('x%02x', $bank) . '.php';
5384
+        $bankfile = __DIR__.'/data/'.sprintf('x%02x', $bank).'.php';
5385 5385
         if (file_exists($bankfile)) {
5386 5386
           /** @noinspection PhpIncludeInspection */
5387 5387
           require $bankfile;
@@ -5485,40 +5485,40 @@  discard block
 block discarded – undo
5485 5485
         if ($c1 >= "\xc0" & $c1 <= "\xdf") { // looks like 2 bytes UTF8
5486 5486
 
5487 5487
           if ($c2 >= "\x80" && $c2 <= "\xbf") { // yeah, almost sure it's UTF8 already
5488
-            $buf .= $c1 . $c2;
5488
+            $buf .= $c1.$c2;
5489 5489
             $i++;
5490 5490
           } else { // not valid UTF8 - convert it
5491 5491
             $cc1 = (chr(ord($c1) / 64) | "\xc0");
5492 5492
             $cc2 = ($c1 & "\x3f") | "\x80";
5493
-            $buf .= $cc1 . $cc2;
5493
+            $buf .= $cc1.$cc2;
5494 5494
           }
5495 5495
 
5496 5496
         } elseif ($c1 >= "\xe0" & $c1 <= "\xef") { // looks like 3 bytes UTF8
5497 5497
 
5498 5498
           if ($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf") { // yeah, almost sure it's UTF8 already
5499
-            $buf .= $c1 . $c2 . $c3;
5499
+            $buf .= $c1.$c2.$c3;
5500 5500
             $i += 2;
5501 5501
           } else { // not valid UTF8 - convert it
5502 5502
             $cc1 = (chr(ord($c1) / 64) | "\xc0");
5503 5503
             $cc2 = ($c1 & "\x3f") | "\x80";
5504
-            $buf .= $cc1 . $cc2;
5504
+            $buf .= $cc1.$cc2;
5505 5505
           }
5506 5506
 
5507 5507
         } elseif ($c1 >= "\xf0" & $c1 <= "\xf7") { // looks like 4 bytes UTF8
5508 5508
 
5509 5509
           if ($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf" && $c4 >= "\x80" && $c4 <= "\xbf") { // yeah, almost sure it's UTF8 already
5510
-            $buf .= $c1 . $c2 . $c3 . $c4;
5510
+            $buf .= $c1.$c2.$c3.$c4;
5511 5511
             $i += 3;
5512 5512
           } else { // not valid UTF8 - convert it
5513 5513
             $cc1 = (chr(ord($c1) / 64) | "\xc0");
5514 5514
             $cc2 = ($c1 & "\x3f") | "\x80";
5515
-            $buf .= $cc1 . $cc2;
5515
+            $buf .= $cc1.$cc2;
5516 5516
           }
5517 5517
 
5518 5518
         } else { // doesn't look like UTF8, but should be converted
5519 5519
           $cc1 = (chr(ord($c1) / 64) | "\xc0");
5520 5520
           $cc2 = (($c1 & "\x3f") | "\x80");
5521
-          $buf .= $cc1 . $cc2;
5521
+          $buf .= $cc1.$cc2;
5522 5522
         }
5523 5523
 
5524 5524
       } elseif (($c1 & "\xc0") === "\x80") { // needs conversion
@@ -5529,7 +5529,7 @@  discard block
 block discarded – undo
5529 5529
         } else {
5530 5530
           $cc1 = (chr($ordC1 / 64) | "\xc0");
5531 5531
           $cc2 = (($c1 & "\x3f") | "\x80");
5532
-          $buf .= $cc1 . $cc2;
5532
+          $buf .= $cc1.$cc2;
5533 5533
         }
5534 5534
 
5535 5535
       } else { // it doesn't need conversion
@@ -5540,7 +5540,7 @@  discard block
 block discarded – undo
5540 5540
     // decode unicode escape sequences
5541 5541
     $buf = preg_replace_callback(
5542 5542
         '/\\\\u([0-9a-f]{4})/i',
5543
-        function ($match) {
5543
+        function($match) {
5544 5544
           return \mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
5545 5545
         },
5546 5546
         $buf
@@ -5549,7 +5549,7 @@  discard block
 block discarded – undo
5549 5549
     // decode UTF-8 codepoints
5550 5550
     $buf = preg_replace_callback(
5551 5551
         '/&#\d{2,4};/',
5552
-        function ($match) {
5552
+        function($match) {
5553 5553
           return \mb_convert_encoding($match[0], 'UTF-8', 'HTML-ENTITIES');
5554 5554
         },
5555 5555
         $buf
@@ -5625,7 +5625,7 @@  discard block
 block discarded – undo
5625 5625
    */
5626 5626
   public static function ucfirst($str)
5627 5627
   {
5628
-    return self::strtoupper(self::substr($str, 0, 1)) . self::substr($str, 1);
5628
+    return self::strtoupper(self::substr($str, 0, 1)).self::substr($str, 1);
5629 5629
   }
5630 5630
 
5631 5631
   /**
@@ -6072,7 +6072,7 @@  discard block
 block discarded – undo
6072 6072
       return '';
6073 6073
     }
6074 6074
 
6075
-    preg_match('/^\s*+(?:\S++\s*+){1,' . $words . '}/u', $str, $matches);
6075
+    preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $str, $matches);
6076 6076
 
6077 6077
     if (
6078 6078
         !isset($matches[0])
@@ -6082,7 +6082,7 @@  discard block
 block discarded – undo
6082 6082
       return $str;
6083 6083
     }
6084 6084
 
6085
-    return self::rtrim($matches[0]) . $strAddOn;
6085
+    return self::rtrim($matches[0]).$strAddOn;
6086 6086
   }
6087 6087
 
6088 6088
   /**
@@ -6154,7 +6154,7 @@  discard block
 block discarded – undo
6154 6154
       $strReturn .= $break;
6155 6155
     }
6156 6156
 
6157
-    return $strReturn . implode('', $chars);
6157
+    return $strReturn.implode('', $chars);
6158 6158
   }
6159 6159
 
6160 6160
   /**
Please login to merge, or discard this patch.