Completed
Push — master ( 2ffeb6...8b3ae6 )
by Lars
03:06
created
src/voku/helper/UTF8.php 1 patch
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
   public static function add_bom_to_string($str)
840 840
   {
841 841
     if (self::string_has_bom($str) === false) {
842
-      $str = self::bom() . $str;
842
+      $str = self::bom().$str;
843 843
     }
844 844
 
845 845
     return $str;
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
 
930 930
     // use static cache, if there is no support for "IntlChar"
931 931
     static $cache = array();
932
-    $cacheKey = $code_point . $encoding;
932
+    $cacheKey = $code_point.$encoding;
933 933
     if (isset($cache[$cacheKey]) === true) {
934 934
       return $cache[$cacheKey];
935 935
     }
@@ -937,16 +937,16 @@  discard block
 block discarded – undo
937 937
     if (0x80 > $code_point %= 0x200000) {
938 938
       $str = chr($code_point);
939 939
     } elseif (0x800 > $code_point) {
940
-      $str = chr(0xC0 | $code_point >> 6) .
940
+      $str = chr(0xC0 | $code_point >> 6).
941 941
              chr(0x80 | $code_point & 0x3F);
942 942
     } elseif (0x10000 > $code_point) {
943
-      $str = chr(0xE0 | $code_point >> 12) .
944
-             chr(0x80 | $code_point >> 6 & 0x3F) .
943
+      $str = chr(0xE0 | $code_point >> 12).
944
+             chr(0x80 | $code_point >> 6 & 0x3F).
945 945
              chr(0x80 | $code_point & 0x3F);
946 946
     } else {
947
-      $str = chr(0xF0 | $code_point >> 18) .
948
-             chr(0x80 | $code_point >> 12 & 0x3F) .
949
-             chr(0x80 | $code_point >> 6 & 0x3F) .
947
+      $str = chr(0xF0 | $code_point >> 18).
948
+             chr(0x80 | $code_point >> 12 & 0x3F).
949
+             chr(0x80 | $code_point >> 6 & 0x3F).
950 950
              chr(0x80 | $code_point & 0x3F);
951 951
     }
952 952
 
@@ -1202,7 +1202,7 @@  discard block
 block discarded – undo
1202 1202
   public static function decimal_to_chr($code)
1203 1203
   {
1204 1204
     return \mb_convert_encoding(
1205
-        '&#x' . dechex($code) . ';',
1205
+        '&#x'.dechex($code).';',
1206 1206
         'UTF-8',
1207 1207
         'HTML-ENTITIES'
1208 1208
     );
@@ -1468,7 +1468,7 @@  discard block
 block discarded – undo
1468 1468
           ) {
1469 1469
             // Prevent leading combining chars
1470 1470
             // for NFC-safe concatenations.
1471
-            $var = $leading_combining . $var;
1471
+            $var = $leading_combining.$var;
1472 1472
           }
1473 1473
         }
1474 1474
         break;
@@ -1886,7 +1886,7 @@  discard block
 block discarded – undo
1886 1886
    */
1887 1887
   private static function getData($file)
