PluginProbe
WindPress – Tailwind CSS integration for WordPress / 3.2.90
WindPress – Tailwind CSS integration for WordPress v3.2.90
3.2.90 3.2.89 3.2.88 3.2.87 3.2.86 3.2.85 3.2.84 3.2.83 3.2.82 3.2.81 trunk 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.2 3.0.3 3.0.4 3.0.5 All 144 releases
← All changes | vendor/symfony/polyfill-mbstring/Mbstring.php +243 -126 3.0.33.2.90 View file →
@@ -48,8 +48,11 @@
48 48 * - mb_strwidth - Return width of string
49 49 * - mb_substr_count - Count the number of substring occurrences
50 50 * - mb_ucfirst - Make a string's first character uppercase
51 51 * - mb_lcfirst - Make a string's first character lowercase
52 + * - mb_trim - Strip whitespace (or other characters) from the beginning and end of a string
53 + * - mb_ltrim - Strip whitespace (or other characters) from the beginning of a string
54 + * - mb_rtrim - Strip whitespace (or other characters) from the end of a string
52 55 *
53 56 * Not implemented:
54 57 * - mb_convert_kana - Convert "kana" one from another ("zen-kaku", "han-kaku" and more)
55 58 * - mb_ereg_* - Regular expression with multibyte support
@@ -72,15 +75,12 @@
72 75 private const SIMPLE_CASE_FOLD = [['µ', 'ſ', "ͅ", 'ς', "ϐ", "ϑ", "ϕ", "ϖ", "ϰ", "ϱ", "ϵ", "ẛ", "ι"], ['μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "ṡ", 'ι']];
73 76 private static $encodingList = ['ASCII', 'UTF-8'];
74 77 private static $language = 'neutral';
75 78 private static $internalEncoding = 'UTF-8';
79 + private static $iconvSupportsIgnore;
76 80 public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null)
77 81 {
78 82 if (\is_array($s)) {
79 - if (\PHP_VERSION_ID < 70200) {
80 - \trigger_error('mb_convert_encoding() expects parameter 1 to be string, array given', \E_USER_WARNING);
81 - return null;
82 - }
83 83 $r = [];
84 84 foreach ($s as $str) {
85 85 $r[] = self::mb_convert_encoding($str, $toEncoding, $fromEncoding);
86 86 }
@@ -85,9 +85,9 @@
85 85 $r[] = self::mb_convert_encoding($str, $toEncoding, $fromEncoding);
86 86 }
87 87 return $r;
88 88 }
89 - if (\is_array($fromEncoding) || null !== $fromEncoding && \false !== \strpos($fromEncoding, ',')) {
89 + if (\is_array($fromEncoding) || null !== $fromEncoding && \false !== strpos($fromEncoding, ',')) {
90 90 $fromEncoding = self::mb_detect_encoding($s, $fromEncoding);
91 91 } else {
92 92 $fromEncoding = self::getEncoding($fromEncoding);
93 93 }
@@ -92,13 +92,13 @@
92 92 $fromEncoding = self::getEncoding($fromEncoding);
93 93 }
94 94 $toEncoding = self::getEncoding($toEncoding);
95 95 if ('BASE64' === $fromEncoding) {
96 - $s = \base64_decode($s);
96 + $s = base64_decode($s);
97 97 $fromEncoding = $toEncoding;
98 98 }
99 99 if ('BASE64' === $toEncoding) {
100 - return \base64_encode($s);
100 + return base64_encode($s);
101 101 }
102 102 if ('HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding) {
103 103 if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) {
104 104 $fromEncoding = 'Windows-1252';
@@ -103,23 +103,49 @@
103 103 if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) {
104 104 $fromEncoding = 'Windows-1252';
105 105 }
106 106 if ('UTF-8' !== $fromEncoding) {
107 - $s = \iconv($fromEncoding, 'UTF-8//IGNORE', $s);
107 + $s = self::iconv($fromEncoding, 'UTF-8', $s);
108 108 }
109 - return \preg_replace_callback('/[\\x80-\\xFF]+/', [__CLASS__, 'html_encoding_callback'], $s);
109 + return preg_replace_callback('/[\x80-\xFF]+/', [__CLASS__, 'html_encoding_callback'], $s);
110 110 }
111 111 if ('HTML-ENTITIES' === $fromEncoding) {
112 - $s = \html_entity_decode($s, \ENT_COMPAT, 'UTF-8');
112 + $decodeControlChars = static function ($m) {
113 + $code = '' !== ($m[2] ?? '') ? hexdec($m[2]) : (int) $m[1];
114 + if ($code < 32 || 127 === $code) {
115 + return \chr($code);
116 + }
117 + if (128 <= $code && $code <= 159) {
118 + return "\xc2" . \chr(0x80 | $code & 0x3f);
119 + }
120 + return $m[0];
121 + };
122 + if (\PHP_VERSION_ID >= 70400) {
123 + $s = html_entity_decode($s, \ENT_QUOTES, 'UTF-8');
124 + // html_entity_decode() leaves numeric entities for C0/C1 control
125 + // characters as-is (HTML spec), but mb_convert_encoding() decodes
126 + // them. Catch what html_entity_decode() missed.
127 + if (\false !== strpos($s, '&#')) {
128 + $s = preg_replace_callback('/&#(?:0*([0-9]++)|[xX]0*([0-9a-fA-F]++));/', $decodeControlChars, $s);
129 + }
130 + } else {
131 + // PHP < 7.4: html_entity_decode() truncates strings at NUL bytes,
132 + // so decode the control character entities first then call
133 + // html_entity_decode() on each NUL-delimited chunk independently.
134 + $s = preg_replace_callback('/&#(?:0*([0-9]++)|[xX]0*([0-9a-fA-F]++));/', $decodeControlChars, $s);
135 + $s = implode("\x00", array_map(static function ($chunk) {
136 + return html_entity_decode($chunk, \ENT_QUOTES, 'UTF-8');
137 + }, explode("\x00", $s)));
138 + }
113 139 $fromEncoding = 'UTF-8';
114 140 }
115 - return \iconv($fromEncoding, $toEncoding . '//IGNORE', $s);
141 + return self::iconv($fromEncoding, $toEncoding, $s);
116 142 }
117 143 public static function mb_convert_variables($toEncoding, $fromEncoding, &...$vars)
118 144 {
119 145 $ok = \true;
120 - \array_walk_recursive($vars, function (&$v) use(&$ok, $toEncoding, $fromEncoding) {
121 - if (\false === ($v = self::mb_convert_encoding($v, $toEncoding, $fromEncoding))) {
146 + array_walk_recursive($vars, static function (&$v) use (&$ok, $toEncoding, $fromEncoding) {
147 + if (\false === $v = self::mb_convert_encoding($v, $toEncoding, $fromEncoding)) {
122 148 $ok = \false;
123 149 }
124 150 });
125 151 return $ok ? $fromEncoding : \false;
@@ -125,18 +151,18 @@
125 151 return $ok ? $fromEncoding : \false;
126 152 }
127 153 public static function mb_decode_mimeheader($s)
128 154 {
129 - return \iconv_mime_decode($s, 2, self::$internalEncoding);
155 + return iconv_mime_decode($s, 2, self::$internalEncoding);
130 156 }
131 157 public static function mb_encode_mimeheader($s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null)
132 158 {
133 - \trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', \E_USER_WARNING);
159 + trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', \E_USER_WARNING);
134 160 }
135 161 public static function mb_decode_numericentity($s, $convmap, $encoding = null)
136 162 {
137 - if (null !== $s && !\is_scalar($s) && !(\is_object($s) && \method_exists($s, '__toString'))) {
138 - \trigger_error('mb_decode_numericentity() expects parameter 1 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
163 + if (null !== $s && !\is_scalar($s) && !(\is_object($s) && method_exists($s, '__toString'))) {
164 + trigger_error('mb_decode_numericentity() expects parameter 1 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
139 165 return null;
140 166 }
141 167 if (!\is_array($convmap) || 80000 > \PHP_VERSION_ID && !$convmap) {
142 168 return \false;
@@ -141,9 +167,9 @@
141 167 if (!\is_array($convmap) || 80000 > \PHP_VERSION_ID && !$convmap) {
142 168 return \false;
143 169 }
144 170 if (null !== $encoding && !\is_scalar($encoding)) {
145 - \trigger_error('mb_decode_numericentity() expects parameter 3 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
171 + trigger_error('mb_decode_numericentity() expects parameter 3 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
146 172 return '';
147 173 // Instead of null (cf. mb_encode_numericentity).
148 174 }
149 175 $s = (string) $s;
@@ -152,22 +178,22 @@
152 178 }
153 179 $encoding = self::getEncoding($encoding);
154 180 if ('UTF-8' === $encoding) {
155 181 $encoding = null;
156 - if (!\preg_match('//u', $s)) {
157 - $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s);
182 + if (!preg_match('//u', $s)) {
183 + $s = @self::iconv('UTF-8', 'UTF-8', $s);
158 184 }
159 185 } else {
160 - $s = \iconv($encoding, 'UTF-8//IGNORE', $s);
186 + $s = self::iconv($encoding, 'UTF-8', $s);
161 187 }
162 - $cnt = \floor(\count($convmap) / 4) * 4;
188 + $cnt = floor(\count($convmap) / 4) * 4;
163 189 for ($i = 0; $i < $cnt; $i += 4) {
164 190 // collector_decode_htmlnumericentity ignores $convmap[$i + 3]
165 191 $convmap[$i] += $convmap[$i + 2];
166 192 $convmap[$i + 1] += $convmap[$i + 2];
167 193 }
168 - $s = \preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function (array $m) use($cnt, $convmap) {
169 - $c = isset($m[2]) ? (int) \hexdec($m[2]) : $m[1];
194 + $s = preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))' . (\PHP_VERSION_ID >= 80200 ? '' : '(?!&)') . ';?/', static function (array $m) use ($cnt, $convmap) {
195 + $c = isset($m[2]) ? (int) hexdec($m[2]) : $m[1];
170 196 for ($i = 0; $i < $cnt; $i += 4) {
171 197 if ($c >= $convmap[$i] && $c <= $convmap[$i + 1]) {
172 198 return self::mb_chr($c - $convmap[$i + 2]);
173 199 }
@@ -176,14 +202,14 @@
176 202 }, $s);
177 203 if (null === $encoding) {
178 204 return $s;
179 205 }
180 - return \iconv('UTF-8', $encoding . '//IGNORE', $s);
206 + return self::iconv('UTF-8', $encoding, $s);
181 207 }
182 208 public static function mb_encode_numericentity($s, $convmap, $encoding = null, $is_hex = \false)
183 209 {
184 - if (null !== $s && !\is_scalar($s) && !(\is_object($s) && \method_exists($s, '__toString'))) {
185 - \trigger_error('mb_encode_numericentity() expects parameter 1 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
210 + if (null !== $s && !\is_scalar($s) && !(\is_object($s) && method_exists($s, '__toString'))) {
211 + trigger_error('mb_encode_numericentity() expects parameter 1 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
186 212 return null;
187 213 }
188 214 if (!\is_array($convmap) || 80000 > \PHP_VERSION_ID && !$convmap) {
189 215 return \false;
@@ -188,14 +214,14 @@
188 214 if (!\is_array($convmap) || 80000 > \PHP_VERSION_ID && !$convmap) {
189 215 return \false;
190 216 }
191 217 if (null !== $encoding && !\is_scalar($encoding)) {
192 - \trigger_error('mb_encode_numericentity() expects parameter 3 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
218 + trigger_error('mb_encode_numericentity() expects parameter 3 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
193 219 return null;
194 220 // Instead of '' (cf. mb_decode_numericentity).
195 221 }
196 222 if (null !== $is_hex && !\is_scalar($is_hex)) {
197 - \trigger_error('mb_encode_numericentity() expects parameter 4 to be boolean, ' . \gettype($s) . ' given', \E_USER_WARNING);
223 + trigger_error('mb_encode_numericentity() expects parameter 4 to be boolean, ' . \gettype($s) . ' given', \E_USER_WARNING);
198 224 return null;
199 225 }
200 226 $s = (string) $s;
201 227 if ('' === $s) {
@@ -203,22 +229,22 @@
203 229 }
204 230 $encoding = self::getEncoding($encoding);
205 231 if ('UTF-8' === $encoding) {
206 232 $encoding = null;
207 - if (!\preg_match('//u', $s)) {
208 - $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s);
233 + if (!preg_match('//u', $s)) {
234 + $s = @self::iconv('UTF-8', 'UTF-8', $s);
209 235 }
210 236 } else {
211 - $s = \iconv($encoding, 'UTF-8//IGNORE', $s);
237 + $s = self::iconv($encoding, 'UTF-8', $s);
212 238 }
213 239 static $ulenMask = ["\xc0" => 2, "\xd0" => 2, "\xe0" => 3, "\xf0" => 4];
214 - $cnt = \floor(\count($convmap) / 4) * 4;
240 + $cnt = floor(\count($convmap) / 4) * 4;
215 241 $i = 0;
216 242 $len = \strlen($s);
217 243 $result = '';
218 244 while ($i < $len) {
219 245 $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xf0"];
220 - $uchr = \substr($s, $i, $ulen);
246 + $uchr = substr($s, $i, $ulen);
221 247 $i += $ulen;
222 248 $c = self::mb_ord($uchr);
223 249 for ($j = 0; $j < $cnt; $j += 4) {
224 250 if ($c >= $convmap[$j] && $c <= $convmap[$j + 1]) {
@@ -231,9 +257,9 @@
231 257 }
232 258 if (null === $encoding) {
233 259 return $result;
234 260 }
235 - return \iconv('UTF-8', $encoding . '//IGNORE', $result);
261 + return self::iconv('UTF-8', $encoding, $result);
236 262 }
237 263 public static function mb_convert_case($s, $mode, $encoding = null)
238 264 {
239 265 $s = (string) $s;
@@ -242,13 +268,13 @@
242 268 }
243 269 $encoding = self::getEncoding($encoding);
244 270 if ('UTF-8' === $encoding) {
245 271 $encoding = null;
246 - if (!\preg_match('//u', $s)) {
247 - $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s);
272 + if (!preg_match('//u', $s)) {
273 + $s = @self::iconv('UTF-8', 'UTF-8', $s);
248 274 }
249 275 } else {
250 - $s = \iconv($encoding, 'UTF-8//IGNORE', $s);
276 + $s = self::iconv($encoding, 'UTF-8', $s);
251 277 }
252 278 if (\MB_CASE_TITLE == $mode) {
253 279 static $titleRegexp = null;
254 280 if (null === $titleRegexp) {
@@ -253,9 +279,9 @@
253 279 static $titleRegexp = null;
254 280 if (null === $titleRegexp) {
255 281 $titleRegexp = self::getData('titleCaseRegexp');
256 282 }
257 - $s = \preg_replace_callback($titleRegexp, [__CLASS__, 'title_case'], $s);
283 + $s = preg_replace_callback($titleRegexp, [__CLASS__, 'title_case'], $s);
258 284 } else {
259 285 if (\MB_CASE_UPPER == $mode) {
260 286 static $upper = null;
261 287 if (null === $upper) {
@@ -267,9 +293,9 @@
267 293 static $caseFolding = null;
268 294 if (null === $caseFolding) {
269 295 $caseFolding = self::getData('caseFolding');
270 296 }
271 - $s = \strtr($s, $caseFolding);
297 + $s = strtr($s, $caseFolding);
272 298 }
273 299 static $lower = null;
274 300 if (null === $lower) {
275 301 $lower = self::getData('lowerCase');
@@ -280,9 +306,9 @@
280 306 $i = 0;
281 307 $len = \strlen($s);
282 308 while ($i < $len) {
283 309 $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xf0"];
284 - $uchr = \substr($s, $i, $ulen);
310 + $uchr = substr($s, $i, $ulen);
285 311 $i += $ulen;
286 312 if (isset($map[$uchr])) {
287 313 $uchr = $map[$uchr];
288 314 $nlen = \strlen($uchr);
@@ -291,9 +317,9 @@
291 317 do {
292 318 $s[--$nlen] = $uchr[--$ulen];
293 319 } while ($ulen);
294 320 } else {
295 - $s = \substr_replace($s, $uchr, $i - $ulen, $ulen);
321 + $s = substr_replace($s, $uchr, $i - $ulen, $ulen);
296 322 $len += $nlen - $ulen;
297 323 $i += $nlen - $ulen;
298 324 }
299 325 }
@@ -301,9 +327,9 @@
301 327 }
302 328 if (null === $encoding) {
303 329 return $s;
304 330 }
305 - return \iconv('UTF-8', $encoding . '//IGNORE', $s);
331 + return self::iconv('UTF-8', $encoding, $s);
306 332 }
307 333 public static function mb_internal_encoding($encoding = null)
308 334 {
309 335 if (null === $encoding) {
@@ -309,9 +335,9 @@
309 335 if (null === $encoding) {
310 336 return self::$internalEncoding;
311 337 }
312 338 $normalizedEncoding = self::getEncoding($encoding);
313 - if ('UTF-8' === $normalizedEncoding || \false !== @\iconv($normalizedEncoding, $normalizedEncoding, ' ')) {
339 + if ('UTF-8' === $normalizedEncoding || \false !== @iconv($normalizedEncoding, $normalizedEncoding, ' ')) {
314 340 self::$internalEncoding = $normalizedEncoding;
315 341 return \true;
316 342 }
317 343 if (80000 > \PHP_VERSION_ID) {
@@ -323,9 +349,9 @@
323 349 {
324 350 if (null === $lang) {
325 351 return self::$language;
326 352 }
327 - switch ($normalizedLang = \strtolower($lang)) {
353 + switch ($normalizedLang = strtolower($lang)) {
328 354 case 'uni':
329 355 case 'neutral':
330 356 self::$language = $normalizedLang;
331 357 return \true;
@@ -340,9 +366,9 @@
340 366 return ['UTF-8'];
341 367 }
342 368 public static function mb_encoding_aliases($encoding)
343 369 {
344 - switch (\strtoupper($encoding)) {
370 + switch (strtoupper($encoding)) {
345 371 case 'UTF8':
346 372 case 'UTF-8':
347 373 return ['utf8'];
348 374 }
@@ -349,12 +375,8 @@
349 375 return \false;
350 376 }
351 377 public static function mb_check_encoding($var = null, $encoding = null)
352 378 {
353 - if (\PHP_VERSION_ID < 70200 && \is_array($var)) {
354 - \trigger_error('mb_check_encoding() expects parameter 1 to be string, array given', \E_USER_WARNING);
355 - return null;
356 - }
357 379 if (null === $encoding) {
358 380 if (null === $var) {
359 381 return \false;
360 382 }
@@ -360,9 +382,9 @@
360 382 }
361 383 $encoding = self::$internalEncoding;
362 384 }
363 385 if (!\is_array($var)) {
364 - return self::mb_detect_encoding($var, [$encoding]) || \false !== @\iconv($encoding, $encoding, $var);
386 + return self::mb_detect_encoding($var, [$encoding]) || \false !== @iconv($encoding, $encoding, $var);
365 387 }
366 388 foreach ($var as $key => $value) {
367 389 if (!self::mb_check_encoding($key, $encoding)) {
368 390 return \false;
@@ -378,27 +400,27 @@
378 400 if (null === $encodingList) {
379 401 $encodingList = self::$encodingList;
380 402 } else {
381 403 if (!\is_array($encodingList)) {
382 - $encodingList = \array_map('trim', \explode(',', $encodingList));
404 + $encodingList = array_map('trim', explode(',', $encodingList));
383 405 }
384 - $encodingList = \array_map('strtoupper', $encodingList);
406 + $encodingList = array_map('strtoupper', $encodingList);
385 407 }
386 408 foreach ($encodingList as $enc) {
387 409 switch ($enc) {
388 410 case 'ASCII':
389 - if (!\preg_match('/[\\x80-\\xFF]/', $str)) {
411 + if (!preg_match('/[\x80-\xFF]/', $str)) {
390 412 return $enc;
391 413 }
392 414 break;
393 415 case 'UTF8':
394 416 case 'UTF-8':
395 - if (\preg_match('//u', $str)) {
417 + if (preg_match('//u', $str)) {
396 418 return 'UTF-8';
397 419 }
398 420 break;
399 421 default:
400 - if (0 === \strncmp($enc, 'ISO-8859-', 9)) {
422 + if (0 === strncmp($enc, 'ISO-8859-', 9)) {
401 423 return $enc;
402 424 }
403 425 }
404 426 }
@@ -409,15 +431,15 @@
409 431 if (null === $encodingList) {
410 432 return self::$encodingList;
411 433 }
412 434 if (!\is_array($encodingList)) {
413 - $encodingList = \array_map('trim', \explode(',', $encodingList));
435 + $encodingList = array_map('trim', explode(',', $encodingList));
414 436 }
415 - $encodingList = \array_map('strtoupper', $encodingList);
437 + $encodingList = array_map('strtoupper', $encodingList);
416 438 foreach ($encodingList as $enc) {
417 439 switch ($enc) {
418 440 default:
419 - if (\strncmp($enc, 'ISO-8859-', 9)) {
441 + if (strncmp($enc, 'ISO-8859-', 9)) {
420 442 return \false;
421 443 }
422 444 // no break
423 445 case 'ASCII':
@@ -433,37 +455,43 @@
433 455 $encoding = self::getEncoding($encoding);
434 456 if ('CP850' === $encoding || 'ASCII' === $encoding) {
435 457 return \strlen($s);
436 458 }
437 - return @\iconv_strlen($s, $encoding);
459 + if (\false !== $len = @iconv_strlen($s, $encoding)) {
460 + return $len;
461 + }
462 + if ('UTF-8' !== $encoding) {
463 + return $len;
464 + }
465 + return preg_match_all('/[\x00-\x7F]|[\xC0-\xDF][\x80-\xBF]?|[\xE0-\xEF][\x80-\xBF]{0,2}|[\xF0-\xF7][\x80-\xBF]{0,3}|[\xF8-\xFB][\x80-\xBF]{0,4}|[\xFC-\xFD][\x80-\xBF]{0,5}|[\x80-\xBF\xFE\xFF]/s', $s);
438 466 }
439 467 public static function mb_strpos($haystack, $needle, $offset = 0, $encoding = null)
440 468 {
441 469 $encoding = self::getEncoding($encoding);
442 470 if ('CP850' === $encoding || 'ASCII' === $encoding) {
443 - return \strpos($haystack, $needle, $offset);
471 + return strpos($haystack, $needle, $offset);
444 472 }
445 473 $needle = (string) $needle;
446 474 if ('' === $needle) {
447 475 if (80000 > \PHP_VERSION_ID) {
448 - \trigger_error(__METHOD__ . ': Empty delimiter', \E_USER_WARNING);
476 + trigger_error(__METHOD__ . ': Empty delimiter', \E_USER_WARNING);
449 477 return \false;
450 478 }
451 479 return 0;
452 480 }
453 - return \iconv_strpos($haystack, $needle, $offset, $encoding);
481 + return iconv_strpos($haystack, $needle, $offset, $encoding);
454 482 }
455 483 public static function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null)
456 484 {
457 485 $encoding = self::getEncoding($encoding);
458 486 if ('CP850' === $encoding || 'ASCII' === $encoding) {
459 - return \strrpos($haystack, $needle, $offset);
487 + return strrpos($haystack, $needle, $offset);
460 488 }
461 489 if ($offset != (int) $offset) {
462 490 $offset = 0;
463 491 } elseif ($offset = (int) $offset) {
464 492 if ($offset < 0) {
465 - if (0 > ($offset += self::mb_strlen($needle))) {
493 + if (0 > $offset += self::mb_strlen($needle)) {
466 494 $haystack = self::mb_substr($haystack, 0, $offset, $encoding);
467 495 }
468 496 $offset = 0;
469 497 } else {
@@ -469,28 +497,28 @@
469 497 } else {
470 498 $haystack = self::mb_substr($haystack, $offset, 2147483647, $encoding);
471 499 }
472 500 }
473 - $pos = '' !== $needle || 80000 > \PHP_VERSION_ID ? \iconv_strrpos($haystack, $needle, $encoding) : self::mb_strlen($haystack, $encoding);
501 + $pos = '' !== $needle || 80000 > \PHP_VERSION_ID ? iconv_strrpos($haystack, $needle, $encoding) : self::mb_strlen($haystack, $encoding);
474 502 return \false !== $pos ? $offset + $pos : \false;
475 503 }
476 504 public static function mb_str_split($string, $split_length = 1, $encoding = null)
477 505 {
478 - if (null !== $string && !\is_scalar($string) && !(\is_object($string) && \method_exists($string, '__toString'))) {
479 - \trigger_error('mb_str_split() expects parameter 1 to be string, ' . \gettype($string) . ' given', \E_USER_WARNING);
506 + if (null !== $string && !\is_scalar($string) && !(\is_object($string) && method_exists($string, '__toString'))) {
507 + trigger_error('mb_str_split() expects parameter 1 to be string, ' . \gettype($string) . ' given', \E_USER_WARNING);
480 508 return null;
481 509 }
482 - if (1 > ($split_length = (int) $split_length)) {
510 + if (1 > $split_length = (int) $split_length) {
483 511 if (80000 > \PHP_VERSION_ID) {
484 - \trigger_error('The length of each segment must be greater than zero', \E_USER_WARNING);
512 + trigger_error('The length of each segment must be greater than zero', \E_USER_WARNING);
485 513 return \false;
486 514 }
487 515 throw new \ValueError('Argument #2 ($length) must be greater than 0');
488 516 }
489 517 if (null === $encoding) {
490 - $encoding = \mb_internal_encoding();
518 + $encoding = mb_internal_encoding();
491 519 }
492 - if ('UTF-8' === ($encoding = self::getEncoding($encoding))) {
520 + if ('UTF-8' === $encoding = self::getEncoding($encoding)) {
493 521 $rx = '/(';
494 522 while (65535 < $split_length) {
495 523 $rx .= '.{65535}';
496 524 $split_length -= 65535;
@@ -495,14 +523,14 @@
495 523 $rx .= '.{65535}';
496 524 $split_length -= 65535;
497 525 }
498 526 $rx .= '.{' . $split_length . '})/us';
499 - return \preg_split($rx, $string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY);
527 + return preg_split($rx, $string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY);
500 528 }
501 529 $result = [];
502 - $length = \mb_strlen($string, $encoding);
530 + $length = mb_strlen($string, $encoding);
503 531 for ($i = 0; $i < $length; $i += $split_length) {
504 - $result[] = \mb_substr($string, $i, $split_length, $encoding);
532 + $result[] = mb_substr($string, $i, $split_length, $encoding);
505 533 }
506 534 return $result;
507 535 }
508 536 public static function mb_strtolower($s, $encoding = null)
@@ -517,9 +545,9 @@
517 545 {
518 546 if (null === $c) {
519 547 return 'none';
520 548 }
521 - if (0 === \strcasecmp($c, 'none')) {
549 + if (0 === strcasecmp($c, 'none')) {
522 550 return \true;
523 551 }
524 552 if (80000 > \PHP_VERSION_ID) {
525 553 return \false;
@@ -532,12 +560,12 @@
532 560 public static function mb_substr($s, $start, $length = null, $encoding = null)
533 561 {
534 562 $encoding = self::getEncoding($encoding);
535 563 if ('CP850' === $encoding || 'ASCII' === $encoding) {
536 - return (string) \substr($s, $start, null === $length ? 2147483647 : $length);
564 + return (string) substr($s, $start, null === $length ? 2147483647 : $length);
537 565 }
538 566 if ($start < 0) {
539 - $start = \iconv_strlen($s, $encoding) + $start;
567 + $start = iconv_strlen($s, $encoding) + $start;
540 568 if ($start < 0) {
541 569 $start = 0;
542 570 }
543 571 }
@@ -543,18 +571,18 @@
543 571 }
544 572 if (null === $length) {
545 573 $length = 2147483647;
546 574 } elseif ($length < 0) {
547 - $length = \iconv_strlen($s, $encoding) + $length - $start;
575 + $length = iconv_strlen($s, $encoding) + $length - $start;
548 576 if ($length < 0) {
549 577 return '';
550 578 }
551 579 }
552 - return (string) \iconv_substr($s, $start, $length, $encoding);
580 + return (string) iconv_substr($s, $start, $length, $encoding);
553 581 }
554 582 public static function mb_stripos($haystack, $needle, $offset = 0, $encoding = null)
555 583 {
556 - [$haystack, $needle] = \str_replace(self::SIMPLE_CASE_FOLD[0], self::SIMPLE_CASE_FOLD[1], [self::mb_convert_case($haystack, \MB_CASE_LOWER, $encoding), self::mb_convert_case($needle, \MB_CASE_LOWER, $encoding)]);
584 + [$haystack, $needle] = str_replace(self::SIMPLE_CASE_FOLD[0], self::SIMPLE_CASE_FOLD[1], [self::mb_convert_case($haystack, \MB_CASE_LOWER, $encoding), self::mb_convert_case($needle, \MB_CASE_LOWER, $encoding)]);
557 585 return self::mb_strpos($haystack, $needle, $offset, $encoding);
558 586 }
559 587 public static function mb_stristr($haystack, $needle, $part = \false, $encoding = null)
560 588 {
@@ -564,12 +592,12 @@
564 592 public static function mb_strrchr($haystack, $needle, $part = \false, $encoding = null)
565 593 {
566 594 $encoding = self::getEncoding($encoding);
567 595 if ('CP850' === $encoding || 'ASCII' === $encoding) {
568 - $pos = \strrpos($haystack, $needle);
596 + $pos = strrpos($haystack, $needle);
569 597 } else {
570 598 $needle = self::mb_substr($needle, 0, 1, $encoding);
571 - $pos = \iconv_strrpos($haystack, $needle, $encoding);
599 + $pos = iconv_strrpos($haystack, $needle, $encoding);
572 600 }
573 601 return self::getSubpart($pos, $part, $haystack, $encoding);
574 602 }
575 603 public static function mb_strrichr($haystack, $needle, $part = \false, $encoding = null)
@@ -581,26 +609,26 @@
581 609 public static function mb_strripos($haystack, $needle, $offset = 0, $encoding = null)
582 610 {
583 611 $haystack = self::mb_convert_case($haystack, \MB_CASE_LOWER, $encoding);
584 612 $needle = self::mb_convert_case($needle, \MB_CASE_LOWER, $encoding);
585 - $haystack = \str_replace(self::SIMPLE_CASE_FOLD[0], self::SIMPLE_CASE_FOLD[1], $haystack);
586 - $needle = \str_replace(self::SIMPLE_CASE_FOLD[0], self::SIMPLE_CASE_FOLD[1], $needle);
613 + $haystack = str_replace(self::SIMPLE_CASE_FOLD[0], self::SIMPLE_CASE_FOLD[1], $haystack);
614 + $needle = str_replace(self::SIMPLE_CASE_FOLD[0], self::SIMPLE_CASE_FOLD[1], $needle);
587 615 return self::mb_strrpos($haystack, $needle, $offset, $encoding);
588 616 }
589 617 public static function mb_strstr($haystack, $needle, $part = \false, $encoding = null)
590 618 {
591 - $pos = \strpos($haystack, $needle);
619 + $pos = strpos($haystack, $needle);
592 620 if (\false === $pos) {
593 621 return \false;
594 622 }
595 623 if ($part) {
596 - return \substr($haystack, 0, $pos);
624 + return substr($haystack, 0, $pos);
597 625 }
598 - return \substr($haystack, $pos);
626 + return substr($haystack, $pos);
599 627 }
600 628 public static function mb_get_info($type = 'all')
601 629 {
602 - $info = ['internal_encoding' => self::$internalEncoding, 'http_output' => 'pass', 'http_output_conv_mimetypes' => '^(text/|application/xhtml\\+xml)', 'func_overload' => 0, 'func_overload_list' => 'no overload', 'mail_charset' => 'UTF-8', 'mail_header_encoding' => 'BASE64', 'mail_body_encoding' => 'BASE64', 'illegal_chars' => 0, 'encoding_translation' => 'Off', 'language' => self::$language, 'detect_order' => self::$encodingList, 'substitute_character' => 'none', 'strict_detection' => 'Off'];
630 + $info = ['internal_encoding' => self::$internalEncoding, 'http_output' => 'pass', 'http_output_conv_mimetypes' => '^(text/|application/xhtml\+xml)', 'func_overload' => 0, 'func_overload_list' => 'no overload', 'mail_charset' => 'UTF-8', 'mail_header_encoding' => 'BASE64', 'mail_body_encoding' => 'BASE64', 'illegal_chars' => 0, 'encoding_translation' => 'Off', 'language' => self::$language, 'detect_order' => self::$encodingList, 'substitute_character' => 'none', 'strict_detection' => 'Off'];
603 631 if ('all' === $type) {
604 632 return $info;
605 633 }
606 634 if (isset($info[$type])) {
@@ -619,16 +647,16 @@
619 647 public static function mb_strwidth($s, $encoding = null)
620 648 {
621 649 $encoding = self::getEncoding($encoding);
622 650 if ('UTF-8' !== $encoding) {
623 - $s = \iconv($encoding, 'UTF-8//IGNORE', $s);
651 + $s = self::iconv($encoding, 'UTF-8', $s);
624 652 }
625 - $s = \preg_replace('/[\\x{1100}-\\x{115F}\\x{2329}\\x{232A}\\x{2E80}-\\x{303E}\\x{3040}-\\x{A4CF}\\x{AC00}-\\x{D7A3}\\x{F900}-\\x{FAFF}\\x{FE10}-\\x{FE19}\\x{FE30}-\\x{FE6F}\\x{FF00}-\\x{FF60}\\x{FFE0}-\\x{FFE6}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}]/u', '', $s, -1, $wide);
626 - return ($wide << 1) + \iconv_strlen($s, 'UTF-8');
653 + $s = preg_replace('/[\x{1100}-\x{115F}\x{2329}\x{232A}\x{2E80}-\x{303E}\x{3040}-\x{A4CF}\x{AC00}-\x{D7A3}\x{F900}-\x{FAFF}\x{FE10}-\x{FE19}\x{FE30}-\x{FE6F}\x{FF00}-\x{FF60}\x{FFE0}-\x{FFE6}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}]/u', '', $s, -1, $wide);
654 + return ($wide << 1) + iconv_strlen($s, 'UTF-8');
627 655 }
628 656 public static function mb_substr_count($haystack, $needle, $encoding = null)
629 657 {
630 - return \substr_count($haystack, $needle);
658 + return substr_count($haystack, $needle);
631 659 }
632 660 public static function mb_output_handler($contents, $status)
633 661 {
634 662 return $contents;
@@ -634,9 +662,9 @@
634 662 return $contents;
635 663 }
636 664 public static function mb_chr($code, $encoding = null)
637 665 {
638 - if (0x80 > ($code %= 0x200000)) {
666 + if (0x80 > $code %= 0x200000) {
639 667 $s = \chr($code);
640 668 } elseif (0x800 > $code) {
641 669 $s = \chr(0xc0 | $code >> 6) . \chr(0x80 | $code & 0x3f);
642 670 } elseif (0x10000 > $code) {
@@ -643,22 +671,22 @@
643 671 $s = \chr(0xe0 | $code >> 12) . \chr(0x80 | $code >> 6 & 0x3f) . \chr(0x80 | $code & 0x3f);
644 672 } else {
645 673 $s = \chr(0xf0 | $code >> 18) . \chr(0x80 | $code >> 12 & 0x3f) . \chr(0x80 | $code >> 6 & 0x3f) . \chr(0x80 | $code & 0x3f);
646 674 }
647 - if ('UTF-8' !== ($encoding = self::getEncoding($encoding))) {
648 - $s = \mb_convert_encoding($s, $encoding, 'UTF-8');
675 + if ('UTF-8' !== $encoding = self::getEncoding($encoding)) {
676 + $s = mb_convert_encoding($s, $encoding, 'UTF-8');
649 677 }
650 678 return $s;
651 679 }
652 680 public static function mb_ord($s, $encoding = null)
653 681 {
654 - if ('UTF-8' !== ($encoding = self::getEncoding($encoding))) {
655 - $s = \mb_convert_encoding($s, 'UTF-8', $encoding);
682 + if ('UTF-8' !== $encoding = self::getEncoding($encoding)) {
683 + $s = mb_convert_encoding($s, 'UTF-8', $encoding);
656 684 }
657 685 if (1 === \strlen($s)) {
658 686 return \ord($s);
659 687 }
660 - $code = ($s = \unpack('C*', \substr($s, 0, 4))) ? $s[1] : 0;
688 + $code = ($s = unpack('C*', substr($s, 0, 4))) ? $s[1] : 0;
661 689 if (0xf0 <= $code) {
662 690 return ($code - 0xf0 << 18) + ($s[2] - 0x80 << 12) + ($s[3] - 0x80 << 6) + $s[4] - 0x80;
663 691 }
664 692 if (0xe0 <= $code) {
@@ -668,21 +696,40 @@
668 696 return ($code - 0xc0 << 6) + $s[2] - 0x80;
669 697 }
670 698 return $code;
671 699 }
672 - public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, ?string $encoding = null) : string
700 + /** @return string|false */
701 + public static function mb_scrub(?string $string, ?string $encoding = null): string
673 702 {
674 - if (!\in_array($pad_type, [\STR_PAD_RIGHT, \STR_PAD_LEFT, \STR_PAD_BOTH], \true)) {
675 - throw new \ValueError('mb_str_pad(): Argument #4 ($pad_type) must be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH');
703 + if (null === $encoding) {
704 + $encoding = self::mb_internal_encoding();
705 + } elseif (!self::assertEncoding($encoding, 'mb_scrub(): Argument #2 ($encoding) must be a valid encoding, "%s" given')) {
706 + return \false;
676 707 }
708 + return self::mb_convert_encoding((string) $string, $encoding, $encoding);
709 + }
710 + /** @return string|false */
711 + public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, ?string $encoding = null)
712 + {
677 713 if (null === $encoding) {
678 714 $encoding = self::mb_internal_encoding();
679 - } else {
680 - self::assertEncoding($encoding, 'mb_str_pad(): Argument #5 ($encoding) must be a valid encoding, "%s" given');
715 + } elseif (!self::assertEncoding($encoding, 'mb_str_pad(): Argument #5 ($encoding) must be a valid encoding, "%s" given')) {
716 + return \false;
681 717 }
682 718 if (self::mb_strlen($pad_string, $encoding) <= 0) {
719 + if (\PHP_VERSION_ID < 80000) {
720 + trigger_error('mb_str_pad(): Argument #3 ($pad_string) must be a non-empty string', \E_USER_WARNING);
721 + return \false;
722 + }
683 723 throw new \ValueError('mb_str_pad(): Argument #3 ($pad_string) must be a non-empty string');
684 724 }
725 + if (!\in_array($pad_type, [\STR_PAD_RIGHT, \STR_PAD_LEFT, \STR_PAD_BOTH], \true)) {
726 + if (\PHP_VERSION_ID < 80000) {
727 + trigger_error('mb_str_pad(): Argument #4 ($pad_type) must be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH', \E_USER_WARNING);
728 + return \false;
729 + }
730 + throw new \ValueError('mb_str_pad(): Argument #4 ($pad_type) must be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH');
731 + }
685 732 $paddingRequired = $length - self::mb_strlen($string, $encoding);
686 733 if ($paddingRequired < 1) {
687 734 return $string;
688 735 }
@@ -687,39 +734,56 @@
687 734 return $string;
688 735 }
689 736 switch ($pad_type) {
690 737 case \STR_PAD_LEFT:
691 - return self::mb_substr(\str_repeat($pad_string, $paddingRequired), 0, $paddingRequired, $encoding) . $string;
738 + return self::mb_substr(str_repeat($pad_string, $paddingRequired), 0, $paddingRequired, $encoding) . $string;
692 739 case \STR_PAD_RIGHT:
693 - return $string . self::mb_substr(\str_repeat($pad_string, $paddingRequired), 0, $paddingRequired, $encoding);
740 + return $string . self::mb_substr(str_repeat($pad_string, $paddingRequired), 0, $paddingRequired, $encoding);
694 741 default:
695 - $leftPaddingLength = \floor($paddingRequired / 2);
742 + $leftPaddingLength = floor($paddingRequired / 2);
696 743 $rightPaddingLength = $paddingRequired - $leftPaddingLength;
697 - return self::mb_substr(\str_repeat($pad_string, $leftPaddingLength), 0, $leftPaddingLength, $encoding) . $string . self::mb_substr(\str_repeat($pad_string, $rightPaddingLength), 0, $rightPaddingLength, $encoding);
744 + return self::mb_substr(str_repeat($pad_string, $leftPaddingLength), 0, $leftPaddingLength, $encoding) . $string . self::mb_substr(str_repeat($pad_string, $rightPaddingLength), 0, $rightPaddingLength, $encoding);
698 745 }
699 746 }
700 - public static function mb_ucfirst(string $string, ?string $encoding = null) : string
747 + /** @return string|false */
748 + public static function mb_ucfirst(string $string, ?string $encoding = null)
701 749 {
702 750 if (null === $encoding) {
703 751 $encoding = self::mb_internal_encoding();
704 - } else {
705 - self::assertEncoding($encoding, 'mb_ucfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given');
752 + } elseif (!self::assertEncoding($encoding, 'mb_ucfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given')) {
753 + return \false;
706 754 }
707 - $firstChar = \mb_substr($string, 0, 1, $encoding);
708 - $firstChar = \mb_convert_case($firstChar, \MB_CASE_TITLE, $encoding);
709 - return $firstChar . \mb_substr($string, 1, null, $encoding);
755 + $firstChar = mb_substr($string, 0, 1, $encoding);
756 + $firstChar = mb_convert_case($firstChar, \MB_CASE_TITLE, $encoding);
757 + return $firstChar . mb_substr($string, 1, null, $encoding);
710 758 }
711 - public static function mb_lcfirst(string $string, ?string $encoding = null) : string
759 + /** @return string|false */
760 + public static function mb_lcfirst(string $string, ?string $encoding = null)
712 761 {
713 762 if (null === $encoding) {
714 763 $encoding = self::mb_internal_encoding();
715 - } else {
716 - self::assertEncoding($encoding, 'mb_lcfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given');
764 + } elseif (!self::assertEncoding($encoding, 'mb_lcfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given')) {
765 + return \false;
717 766 }
718 - $firstChar = \mb_substr($string, 0, 1, $encoding);
719 - $firstChar = \mb_convert_case($firstChar, \MB_CASE_LOWER, $encoding);
720 - return $firstChar . \mb_substr($string, 1, null, $encoding);
767 + $firstChar = mb_substr($string, 0, 1, $encoding);
768 + $firstChar = mb_convert_case($firstChar, \MB_CASE_LOWER, $encoding);
769 + return $firstChar . mb_substr($string, 1, null, $encoding);
721 770 }
771 + /** @return string|false */
772 + public static function mb_trim(string $string, ?string $characters = null, ?string $encoding = null)
773 + {
774 + return self::mb_internal_trim('{^[%s]+|[%1$s]+$}Du', $string, $characters, $encoding, __FUNCTION__);
775 + }
776 + /** @return string|false */
777 + public static function mb_ltrim(string $string, ?string $characters = null, ?string $encoding = null)
778 + {
779 + return self::mb_internal_trim('{^[%s]+}Du', $string, $characters, $encoding, __FUNCTION__);
780 + }
781 + /** @return string|false */
782 + public static function mb_rtrim(string $string, ?string $characters = null, ?string $encoding = null)
783 + {
784 + return self::mb_internal_trim('{[%s]+$}Du', $string, $characters, $encoding, __FUNCTION__);
785 + }
722 786 private static function getSubpart($pos, $part, $haystack, $encoding)
723 787 {
724 788 if (\false === $pos) {
725 789 return \false;
@@ -732,9 +796,9 @@
732 796 private static function html_encoding_callback(array $m)
733 797 {
734 798 $i = 1;
735 799 $entities = '';
736 - $m = \unpack('C*', \htmlentities($m[0], \ENT_COMPAT, 'UTF-8'));
800 + $m = unpack('C*', htmlentities($m[0], \ENT_COMPAT, 'UTF-8'));
737 801 while (isset($m[$i])) {
738 802 if (0x80 > $m[$i]) {
739 803 $entities .= \chr($m[$i++]);
740 804 continue;
@@ -755,9 +819,9 @@
755 819 return self::mb_convert_case($s[1], \MB_CASE_UPPER, 'UTF-8') . self::mb_convert_case($s[2], \MB_CASE_LOWER, 'UTF-8');
756 820 }
757 821 private static function getData($file)
758 822 {
759 - if (\file_exists($file = __DIR__ . '/Resources/unidata/' . $file . '.php')) {
823 + if (file_exists($file = __DIR__ . '/Resources/unidata/' . $file . '.php')) {
760 824 return require $file;
761 825 }
762 826 return \false;
763 827 }
@@ -768,9 +832,9 @@
768 832 }
769 833 if ('UTF-8' === $encoding) {
770 834 return 'UTF-8';
771 835 }
772 - $encoding = \strtoupper($encoding);
836 + $encoding = strtoupper($encoding);
773 837 if ('8BIT' === $encoding || 'BINARY' === $encoding) {
774 838 return 'CP850';
775 839 }
776 840 if ('UTF8' === $encoding) {
@@ -775,19 +839,72 @@
775 839 }
776 840 if ('UTF8' === $encoding) {
777 841 return 'UTF-8';
778 842 }
843 + if ('UTF-32' === $encoding) {
844 + return 'UTF-32BE';
845 + }
846 + if ('UTF-16' === $encoding) {
847 + return 'UTF-16BE';
848 + }
779 849 return $encoding;
780 850 }
781 - private static function assertEncoding(string $encoding, string $errorFormat) : void
851 + private static function iconv($fromEncoding, $toEncoding, $s)
782 852 {
853 + if (null === self::$iconvSupportsIgnore) {
854 + self::$iconvSupportsIgnore = \false !== @iconv('UTF-8', 'UTF-8//IGNORE', '');
855 + }
856 + return self::$iconvSupportsIgnore ? iconv($fromEncoding, $toEncoding . '//IGNORE', $s) : iconv($fromEncoding, $toEncoding, $s);
857 + }
858 + /** @return string|false */
859 + private static function mb_internal_trim(string $regex, string $string, ?string $characters, ?string $encoding, string $function)
860 + {
861 + if (null === $encoding) {
862 + $encoding = self::mb_internal_encoding();
863 + } elseif (!self::assertEncoding($encoding, $function . '(): Argument #3 ($encoding) must be a valid encoding, "%s" given')) {
864 + return \false;
865 + }
866 + if ('' === $characters) {
867 + return null === $encoding ? $string : self::mb_convert_encoding($string, $encoding);
868 + }
869 + if ('UTF-8' === $encoding) {
870 + $encoding = null;
871 + if (!preg_match('//u', $string)) {
872 + $string = @self::iconv('UTF-8', 'UTF-8', $string);
873 + }
874 + if (null !== $characters && !preg_match('//u', $characters)) {
875 + $characters = @self::iconv('UTF-8', 'UTF-8', $characters);
876 + }
877 + } else {
878 + $string = self::iconv($encoding, 'UTF-8', $string);
879 + if (null !== $characters) {
880 + $characters = self::iconv($encoding, 'UTF-8', $characters);
881 + }
882 + }
883 + if (null === $characters) {
884 + $characters = "\\0 \f\n\r\t\v             

   …᠎";
885 + } else {
886 + $characters = preg_quote($characters);
887 + }
888 + $string = preg_replace(\sprintf($regex, $characters), '', $string);
889 + if (null === $encoding) {
890 + return $string;
891 + }
892 + return self::iconv('UTF-8', $encoding, $string);
893 + }
894 + private static function assertEncoding(string $encoding, string $errorFormat): bool
895 + {
783 896 try {
784 897 $validEncoding = @self::mb_check_encoding('', $encoding);
785 898 } catch (\ValueError $e) {
786 899 throw new \ValueError(\sprintf($errorFormat, $encoding));
787 900 }
788 - // BC for PHP 7.3 and lower
789 901 if (!$validEncoding) {
790 - throw new \ValueError(\sprintf($errorFormat, $encoding));
902 + if (80000 > \PHP_VERSION_ID) {
903 + trigger_error(\sprintf($errorFormat, $encoding), \E_USER_WARNING);
904 + } else {
905 + throw new \ValueError(\sprintf($errorFormat, $encoding));
906 + }
791 907 }
908 + return $validEncoding;
792 909 }
793 910 }