Completed
Pull Request — master (#31)
by
unknown
04:18
created
src/voku/helper/UTF8.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
   public static function add_bom_to_string($str)
819 819
   {
820 820
     if (!self::is_bom(substr($str, 0, 3))) {
821
-      $str = self::bom() . $str;
821
+      $str = self::bom().$str;
822 822
     }
823 823
 
824 824
     return $str;
@@ -2137,7 +2137,7 @@  discard block
 block discarded – undo
2137 2137
     self::checkForSupport();
2138 2138
 
2139 2139
     return \mb_convert_encoding(
2140
-        '&#x' . dechex($code) . ';',
2140
+        '&#x'.dechex($code).';',
2141 2141
         'UTF-8',
2142 2142
         'HTML-ENTITIES'
2143 2143
     );
@@ -2415,7 +2415,7 @@  discard block
 block discarded – undo
2415 2415
           if ($var[0] >= "\x80" && isset($n[0], $leading_combining[0]) && preg_match('/^\p{Mn}/u', $var)) {
2416 2416
             // Prevent leading combining chars
2417 2417
             // for NFC-safe concatenations.
2418
-            $var = $leading_combining . $var;
2418
+            $var = $leading_combining.$var;
2419 2419
           }
2420 2420
         }
2421 2421
         break;
@@ -2682,7 +2682,7 @@  discard block
 block discarded – undo
2682 2682
    */
2683 2683
   protected static function getData($file)
2684 2684
   {
2685
-    $file = __DIR__ . '/data/' . $file . '.php';
2685
+    $file = __DIR__.'/data/'.$file.'.php';
2686 2686
     if (file_exists($file)) {
2687 2687
       /** @noinspection PhpIncludeInspection */
2688 2688
       return require $file;
@@ -3128,9 +3128,9 @@  discard block
 block discarded – undo
3128 3128
     if (ctype_digit((string)$int)) {
3129 3129
       $hex = dechex((int)$int);
3130 3130
 
3131
-      $hex = (strlen($hex) < 4 ? substr('0000' . $hex, -4) : $hex);
3131
+      $hex = (strlen($hex) < 4 ? substr('0000'.$hex, -4) : $hex);
3132 3132
 
3133
-      return $pfix . $hex;
3133
+      return $pfix.$hex;
3134 3134
     }
3135 3135
 
3136 3136
     return '';
@@ -3667,7 +3667,7 @@  discard block
 block discarded – undo
3667 3667
    */
3668 3668
   public static function lcfirst($str)
3669 3669
   {
3670
-    return self::strtolower(self::substr($str, 0, 1)) . self::substr($str, 1);
3670
+    return self::strtolower(self::substr($str, 0, 1)).self::substr($str, 1);
3671 3671
   }
3672 3672
 
3673 3673
   /**
@@ -3919,7 +3919,7 @@  discard block
 block discarded – undo
3919 3919
    */
3920 3920
   public static function ord($s)
3921 3921
   {
3922
-    if (!$s  && $s !== "0") {
3922
+    if (!$s && $s !== "0") {
3923 3923
       return 0;
3924 3924
     }
3925 3925
 
@@ -4075,7 +4075,7 @@  discard block
 block discarded – undo
4075 4075
 
4076 4076
     if (is_array($what)) {
4077 4077
       foreach ($what as $item) {
4078
-        $str = preg_replace('/(' . preg_quote($item, '/') . ')+/', $item, $str);
4078
+        $str = preg_replace('/('.preg_quote($item, '/').')+/', $item, $str);
4079 4079
       }
4080 4080
     }
4081 4081
 
@@ -4174,7 +4174,7 @@  discard block
 block discarded – undo
4174 4174
   {
4175 4175
     static $rxClassCache = array();
4176 4176
 
4177
-    $cacheKey = $s . $class;
4177
+    $cacheKey = $s.$class;
4178 4178
 
4179 4179
     if (isset($rxClassCache[$cacheKey])) {
4180 4180
       return $rxClassCache[$cacheKey];
@@ -4185,7 +4185,7 @@  discard block
 block discarded – undo
4185 4185
     /** @noinspection SuspiciousLoopInspection */
4186 4186
     foreach (self::str_split($s) as $s) {
4187 4187
       if ('-' === $s) {
4188
-        $class[0] = '-' . $class[0];
4188
+        $class[0] = '-'.$class[0];
4189 4189
       } elseif (!isset($s[2])) {
4190 4190
         $class[0] .= preg_quote($s, '/');
4191 4191
       } elseif (1 === self::strlen($s)) {
@@ -4195,12 +4195,12 @@  discard block
 block discarded – undo
4195 4195
       }
4196 4196
     }
4197 4197
 
4198
-    $class[0] = '[' . $class[0] . ']';
4198
+    $class[0] = '['.$class[0].']';
4199 4199
 
4200 4200
     if (1 === count($class)) {
4201 4201
       $return = $class[0];
4202 4202
     } else {
4203
-      $return = '(?:' . implode('|', $class) . ')';
4203
+      $return = '(?:'.implode('|', $class).')';
4204 4204
     }
4205 4205
 
4206 4206
     $rxClassCache[$cacheKey] = $return;
@@ -4214,7 +4214,7 @@  discard block
 block discarded – undo
4214 4214
   public static function showSupport()
4215 4215
   {
4216 4216
     foreach (self::$support as $utf8Support) {
4217
-      echo $utf8Support . "\n<br>";
4217
+      echo $utf8Support."\n<br>";
4218 4218
     }
4219 4219
   }
4220 4220
 
@@ -4231,7 +4231,7 @@  discard block
 block discarded – undo
4231 4231
       return '';
4232 4232
     }
4233 4233
 
4234
-    return '&#' . self::ord($chr) . ';';
4234
+    return '&#'.self::ord($chr).';';
4235 4235
   }
4236 4236
 
4237 4237
   /**
@@ -4280,19 +4280,19 @@  discard block
 block discarded – undo
4280 4280
           $ret[] = $str[$i];
4281 4281
         } elseif ((($str[$i] & "\xE0") === "\xC0") && isset($str[$i + 1])) {
4282 4282
           if (($str[$i + 1] & "\xC0") === "\x80") {
4283
-            $ret[] = $str[$i] . $str[$i + 1];
4283
+            $ret[] = $str[$i].$str[$i + 1];
4284 4284
 
4285 4285
             $i++;
4286 4286
           }
4287 4287
         } elseif ((($str[$i] & "\xF0") === "\xE0") && isset($str[$i + 2])) {
4288 4288
           if ((($str[$i + 1] & "\xC0") === "\x80") && (($str[$i + 2] & "\xC0") === "\x80")) {
4289
-            $ret[] = $str[$i] . $str[$i + 1] . $str[$i + 2];
4289
+            $ret[] = $str[$i].$str[$i + 1].$str[$i + 2];
4290 4290
 
4291 4291
             $i += 2;
4292 4292
           }
4293 4293
         } elseif ((($str[$i] & "\xF8") === "\xF0") && isset($str[$i + 3])) {
4294 4294
           if ((($str[$i + 1] & "\xC0") === "\x80") && (($str[$i + 2] & "\xC0") === "\x80") && (($str[$i + 3] & "\xC0") === "\x80")) {
4295
-            $ret[] = $str[$i] . $str[$i + 1] . $str[$i + 2] . $str[$i + 3];
4295
+            $ret[] = $str[$i].$str[$i + 1].$str[$i + 2].$str[$i + 3];
4296 4296
 
4297 4297
             $i += 3;
4298 4298
           }
@@ -4426,7 +4426,7 @@  discard block
 block discarded – undo
4426 4426
       if ('' === $s .= '') {
4427 4427
         $s = '/^(?<=.)$/';
4428 4428
       } else {
4429
-        $s = '/' . preg_quote($s, '/') . '/ui';
4429
+        $s = '/'.preg_quote($s, '/').'/ui';
4430 4430
       }
4431 4431
     }
4432 4432
 
@@ -4460,7 +4460,7 @@  discard block
 block discarded – undo
4460 4460
     }
4461 4461
 
4462 4462
     if (self::substr($str, $length - 1, 1) === ' ') {
4463
-      return self::substr($str, 0, $length - 1) . $strAddOn;
4463
+      return self::substr($str, 0, $length - 1).$strAddOn;
4464 4464
     }
4465 4465
 
4466 4466
     $str = self::substr($str, 0, $length);
@@ -4469,9 +4469,9 @@  discard block
 block discarded – undo
4469 4469
     $new_str = implode(' ', $array);
4470 4470
 
4471 4471
     if ($new_str === '') {
4472
-      $str = self::substr($str, 0, $length - 1) . $strAddOn;
4472
+      $str = self::substr($str, 0, $length - 1).$strAddOn;
4473 4473
     } else {
4474
-      $str = $new_str . $strAddOn;
4474
+      $str = $new_str.$strAddOn;
4475 4475
     }
4476 4476
 
4477 4477
     return $str;
@@ -4517,7 +4517,7 @@  discard block
 block discarded – undo
4517 4517
           $pre = '';
4518 4518
       }
4519 4519
 
4520
-      return $pre . $input . $post;
4520
+      return $pre.$input.$post;
4521 4521
     }
4522 4522
 
4523 4523
     return $input;
@@ -4651,7 +4651,7 @@  discard block
 block discarded – undo
4651 4651
         $a[] = \grapheme_extract($str, 1, GRAPHEME_EXTR_COUNT, $p, $p);
4652 4652
       }
4653 4653
     } else {
4654
-      preg_match_all('/' . Grapheme::GRAPHEME_CLUSTER_RX . '/u', $str, $a);
4654
+      preg_match_all('/'.Grapheme::GRAPHEME_CLUSTER_RX.'/u', $str, $a);
4655 4655
       $a = $a[0];
4656 4656
     }
4657 4657
 
@@ -4792,7 +4792,7 @@  discard block
 block discarded – undo
4792 4792
 
4793 4793
       $bank = $ord >> 8;
4794 4794
       if (!array_key_exists($bank, (array)$UTF8_TO_ASCII)) {
4795
-        $bankfile = __DIR__ . '/data/' . sprintf('x%02x', $bank) . '.php';
4795
+        $bankfile = __DIR__.'/data/'.sprintf('x%02x', $bank).'.php';
4796 4796
         if (file_exists($bankfile)) {
4797 4797
           /** @noinspection PhpIncludeInspection */
4798 4798
           require $bankfile;
@@ -4882,7 +4882,7 @@  discard block
 block discarded – undo
4882 4882
    */
4883 4883
   public static function strcmp($str1, $str2)
4884 4884
   {
4885
-    return $str1 . '' === $str2 . '' ? 0 : strcmp(
4885
+    return $str1.'' === $str2.'' ? 0 : strcmp(
4886 4886
         \Normalizer::normalize($str1, \Normalizer::NFD),
4887 4887
         \Normalizer::normalize($str2, \Normalizer::NFD)
4888 4888
     );
@@ -4910,7 +4910,7 @@  discard block
 block discarded – undo
4910 4910
       $str = (string)$str;
4911 4911
     }
4912 4912
 
4913
-    if (preg_match('/^(.*?)' . self::rxClass($charList) . '/us', $str, $length)) {
4913
+    if (preg_match('/^(.*?)'.self::rxClass($charList).'/us', $str, $length)) {
4914 4914
       /** @noinspection OffsetOperationsInspection */
4915 4915
       return self::strlen($length[1]);
4916 4916
     } else {
@@ -5119,7 +5119,7 @@  discard block
 block discarded – undo
5119 5119
    */
5120 5120
   public static function strnatcmp($str1, $str2)
5121 5121
   {
5122
-    return $str1 . '' === $str2 . '' ? 0 : strnatcmp(self::strtonatfold($str1), self::strtonatfold($str2));
5122
+    return $str1.'' === $str2.'' ? 0 : strnatcmp(self::strtonatfold($str1), self::strtonatfold($str2));
5123 5123
   }
5124 5124
 
5125 5125
   /**
@@ -5200,7 +5200,7 @@  discard block
 block discarded – undo
5200 5200
       return false;
5201 5201
     }
5202 5202
 
5203
-    if (preg_match('/' . self::rxClass($char_list) . '/us', $haystack, $m)) {
5203
+    if (preg_match('/'.self::rxClass($char_list).'/us', $haystack, $m)) {
5204 5204
       return substr($haystack, strpos($haystack, $m[0]));
5205 5205
     } else {
5206 5206
       return false;
@@ -5473,7 +5473,7 @@  discard block
 block discarded – undo
5473 5473
       $str = self::substr($str, $offset, $length);
5474 5474
     }
5475 5475
 
5476
-    return preg_match('/^' . self::rxClass($mask) . '+/u', $str, $str) ? self::strlen($str[0]) : 0;
5476
+    return preg_match('/^'.self::rxClass($mask).'+/u', $str, $str) ? self::strlen($str[0]) : 0;
5477 5477
   }
5478 5478
 
5479 5479
   /**
@@ -5910,7 +5910,7 @@  discard block
 block discarded – undo
5910 5910
 
5911 5911
     $strSwappedCase = preg_replace_callback(
5912 5912
         '/[\S]/u',
5913
-        function ($match) use ($encoding) {
5913
+        function($match) use ($encoding) {
5914 5914
           $marchToUpper = UTF8::strtoupper($match[0], $encoding);
5915 5915
 
5916 5916
           if ($match[0] === $marchToUpper) {
@@ -6119,40 +6119,40 @@  discard block
 block discarded – undo
6119 6119
         if ($c1 >= "\xc0" & $c1 <= "\xdf") { // looks like 2 bytes UTF8
6120 6120
 
6121 6121
           if ($c2 >= "\x80" && $c2 <= "\xbf") { // yeah, almost sure it's UTF8 already
6122
-            $buf .= $c1 . $c2;
6122
+            $buf .= $c1.$c2;
6123 6123
             $i++;
6124 6124
           } else { // not valid UTF8 - convert it
6125 6125
             $cc1 = (chr(ord($c1) / 64) | "\xc0");
6126 6126
             $cc2 = ($c1 & "\x3f") | "\x80";
6127
-            $buf .= $cc1 . $cc2;
6127
+            $buf .= $cc1.$cc2;
6128 6128
           }
6129 6129
 
6130 6130
         } elseif ($c1 >= "\xe0" & $c1 <= "\xef") { // looks like 3 bytes UTF8
6131 6131
 
6132 6132
           if ($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf") { // yeah, almost sure it's UTF8 already
6133
-            $buf .= $c1 . $c2 . $c3;
6133
+            $buf .= $c1.$c2.$c3;
6134 6134
             $i += 2;
6135 6135
           } else { // not valid UTF8 - convert it
6136 6136
             $cc1 = (chr(ord($c1) / 64) | "\xc0");
6137 6137
             $cc2 = ($c1 & "\x3f") | "\x80";
6138
-            $buf .= $cc1 . $cc2;
6138
+            $buf .= $cc1.$cc2;
6139 6139
           }
6140 6140
 
6141 6141
         } elseif ($c1 >= "\xf0" & $c1 <= "\xf7") { // looks like 4 bytes UTF8
6142 6142
 
6143 6143
           if ($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf" && $c4 >= "\x80" && $c4 <= "\xbf") { // yeah, almost sure it's UTF8 already
6144
-            $buf .= $c1 . $c2 . $c3 . $c4;
6144
+            $buf .= $c1.$c2.$c3.$c4;
6145 6145
             $i += 3;
6146 6146
           } else { // not valid UTF8 - convert it
6147 6147
             $cc1 = (chr(ord($c1) / 64) | "\xc0");
6148 6148
             $cc2 = ($c1 & "\x3f") | "\x80";
6149
-            $buf .= $cc1 . $cc2;
6149
+            $buf .= $cc1.$cc2;
6150 6150
           }
6151 6151
 
6152 6152
         } else { // doesn't look like UTF8, but should be converted
6153 6153
           $cc1 = (chr(ord($c1) / 64) | "\xc0");
6154 6154
           $cc2 = (($c1 & "\x3f") | "\x80");
6155
-          $buf .= $cc1 . $cc2;
6155
+          $buf .= $cc1.$cc2;
6156 6156
         }
6157 6157
 
6158 6158
       } elseif (($c1 & "\xc0") === "\x80") { // needs conversion
@@ -6163,7 +6163,7 @@  discard block
 block discarded – undo
6163 6163
         } else {
6164 6164
           $cc1 = (chr($ordC1 / 64) | "\xc0");
6165 6165
           $cc2 = (($c1 & "\x3f") | "\x80");
6166
-          $buf .= $cc1 . $cc2;
6166
+          $buf .= $cc1.$cc2;
6167 6167
         }
6168 6168
 
6169 6169
       } else { // it doesn't need conversion
@@ -6176,7 +6176,7 @@  discard block
 block discarded – undo
6176 6176
     // decode unicode escape sequences
6177 6177
     $buf = preg_replace_callback(
6178 6178
         '/\\\\u([0-9a-f]{4})/i',
6179
-        function ($match) {
6179
+        function($match) {
6180 6180
           return \mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
6181 6181
         },
6182 6182
         $buf
@@ -6185,7 +6185,7 @@  discard block
 block discarded – undo
6185 6185
     // decode UTF-8 codepoints
6186 6186
     $buf = preg_replace_callback(
6187 6187
         '/&#\d{2,4};/',
6188
-        function ($match) {
6188
+        function($match) {
6189 6189
           return \mb_convert_encoding($match[0], 'UTF-8', 'HTML-ENTITIES');
6190 6190
         },
6191 6191
         $buf
@@ -6260,7 +6260,7 @@  discard block
 block discarded – undo
6260 6260
    */
6261 6261
   public static function ucfirst($str)
6262 6262
   {
6263
-    return self::strtoupper(self::substr($str, 0, 1)) . self::substr($str, 1);
6263
+    return self::strtoupper(self::substr($str, 0, 1)).self::substr($str, 1);
6264 6264
   }
6265 6265
 
6266 6266
   /**
@@ -6709,7 +6709,7 @@  discard block
 block discarded – undo
6709 6709
       return '';
6710 6710
     }
6711 6711
 
6712
-    preg_match('/^\s*+(?:\S++\s*+){1,' . $words . '}/u', $str, $matches);
6712
+    preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $str, $matches);
6713 6713
 
6714 6714
     if (
6715 6715
         !isset($matches[0])
@@ -6719,7 +6719,7 @@  discard block
 block discarded – undo
6719 6719
       return $str;
6720 6720
     }
6721 6721
 
6722
-    return self::rtrim($matches[0]) . $strAddOn;
6722
+    return self::rtrim($matches[0]).$strAddOn;
6723 6723
   }
6724 6724
 
6725 6725
   /**
@@ -6801,7 +6801,7 @@  discard block
 block discarded – undo
6801 6801
       $strReturn .= $break;
6802 6802
     }
6803 6803
 
6804
-    return $strReturn . implode('', $chars);
6804
+    return $strReturn.implode('', $chars);
6805 6805
   }
6806 6806
 
6807 6807
   /**
Please login to merge, or discard this patch.