1888 1888
   {
1889
-    $file = __DIR__ . '/data/' . $file . '.php';
1889
+    $file = __DIR__.'/data/'.$file.'.php';
1890 1890
     if (file_exists($file)) {
1891 1891
       /** @noinspection PhpIncludeInspection */
1892 1892
       return require $file;
@@ -1989,7 +1989,7 @@  discard block
 block discarded – undo
1989 1989
     return implode(
1990 1990
         '',
1991 1991
         array_map(
1992
-            function ($data) use ($keepAsciiChars, $encoding) {
1992
+            function($data) use ($keepAsciiChars, $encoding) {
1993 1993
               return UTF8::single_chr_html_encode($data, $keepAsciiChars, $encoding);
1994 1994
             },
1995 1995
             self::split($str)
@@ -2108,7 +2108,7 @@  discard block
 block discarded – undo
2108 2108
 
2109 2109
       $str = preg_replace_callback(
2110 2110
           "/&#\d{2,6};/",
2111
-          function ($matches) use ($encoding) {
2111
+          function($matches) use ($encoding) {
2112 2112
             $returnTmp = \mb_convert_encoding($matches[0], $encoding, 'HTML-ENTITIES');
2113 2113
 
2114 2114
             if ($returnTmp !== '"' && $returnTmp !== "'") {
@@ -2407,9 +2407,9 @@  discard block
 block discarded – undo
2407 2407
     if (ctype_digit((string)$int)) {
2408 2408
       $hex = dechex((int)$int);
2409 2409
 
2410
-      $hex = (strlen($hex) < 4 ? substr('0000' . $hex, -4) : $hex);
2410
+      $hex = (strlen($hex) < 4 ? substr('0000'.$hex, -4) : $hex);
2411 2411
 
2412
-      return $pfix . $hex;
2412
+      return $pfix.$hex;
2413 2413
     }
2414 2414
 
2415 2415
     return '';
@@ -3095,7 +3095,7 @@  discard block
 block discarded – undo
3095 3095
    */
3096 3096
   public static function lcfirst($str)
3097 3097
   {
3098
-    return self::strtolower(self::substr($str, 0, 1)) . self::substr($str, 1);
3098
+    return self::strtolower(self::substr($str, 0, 1)).self::substr($str, 1);
3099 3099
   }
3100 3100
 
3101 3101
   /**
@@ -3119,7 +3119,7 @@  discard block
 block discarded – undo
3119 3119
       return preg_replace('/^[\pZ\pC]+/u', '', $str);
3120 3120
     }
3121 3121
 
3122
-    return preg_replace("/^" . self::rxClass($chars) . "+/u", '', $str);
3122
+    return preg_replace("/^".self::rxClass($chars)."+/u", '', $str);
3123 3123
   }
3124 3124
 
3125 3125
   /**
@@ -3565,7 +3565,7 @@  discard block
 block discarded – undo
3565 3565
     if (is_array($what)) {
3566 3566
       /** @noinspection ForeachSourceInspection */
3567 3567
       foreach ($what as $item) {
3568
-        $str = preg_replace('/(' . preg_quote($item, '/') . ')+/', $item, $str);
3568
+        $str = preg_replace('/('.preg_quote($item, '/').')+/', $item, $str);
3569 3569
       }
3570 3570
     }
3571 3571
 
@@ -3650,7 +3650,7 @@  discard block
 block discarded – undo
3650 3650
       return preg_replace('/[\pZ\pC]+$/u', '', $str);
3651 3651
     }
3652 3652
 
3653
-    return preg_replace("/" . self::rxClass($chars) . "+$/u", '', $str);
3653
+    return preg_replace("/".self::rxClass($chars)."+$/u", '', $str);
3654 3654
   }
3655 3655
 
3656 3656
   /**
@@ -3665,7 +3665,7 @@  discard block
 block discarded – undo
3665 3665
   {
3666 3666
     static $rxClassCache = array();
3667 3667
 
3668
-    $cacheKey = $s . $class;
3668
+    $cacheKey = $s.$class;
3669 3669
 
3670 3670
     if (isset($rxClassCache[$cacheKey])) {
3671 3671
       return $rxClassCache[$cacheKey];
@@ -3677,7 +3677,7 @@  discard block
 block discarded – undo
3677 3677
     /** @noinspection SuspiciousLoopInspection */
3678 3678
     foreach (self::str_split($s) as $s) {
3679 3679
       if ('-' === $s) {
3680
-        $class[0] = '-' . $class[0];
3680
+        $class[0] = '-'.$class[0];
3681 3681
       } elseif (!isset($s[2])) {
3682 3682
         $class[0] .= preg_quote($s, '/');
3683 3683
       } elseif (1 === self::strlen($s)) {
@@ -3688,13 +3688,13 @@  discard block
 block discarded – undo
3688 3688
     }
3689 3689
 
3690 3690
     if ($class[0]) {
3691
-      $class[0] = '[' . $class[0] . ']';
3691
+      $class[0] = '['.$class[0].']';
3692 3692
     }
3693 3693
 
3694 3694
     if (1 === count($class)) {
3695 3695
       $return = $class[0];
3696 3696
     } else {
3697
-      $return = '(?:' . implode('|', $class) . ')';
3697
+      $return = '(?:'.implode('|', $class).')';
3698 3698
     }
3699 3699
 
3700 3700
     $rxClassCache[$cacheKey] = $return;
@@ -3708,7 +3708,7 @@  discard block
 block discarded – undo
3708 3708
   public static function showSupport()
3709 3709
   {
3710 3710
     foreach (self::$support as $utf8Support) {
3711
-      echo $utf8Support . "\n<br>";
3711
+      echo $utf8Support."\n<br>";
3712 3712
     }
3713 3713
   }
3714 3714
 
@@ -3742,7 +3742,7 @@  discard block
 block discarded – undo
3742 3742
       $encoding = self::normalize_encoding($encoding);
3743 3743
     }
3744 3744
 
3745
-    return '&#' . self::ord($char, $encoding) . ';';
3745
+    return '&#'.self::ord($char, $encoding).';';
3746 3746
   }
3747 3747
 
3748 3748
   /**
@@ -3794,19 +3794,19 @@  discard block
 block discarded – undo
3794 3794
           $ret[] = $str[$i];
3795 3795
         } elseif ((($str[$i] & "\xE0") === "\xC0") && isset($str[$i + 1])) {
3796 3796
           if (($str[$i + 1] & "\xC0") === "\x80") {
3797
-            $ret[] = $str[$i] . $str[$i + 1];
3797
+            $ret[] = $str[$i].$str[$i + 1];
3798 3798
 
3799 3799
             $i++;
3800 3800
           }
3801 3801
         } elseif ((($str[$i] & "\xF0") === "\xE0") && isset($str[$i + 2])) {
3802 3802
           if ((($str[$i + 1] & "\xC0") === "\x80") && (($str[$i + 2] & "\xC0") === "\x80")) {
3803
-            $ret[] = $str[$i] . $str[$i + 1] . $str[$i + 2];
3803
+            $ret[] = $str[$i].$str[$i + 1].$str[$i + 2];
3804 3804
 
3805 3805
             $i += 2;
3806 3806
           }
3807 3807
         } elseif ((($str[$i] & "\xF8") === "\xF0") && isset($str[$i + 3])) {
3808 3808
           if ((($str[$i + 1] & "\xC0") === "\x80") && (($str[$i + 2] & "\xC0") === "\x80") && (($str[$i + 3] & "\xC0") === "\x80")) {
3809
-            $ret[] = $str[$i] . $str[$i + 1] . $str[$i + 2] . $str[$i + 3];
3809
+            $ret[] = $str[$i].$str[$i + 1].$str[$i + 2].$str[$i + 3];
3810 3810
 
3811 3811
             $i += 3;
3812 3812
           }
@@ -4005,7 +4005,7 @@  discard block
 block discarded – undo
4005 4005
       if ('' === $s .= '') {
4006 4006
         $s = '/^(?<=.)$/';
4007 4007
       } else {
4008
-        $s = '/' . preg_quote($s, '/') . '/ui';
4008
+        $s = '/'.preg_quote($s, '/').'/ui';
4009 4009
       }
4010 4010
     }
4011 4011
 
@@ -4063,7 +4063,7 @@  discard block
 block discarded – undo
4063 4063
     }
4064 4064
 
4065 4065
     if (self::substr($str, $length - 1, 1) === ' ') {
4066
-      return self::substr($str, 0, $length - 1) . $strAddOn;
4066
+      return self::substr($str, 0, $length - 1).$strAddOn;
4067 4067
     }
4068 4068
 
4069 4069
     $str = self::substr($str, 0, $length);
@@ -4072,9 +4072,9 @@  discard block
 block discarded – undo
4072 4072
     $new_str = implode(' ', $array);
4073 4073
 
4074 4074
     if ($new_str === '') {
4075
-      $str = self::substr($str, 0, $length - 1) . $strAddOn;
4075
+      $str = self::substr($str, 0, $length - 1).$strAddOn;
4076 4076
     } else {
4077
-      $str = $new_str . $strAddOn;
4077
+      $str = $new_str.$strAddOn;
4078 4078
     }
4079 4079
 
4080 4080
     return $str;
@@ -4129,7 +4129,7 @@  discard block
 block discarded – undo
4129 4129
           $pre = '';
4130 4130
       }
4131 4131
 
4132
-      return $pre . $str . $post;
4132
+      return $pre.$str.$post;
4133 4133
     }
4134 4134
 
4135 4135
     return $str;
@@ -4259,7 +4259,7 @@  discard block
 block discarded – undo
4259 4259
     }
4260 4260
 
4261 4261
     /** @noinspection PhpInternalEntityUsedInspection */
4262
-    preg_match_all('/' . Grapheme::GRAPHEME_CLUSTER_RX . '/u', $str, $a);
4262
+    preg_match_all('/'.Grapheme::GRAPHEME_CLUSTER_RX.'/u', $str, $a);
4263 4263
     $a = $a[0];
4264 4264
 
4265 4265
     if ($len === 1) {
@@ -4434,7 +4434,7 @@  discard block
 block discarded – undo
4434 4434
   public static function strcmp($str1, $str2)
4435 4435
   {
4436 4436
     /** @noinspection PhpUndefinedClassInspection */
4437
-    return $str1 . '' === $str2 . '' ? 0 : strcmp(
4437
+    return $str1.'' === $str2.'' ? 0 : strcmp(
4438 4438
         \Normalizer::normalize($str1, \Normalizer::NFD),
4439 4439
         \Normalizer::normalize($str2, \Normalizer::NFD)
4440 4440
     );
@@ -4465,7 +4465,7 @@  discard block
 block discarded – undo
4465 4465
       return null;
4466 4466
     }
4467 4467
 
4468
-    if (preg_match('/^(.*?)' . self::rxClass($charList) . '/us', $str, $length)) {
4468
+    if (preg_match('/^(.*?)'.self::rxClass($charList).'/us', $str, $length)) {
4469 4469
       /** @noinspection OffsetOperationsInspection */
4470 4470
       return self::strlen($length[1]);
4471 4471
     }
@@ -4722,7 +4722,7 @@  discard block
 block discarded – undo
4722 4722
    */
4723 4723
   public static function strnatcmp($str1, $str2)
4724 4724
   {
4725
-    return $str1 . '' === $str2 . '' ? 0 : strnatcmp(self::strtonatfold($str1), self::strtonatfold($str2));
4725
+    return $str1.'' === $str2.'' ? 0 : strnatcmp(self::strtonatfold($str1), self::strtonatfold($str2));
4726 4726
   }
4727 4727
 
4728 4728
   /**
@@ -4783,7 +4783,7 @@  discard block
 block discarded – undo
4783 4783
       return false;
4784 4784
     }
4785 4785
 
4786
-    if (preg_match('/' . self::rxClass($char_list) . '/us', $haystack, $m)) {
4786
+    if (preg_match('/'.self::rxClass($char_list).'/us', $haystack, $m)) {
4787 4787
       return substr($haystack, strpos($haystack, $m[0]));
4788 4788
     } else {
4789 4789
       return false;
@@ -5099,7 +5099,7 @@  discard block
 block discarded – undo
5099 5099
       return 0;
5100 5100
     }
5101 5101
 
5102
-    return preg_match('/^' . self::rxClass($mask) . '+/u', $str, $str) ? self::strlen($str[0]) : 0;
5102
+    return preg_match('/^'.self::rxClass($mask).'+/u', $str, $str) ? self::strlen($str[0]) : 0;
5103 5103
   }
5104 5104
 
5105 5105
   /**
@@ -5499,7 +5499,7 @@  discard block
 block discarded – undo
5499 5499
       return \mb_substr_count($haystack, $needle, $encoding);
5500 5500
     }
5501 5501
 
5502
-    preg_match_all('/' . preg_quote($needle, '/') . '/us', $haystack, $matches, PREG_SET_ORDER);
5502
+    preg_match_all('/'.preg_quote($needle, '/').'/us', $haystack, $matches, PREG_SET_ORDER);
5503 5503
     return count($matches);
5504 5504
   }
5505 5505
 
@@ -5720,7 +5720,7 @@  discard block
 block discarded – undo
5720 5720
 
5721 5721
     $strSwappedCase = preg_replace_callback(
5722 5722
         '/[\S]/u',
5723
-        function ($match) use ($encoding) {
5723
+        function($match) use ($encoding) {
5724 5724
           $marchToUpper = UTF8::strtoupper($match[0], $encoding);
5725 5725
 
5726 5726
           if ($match[0] === $marchToUpper) {
@@ -5902,7 +5902,7 @@  discard block
 block discarded – undo
5902 5902
 
5903 5903
       $bank = $ord >> 8;
5904 5904
       if (!array_key_exists($bank, (array)$UTF8_TO_ASCII)) {
5905
-        $bankfile = __DIR__ . '/data/' . sprintf('x%02x', $bank) . '.php';
5905
+        $bankfile = __DIR__.'/data/'.sprintf('x%02x', $bank).'.php';
5906 5906
         if (file_exists($bankfile)) {
5907 5907
           /** @noinspection PhpIncludeInspection */
5908 5908
           require $bankfile;
@@ -6023,40 +6023,40 @@  discard block
 block discarded – undo
6023 6023
         if ($c1 >= "\xc0" & $c1 <= "\xdf") { // looks like 2 bytes UTF8
6024 6024
 
6025 6025
           if ($c2 >= "\x80" && $c2 <= "\xbf") { // yeah, almost sure it's UTF8 already
6026
-            $buf .= $c1 . $c2;
6026
+            $buf .= $c1.$c2;
6027 6027
             $i++;
6028 6028
           } else { // not valid UTF8 - convert it
6029 6029
             $cc1 = (chr(ord($c1) / 64) | "\xc0");
6030 6030
             $cc2 = ($c1 & "\x3f") | "\x80";
6031
-            $buf .= $cc1 . $cc2;
6031
+            $buf .= $cc1.$cc2;
6032 6032
           }
6033 6033
 
6034 6034
         } elseif ($c1 >= "\xe0" & $c1 <= "\xef") { // looks like 3 bytes UTF8
6035 6035
 
6036 6036
           if ($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf") { // yeah, almost sure it's UTF8 already
6037
-            $buf .= $c1 . $c2 . $c3;
6037
+            $buf .= $c1.$c2.$c3;
6038 6038
             $i += 2;
6039 6039
           } else { // not valid UTF8 - convert it
6040 6040
             $cc1 = (chr(ord($c1) / 64) | "\xc0");
6041 6041
             $cc2 = ($c1 & "\x3f") | "\x80";
6042
-            $buf .= $cc1 . $cc2;
6042
+            $buf .= $cc1.$cc2;
6043 6043
           }
6044 6044
 
6045 6045
         } elseif ($c1 >= "\xf0" & $c1 <= "\xf7") { // looks like 4 bytes UTF8
6046 6046
 
6047 6047
           if ($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf" && $c4 >= "\x80" && $c4 <= "\xbf") { // yeah, almost sure it's UTF8 already
6048
-            $buf .= $c1 . $c2 . $c3 . $c4;
6048
+            $buf .= $c1.$c2.$c3.$c4;
6049 6049
             $i += 3;
6050 6050
           } else { // not valid UTF8 - convert it
6051 6051
             $cc1 = (chr(ord($c1) / 64) | "\xc0");
6052 6052
             $cc2 = ($c1 & "\x3f") | "\x80";
6053
-            $buf .= $cc1 . $cc2;
6053
+            $buf .= $cc1.$cc2;
6054 6054
           }
6055 6055
 
6056 6056
         } else { // doesn't look like UTF8, but should be converted
6057 6057
           $cc1 = (chr(ord($c1) / 64) | "\xc0");
6058 6058
           $cc2 = (($c1 & "\x3f") | "\x80");
6059
-          $buf .= $cc1 . $cc2;
6059
+          $buf .= $cc1.$cc2;
6060 6060
         }
6061 6061
 
6062 6062
       } elseif (($c1 & "\xc0") === "\x80") { // needs conversion
@@ -6067,7 +6067,7 @@  discard block
 block discarded – undo
6067 6067
         } else {
6068 6068
           $cc1 = (chr($ordC1 / 64) | "\xc0");
6069 6069
           $cc2 = (($c1 & "\x3f") | "\x80");
6070
-          $buf .= $cc1 . $cc2;
6070
+          $buf .= $cc1.$cc2;
6071 6071
         }
6072 6072
 
6073 6073
       } else { // it doesn't need conversion
@@ -6078,7 +6078,7 @@  discard block
 block discarded – undo
6078 6078
     // decode unicode escape sequences
6079 6079
     $buf = preg_replace_callback(
6080 6080
         '/\\\\u([0-9a-f]{4})/i',
6081
-        function ($match) {
6081
+        function($match) {
6082 6082
           return \mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
6083 6083
         },
6084 6084
         $buf
@@ -6087,7 +6087,7 @@  discard block
 block discarded – undo
6087 6087
     // decode UTF-8 codepoints
6088 6088
     $buf = preg_replace_callback(
6089 6089
         '/&#\d{2,6};/',
6090
-        function ($match) {
6090
+        function($match) {
6091 6091
           return \mb_convert_encoding($match[0], 'UTF-8', 'HTML-ENTITIES');
6092 6092
         },
6093 6093
         $buf
@@ -6136,7 +6136,7 @@  discard block
 block discarded – undo
6136 6136
    */
6137 6137
   public static function ucfirst($str, $encoding = 'UTF-8', $cleanUtf8 = false)
6138 6138
   {
6139
-    return self::strtoupper(self::substr($str, 0, 1, $encoding, $cleanUtf8), $encoding, $cleanUtf8) . self::substr($str, 1, null, $encoding, $cleanUtf8);
6139
+    return self::strtoupper(self::substr($str, 0, 1, $encoding, $cleanUtf8), $encoding, $cleanUtf8).self::substr($str, 1, null, $encoding, $cleanUtf8);
6140 6140
   }
6141 6141
 
6142 6142
   /**
@@ -6665,7 +6665,7 @@  discard block
 block discarded – undo
6665 6665
       return '';
6666 6666
     }
6667 6667
 
6668
-    preg_match('/^\s*+(?:\S++\s*+){1,' . $words . '}/u', $str, $matches);
6668
+    preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $str, $matches);
6669 6669
 
6670 6670
     if (
6671 6671
         !isset($matches[0])
@@ -6675,7 +6675,7 @@  discard block
 block discarded – undo
6675 6675
       return $str;
6676 6676
     }
6677 6677
 
6678
-    return self::rtrim($matches[0]) . $strAddOn;
6678
+    return self::rtrim($matches[0]).$strAddOn;
6679 6679
   }
6680 6680
 
6681 6681
   /**
@@ -6743,7 +6743,7 @@  discard block
 block discarded – undo
6743 6743
       $strReturn .= $break;
6744 6744
     }
6745 6745
 
6746
-    return $strReturn . implode('', $chars);
6746
+    return $strReturn.implode('', $chars);
6747 6747
   }
6748 6748
 
6749 6749
   /**
Please login to merge, or discard this patch.