PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 4.7.0
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v4.7.0
0.9.6 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.2 1.7.0 1.7.1 1.8.0 1.8.1 1.9.0 2.0.0 2.0.1 2.1.1 2.2.1 2.3.1 2.4.0 2.5.0 2.5.1 2.6.0 2.7.0 2.8.0 2.9.0 3.0.1 3.0.2 3.0.3 3.1.0 3.10.0 3.11.0 3.11.1 3.2.0 3.2.1 3.3.0 3.4.0 3.5.0 3.5.1 3.5.2 3.6.1 3.7.0 3.8.0 3.8.2 3.9.0 4.0.1 4.1.0 4.1.1 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.8.0 trunk 0.10.0 0.10.1 0.11.1 0.11.2 0.3.1 0.3.2 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.5.2 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5
wp-mail-smtp / vendor_prefixed / symfony / polyfill-mbstring / Mbstring.php
wp-mail-smtp / vendor_prefixed / symfony / polyfill-mbstring Last commit date
Resources 6 months ago LICENSE 6 months ago Mbstring.php 6 months ago bootstrap.php 6 months ago bootstrap80.php 6 months ago
Mbstring.php
839 lines
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace WPMailSMTP\Vendor\Symfony\Polyfill\Mbstring;
12
13 /**
14 * Partial mbstring implementation in PHP, iconv based, UTF-8 centric.
15 *
16 * Implemented:
17 * - mb_chr - Returns a specific character from its Unicode code point
18 * - mb_convert_encoding - Convert character encoding
19 * - mb_convert_variables - Convert character code in variable(s)
20 * - mb_decode_mimeheader - Decode string in MIME header field
21 * - mb_encode_mimeheader - Encode string for MIME header XXX NATIVE IMPLEMENTATION IS REALLY BUGGED
22 * - mb_decode_numericentity - Decode HTML numeric string reference to character
23 * - mb_encode_numericentity - Encode character to HTML numeric string reference
24 * - mb_convert_case - Perform case folding on a string
25 * - mb_detect_encoding - Detect character encoding
26 * - mb_get_info - Get internal settings of mbstring
27 * - mb_http_input - Detect HTTP input character encoding
28 * - mb_http_output - Set/Get HTTP output character encoding
29 * - mb_internal_encoding - Set/Get internal character encoding
30 * - mb_list_encodings - Returns an array of all supported encodings
31 * - mb_ord - Returns the Unicode code point of a character
32 * - mb_output_handler - Callback function converts character encoding in output buffer
33 * - mb_scrub - Replaces ill-formed byte sequences with substitute characters
34 * - mb_strlen - Get string length
35 * - mb_strpos - Find position of first occurrence of string in a string
36 * - mb_strrpos - Find position of last occurrence of a string in a string
37 * - mb_str_split - Convert a string to an array
38 * - mb_strtolower - Make a string lowercase
39 * - mb_strtoupper - Make a string uppercase
40 * - mb_substitute_character - Set/Get substitution character
41 * - mb_substr - Get part of string
42 * - mb_stripos - Finds position of first occurrence of a string within another, case insensitive
43 * - mb_stristr - Finds first occurrence of a string within another, case insensitive
44 * - mb_strrchr - Finds the last occurrence of a character in a string within another
45 * - mb_strrichr - Finds the last occurrence of a character in a string within another, case insensitive
46 * - mb_strripos - Finds position of last occurrence of a string within another, case insensitive
47 * - mb_strstr - Finds first occurrence of a string within another
48 * - mb_strwidth - Return width of string
49 * - mb_substr_count - Count the number of substring occurrences
50 * - mb_ucfirst - Make a string's first character uppercase
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
55 *
56 * Not implemented:
57 * - mb_convert_kana - Convert "kana" one from another ("zen-kaku", "han-kaku" and more)
58 * - mb_ereg_* - Regular expression with multibyte support
59 * - mb_parse_str - Parse GET/POST/COOKIE data and set global variable
60 * - mb_preferred_mime_name - Get MIME charset string
61 * - mb_regex_encoding - Returns current encoding for multibyte regex as string
62 * - mb_regex_set_options - Set/Get the default options for mbregex functions
63 * - mb_send_mail - Send encoded mail
64 * - mb_split - Split multibyte string using regular expression
65 * - mb_strcut - Get part of string
66 * - mb_strimwidth - Get truncated string with specified width
67 *
68 * @author Nicolas Grekas <p@tchwork.com>
69 *
70 * @internal
71 */
72 final class Mbstring
73 {
74 public const MB_CASE_FOLD = \PHP_INT_MAX;
75 private const SIMPLE_CASE_FOLD = [['µ', 'ſ', "�
76 ", 'ς', "ϐ", "ϑ", "ϕ", "ϖ", "ϰ", "ϱ", "ϵ", "", ""], ['μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "", 'ι']];
77 private static $encodingList = ['ASCII', 'UTF-8'];
78 private static $language = 'neutral';
79 private static $internalEncoding = 'UTF-8';
80 public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null)
81 {
82 if (\is_array($s)) {
83 $r = [];
84 foreach ($s as $str) {
85 $r[] = self::mb_convert_encoding($str, $toEncoding, $fromEncoding);
86 }
87 return $r;
88 }
89 if (\is_array($fromEncoding) || null !== $fromEncoding && \false !== \strpos($fromEncoding, ',')) {
90 $fromEncoding = self::mb_detect_encoding($s, $fromEncoding);
91 } else {
92 $fromEncoding = self::getEncoding($fromEncoding);
93 }
94 $toEncoding = self::getEncoding($toEncoding);
95 if ('BASE64' === $fromEncoding) {
96 $s = \base64_decode($s);
97 $fromEncoding = $toEncoding;
98 }
99 if ('BASE64' === $toEncoding) {
100 return \base64_encode($s);
101 }
102 if ('HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding) {
103 if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) {
104 $fromEncoding = 'Windows-1252';
105 }
106 if ('UTF-8' !== $fromEncoding) {
107 $s = \iconv($fromEncoding, 'UTF-8//IGNORE', $s);
108 }
109 return \preg_replace_callback('/[\\x80-\\xFF]+/', [__CLASS__, 'html_encoding_callback'], $s);
110 }
111 if ('HTML-ENTITIES' === $fromEncoding) {
112 $s = \html_entity_decode($s, \ENT_COMPAT, 'UTF-8');
113 $fromEncoding = 'UTF-8';
114 }
115 return \iconv($fromEncoding, $toEncoding . '//IGNORE', $s);
116 }
117 public static function mb_convert_variables($toEncoding, $fromEncoding, &...$vars)
118 {
119 $ok = \true;
120 \array_walk_recursive($vars, function (&$v) use(&$ok, $toEncoding, $fromEncoding) {
121 if (\false === ($v = self::mb_convert_encoding($v, $toEncoding, $fromEncoding))) {
122 $ok = \false;
123 }
124 });
125 return $ok ? $fromEncoding : \false;
126 }
127 public static function mb_decode_mimeheader($s)
128 {
129 return \iconv_mime_decode($s, 2, self::$internalEncoding);
130 }
131 public static function mb_encode_mimeheader($s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null)
132 {
133 \trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', \E_USER_WARNING);
134 }
135 public static function mb_decode_numericentity($s, $convmap, $encoding = null)
136 {
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);
139 return null;
140 }
141 if (!\is_array($convmap) || 80000 > \PHP_VERSION_ID && !$convmap) {
142 return \false;
143 }
144 if (null !== $encoding && !\is_scalar($encoding)) {
145 \trigger_error('mb_decode_numericentity() expects parameter 3 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
146 return '';
147 // Instead of null (cf. mb_encode_numericentity).
148 }
149 $s = (string) $s;
150 if ('' === $s) {
151 return '';
152 }
153 $encoding = self::getEncoding($encoding);
154 if ('UTF-8' === $encoding) {
155 $encoding = null;
156 if (!\preg_match('//u', $s)) {
157 $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s);
158 }
159 } else {
160 $s = \iconv($encoding, 'UTF-8//IGNORE', $s);
161 }
162 $cnt = \floor(\count($convmap) / 4) * 4;
163 for ($i = 0; $i < $cnt; $i += 4) {
164 // collector_decode_htmlnumericentity ignores $convmap[$i + 3]
165 $convmap[$i] += $convmap[$i + 2];
166 $convmap[$i + 1] += $convmap[$i + 2];
167 }
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];
170 for ($i = 0; $i < $cnt; $i += 4) {
171 if ($c >= $convmap[$i] && $c <= $convmap[$i + 1]) {
172 return self::mb_chr($c - $convmap[$i + 2]);
173 }
174 }
175 return $m[0];
176 }, $s);
177 if (null === $encoding) {
178 return $s;
179 }
180 return \iconv('UTF-8', $encoding . '//IGNORE', $s);
181 }
182 public static function mb_encode_numericentity($s, $convmap, $encoding = null, $is_hex = \false)
183 {
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);
186 return null;
187 }
188 if (!\is_array($convmap) || 80000 > \PHP_VERSION_ID && !$convmap) {
189 return \false;
190 }
191 if (null !== $encoding && !\is_scalar($encoding)) {
192 \trigger_error('mb_encode_numericentity() expects parameter 3 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
193 return null;
194 // Instead of '' (cf. mb_decode_numericentity).
195 }
196 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);
198 return null;
199 }
200 $s = (string) $s;
201 if ('' === $s) {
202 return '';
203 }
204 $encoding = self::getEncoding($encoding);
205 if ('UTF-8' === $encoding) {
206 $encoding = null;
207 if (!\preg_match('//u', $s)) {
208 $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s);
209 }
210 } else {
211 $s = \iconv($encoding, 'UTF-8//IGNORE', $s);
212 }
213 static $ulenMask = ["\xc0" => 2, "\xd0" => 2, "\xe0" => 3, "\xf0" => 4];
214 $cnt = \floor(\count($convmap) / 4) * 4;
215 $i = 0;
216 $len = \strlen($s);
217 $result = '';
218 while ($i < $len) {
219 $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xf0"];
220 $uchr = \substr($s, $i, $ulen);
221 $i += $ulen;
222 $c = self::mb_ord($uchr);
223 for ($j = 0; $j < $cnt; $j += 4) {
224 if ($c >= $convmap[$j] && $c <= $convmap[$j + 1]) {
225 $cOffset = $c + $convmap[$j + 2] & $convmap[$j + 3];
226 $result .= $is_hex ? \sprintf('&#x%X;', $cOffset) : '&#' . $cOffset . ';';
227 continue 2;
228 }
229 }
230 $result .= $uchr;
231 }
232 if (null === $encoding) {
233 return $result;
234 }
235 return \iconv('UTF-8', $encoding . '//IGNORE', $result);
236 }
237 public static function mb_convert_case($s, $mode, $encoding = null)
238 {
239 $s = (string) $s;
240 if ('' === $s) {
241 return '';
242 }
243 $encoding = self::getEncoding($encoding);
244 if ('UTF-8' === $encoding) {
245 $encoding = null;
246 if (!\preg_match('//u', $s)) {
247 $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s);
248 }
249 } else {
250 $s = \iconv($encoding, 'UTF-8//IGNORE', $s);
251 }
252 if (\MB_CASE_TITLE == $mode) {
253 static $titleRegexp = null;
254 if (null === $titleRegexp) {
255 $titleRegexp = self::getData('titleCaseRegexp');
256 }
257 $s = \preg_replace_callback($titleRegexp, [__CLASS__, 'title_case'], $s);
258 } else {
259 if (\MB_CASE_UPPER == $mode) {
260 static $upper = null;
261 if (null === $upper) {
262 $upper = self::getData('upperCase');
263 }
264 $map = $upper;
265 } else {
266 if (self::MB_CASE_FOLD === $mode) {
267 static $caseFolding = null;
268 if (null === $caseFolding) {
269 $caseFolding = self::getData('caseFolding');
270 }
271 $s = \strtr($s, $caseFolding);
272 }
273 static $lower = null;
274 if (null === $lower) {
275 $lower = self::getData('lowerCase');
276 }
277 $map = $lower;
278 }
279 static $ulenMask = ["\xc0" => 2, "\xd0" => 2, "\xe0" => 3, "\xf0" => 4];
280 $i = 0;
281 $len = \strlen($s);
282 while ($i < $len) {
283 $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xf0"];
284 $uchr = \substr($s, $i, $ulen);
285 $i += $ulen;
286 if (isset($map[$uchr])) {
287 $uchr = $map[$uchr];
288 $nlen = \strlen($uchr);
289 if ($nlen == $ulen) {
290 $nlen = $i;
291 do {
292 $s[--$nlen] = $uchr[--$ulen];
293 } while ($ulen);
294 } else {
295 $s = \substr_replace($s, $uchr, $i - $ulen, $ulen);
296 $len += $nlen - $ulen;
297 $i += $nlen - $ulen;
298 }
299 }
300 }
301 }
302 if (null === $encoding) {
303 return $s;
304 }
305 return \iconv('UTF-8', $encoding . '//IGNORE', $s);
306 }
307 public static function mb_internal_encoding($encoding = null)
308 {
309 if (null === $encoding) {
310 return self::$internalEncoding;
311 }
312 $normalizedEncoding = self::getEncoding($encoding);
313 if ('UTF-8' === $normalizedEncoding || \false !== @\iconv($normalizedEncoding, $normalizedEncoding, ' ')) {
314 self::$internalEncoding = $normalizedEncoding;
315 return \true;
316 }
317 if (80000 > \PHP_VERSION_ID) {
318 return \false;
319 }
320 throw new \ValueError(\sprintf('Argument #1 ($encoding) must be a valid encoding, "%s" given', $encoding));
321 }
322 public static function mb_language($lang = null)
323 {
324 if (null === $lang) {
325 return self::$language;
326 }
327 switch ($normalizedLang = \strtolower($lang)) {
328 case 'uni':
329 case 'neutral':
330 self::$language = $normalizedLang;
331 return \true;
332 }
333 if (80000 > \PHP_VERSION_ID) {
334 return \false;
335 }
336 throw new \ValueError(\sprintf('Argument #1 ($language) must be a valid language, "%s" given', $lang));
337 }
338 public static function mb_list_encodings()
339 {
340 return ['UTF-8'];
341 }
342 public static function mb_encoding_aliases($encoding)
343 {
344 switch (\strtoupper($encoding)) {
345 case 'UTF8':
346 case 'UTF-8':
347 return ['utf8'];
348 }
349 return \false;
350 }
351 public static function mb_check_encoding($var = null, $encoding = null)
352 {
353 if (null === $encoding) {
354 if (null === $var) {
355 return \false;
356 }
357 $encoding = self::$internalEncoding;
358 }
359 if (!\is_array($var)) {
360 return self::mb_detect_encoding($var, [$encoding]) || \false !== @\iconv($encoding, $encoding, $var);
361 }
362 foreach ($var as $key => $value) {
363 if (!self::mb_check_encoding($key, $encoding)) {
364 return \false;
365 }
366 if (!self::mb_check_encoding($value, $encoding)) {
367 return \false;
368 }
369 }
370 return \true;
371 }
372 public static function mb_detect_encoding($str, $encodingList = null, $strict = \false)
373 {
374 if (null === $encodingList) {
375 $encodingList = self::$encodingList;
376 } else {
377 if (!\is_array($encodingList)) {
378 $encodingList = \array_map('trim', \explode(',', $encodingList));
379 }
380 $encodingList = \array_map('strtoupper', $encodingList);
381 }
382 foreach ($encodingList as $enc) {
383 switch ($enc) {
384 case 'ASCII':
385 if (!\preg_match('/[\\x80-\\xFF]/', $str)) {
386 return $enc;
387 }
388 break;
389 case 'UTF8':
390 case 'UTF-8':
391 if (\preg_match('//u', $str)) {
392 return 'UTF-8';
393 }
394 break;
395 default:
396 if (0 === \strncmp($enc, 'ISO-8859-', 9)) {
397 return $enc;
398 }
399 }
400 }
401 return \false;
402 }
403 public static function mb_detect_order($encodingList = null)
404 {
405 if (null === $encodingList) {
406 return self::$encodingList;
407 }
408 if (!\is_array($encodingList)) {
409 $encodingList = \array_map('trim', \explode(',', $encodingList));
410 }
411 $encodingList = \array_map('strtoupper', $encodingList);
412 foreach ($encodingList as $enc) {
413 switch ($enc) {
414 default:
415 if (\strncmp($enc, 'ISO-8859-', 9)) {
416 return \false;
417 }
418 // no break
419 case 'ASCII':
420 case 'UTF8':
421 case 'UTF-8':
422 }
423 }
424 self::$encodingList = $encodingList;
425 return \true;
426 }
427 public static function mb_strlen($s, $encoding = null)
428 {
429 $encoding = self::getEncoding($encoding);
430 if ('CP850' === $encoding || 'ASCII' === $encoding) {
431 return \strlen($s);
432 }
433 return @\iconv_strlen($s, $encoding);
434 }
435 public static function mb_strpos($haystack, $needle, $offset = 0, $encoding = null)
436 {
437 $encoding = self::getEncoding($encoding);
438 if ('CP850' === $encoding || 'ASCII' === $encoding) {
439 return \strpos($haystack, $needle, $offset);
440 }
441 $needle = (string) $needle;
442 if ('' === $needle) {
443 if (80000 > \PHP_VERSION_ID) {
444 \trigger_error(__METHOD__ . ': Empty delimiter', \E_USER_WARNING);
445 return \false;
446 }
447 return 0;
448 }
449 return \iconv_strpos($haystack, $needle, $offset, $encoding);
450 }
451 public static function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null)
452 {
453 $encoding = self::getEncoding($encoding);
454 if ('CP850' === $encoding || 'ASCII' === $encoding) {
455 return \strrpos($haystack, $needle, $offset);
456 }
457 if ($offset != (int) $offset) {
458 $offset = 0;
459 } elseif ($offset = (int) $offset) {
460 if ($offset < 0) {
461 if (0 > ($offset += self::mb_strlen($needle))) {
462 $haystack = self::mb_substr($haystack, 0, $offset, $encoding);
463 }
464 $offset = 0;
465 } else {
466 $haystack = self::mb_substr($haystack, $offset, 2147483647, $encoding);
467 }
468 }
469 $pos = '' !== $needle || 80000 > \PHP_VERSION_ID ? \iconv_strrpos($haystack, $needle, $encoding) : self::mb_strlen($haystack, $encoding);
470 return \false !== $pos ? $offset + $pos : \false;
471 }
472 public static function mb_str_split($string, $split_length = 1, $encoding = null)
473 {
474 if (null !== $string && !\is_scalar($string) && !(\is_object($string) && \method_exists($string, '__toString'))) {
475 \trigger_error('mb_str_split() expects parameter 1 to be string, ' . \gettype($string) . ' given', \E_USER_WARNING);
476 return null;
477 }
478 if (1 > ($split_length = (int) $split_length)) {
479 if (80000 > \PHP_VERSION_ID) {
480 \trigger_error('The length of each segment must be greater than zero', \E_USER_WARNING);
481 return \false;
482 }
483 throw new \ValueError('Argument #2 ($length) must be greater than 0');
484 }
485 if (null === $encoding) {
486 $encoding = \mb_internal_encoding();
487 }
488 if ('UTF-8' === ($encoding = self::getEncoding($encoding))) {
489 $rx = '/(';
490 while (65535 < $split_length) {
491 $rx .= '.{65535}';
492 $split_length -= 65535;
493 }
494 $rx .= '.{' . $split_length . '})/us';
495 return \preg_split($rx, $string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY);
496 }
497 $result = [];
498 $length = \mb_strlen($string, $encoding);
499 for ($i = 0; $i < $length; $i += $split_length) {
500 $result[] = \mb_substr($string, $i, $split_length, $encoding);
501 }
502 return $result;
503 }
504 public static function mb_strtolower($s, $encoding = null)
505 {
506 return self::mb_convert_case($s, \MB_CASE_LOWER, $encoding);
507 }
508 public static function mb_strtoupper($s, $encoding = null)
509 {
510 return self::mb_convert_case($s, \MB_CASE_UPPER, $encoding);
511 }
512 public static function mb_substitute_character($c = null)
513 {
514 if (null === $c) {
515 return 'none';
516 }
517 if (0 === \strcasecmp($c, 'none')) {
518 return \true;
519 }
520 if (80000 > \PHP_VERSION_ID) {
521 return \false;
522 }
523 if (\is_int($c) || 'long' === $c || 'entity' === $c) {
524 return \false;
525 }
526 throw new \ValueError('Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint');
527 }
528 public static function mb_substr($s, $start, $length = null, $encoding = null)
529 {
530 $encoding = self::getEncoding($encoding);
531 if ('CP850' === $encoding || 'ASCII' === $encoding) {
532 return (string) \substr($s, $start, null === $length ? 2147483647 : $length);
533 }
534 if ($start < 0) {
535 $start = \iconv_strlen($s, $encoding) + $start;
536 if ($start < 0) {
537 $start = 0;
538 }
539 }
540 if (null === $length) {
541 $length = 2147483647;
542 } elseif ($length < 0) {
543 $length = \iconv_strlen($s, $encoding) + $length - $start;
544 if ($length < 0) {
545 return '';
546 }
547 }
548 return (string) \iconv_substr($s, $start, $length, $encoding);
549 }
550 public static function mb_stripos($haystack, $needle, $offset = 0, $encoding = null)
551 {
552 [$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)]);
553 return self::mb_strpos($haystack, $needle, $offset, $encoding);
554 }
555 public static function mb_stristr($haystack, $needle, $part = \false, $encoding = null)
556 {
557 $pos = self::mb_stripos($haystack, $needle, 0, $encoding);
558 return self::getSubpart($pos, $part, $haystack, $encoding);
559 }
560 public static function mb_strrchr($haystack, $needle, $part = \false, $encoding = null)
561 {
562 $encoding = self::getEncoding($encoding);
563 if ('CP850' === $encoding || 'ASCII' === $encoding) {
564 $pos = \strrpos($haystack, $needle);
565 } else {
566 $needle = self::mb_substr($needle, 0, 1, $encoding);
567 $pos = \iconv_strrpos($haystack, $needle, $encoding);
568 }
569 return self::getSubpart($pos, $part, $haystack, $encoding);
570 }
571 public static function mb_strrichr($haystack, $needle, $part = \false, $encoding = null)
572 {
573 $needle = self::mb_substr($needle, 0, 1, $encoding);
574 $pos = self::mb_strripos($haystack, $needle, $encoding);
575 return self::getSubpart($pos, $part, $haystack, $encoding);
576 }
577 public static function mb_strripos($haystack, $needle, $offset = 0, $encoding = null)
578 {
579 $haystack = self::mb_convert_case($haystack, \MB_CASE_LOWER, $encoding);
580 $needle = self::mb_convert_case($needle, \MB_CASE_LOWER, $encoding);
581 $haystack = \str_replace(self::SIMPLE_CASE_FOLD[0], self::SIMPLE_CASE_FOLD[1], $haystack);
582 $needle = \str_replace(self::SIMPLE_CASE_FOLD[0], self::SIMPLE_CASE_FOLD[1], $needle);
583 return self::mb_strrpos($haystack, $needle, $offset, $encoding);
584 }
585 public static function mb_strstr($haystack, $needle, $part = \false, $encoding = null)
586 {
587 $pos = \strpos($haystack, $needle);
588 if (\false === $pos) {
589 return \false;
590 }
591 if ($part) {
592 return \substr($haystack, 0, $pos);
593 }
594 return \substr($haystack, $pos);
595 }
596 public static function mb_get_info($type = 'all')
597 {
598 $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'];
599 if ('all' === $type) {
600 return $info;
601 }
602 if (isset($info[$type])) {
603 return $info[$type];
604 }
605 return \false;
606 }
607 public static function mb_http_input($type = '')
608 {
609 return \false;
610 }
611 public static function mb_http_output($encoding = null)
612 {
613 return null !== $encoding ? 'pass' === $encoding : 'pass';
614 }
615 public static function mb_strwidth($s, $encoding = null)
616 {
617 $encoding = self::getEncoding($encoding);
618 if ('UTF-8' !== $encoding) {
619 $s = \iconv($encoding, 'UTF-8//IGNORE', $s);
620 }
621 $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);
622 return ($wide << 1) + \iconv_strlen($s, 'UTF-8');
623 }
624 public static function mb_substr_count($haystack, $needle, $encoding = null)
625 {
626 return \substr_count($haystack, $needle);
627 }
628 public static function mb_output_handler($contents, $status)
629 {
630 return $contents;
631 }
632 public static function mb_chr($code, $encoding = null)
633 {
634 if (0x80 > ($code %= 0x200000)) {
635 $s = \chr($code);
636 } elseif (0x800 > $code) {
637 $s = \chr(0xc0 | $code >> 6) . \chr(0x80 | $code & 0x3f);
638 } elseif (0x10000 > $code) {
639 $s = \chr(0xe0 | $code >> 12) . \chr(0x80 | $code >> 6 & 0x3f) . \chr(0x80 | $code & 0x3f);
640 } else {
641 $s = \chr(0xf0 | $code >> 18) . \chr(0x80 | $code >> 12 & 0x3f) . \chr(0x80 | $code >> 6 & 0x3f) . \chr(0x80 | $code & 0x3f);
642 }
643 if ('UTF-8' !== ($encoding = self::getEncoding($encoding))) {
644 $s = \mb_convert_encoding($s, $encoding, 'UTF-8');
645 }
646 return $s;
647 }
648 public static function mb_ord($s, $encoding = null)
649 {
650 if ('UTF-8' !== ($encoding = self::getEncoding($encoding))) {
651 $s = \mb_convert_encoding($s, 'UTF-8', $encoding);
652 }
653 if (1 === \strlen($s)) {
654 return \ord($s);
655 }
656 $code = ($s = \unpack('C*', \substr($s, 0, 4))) ? $s[1] : 0;
657 if (0xf0 <= $code) {
658 return ($code - 0xf0 << 18) + ($s[2] - 0x80 << 12) + ($s[3] - 0x80 << 6) + $s[4] - 0x80;
659 }
660 if (0xe0 <= $code) {
661 return ($code - 0xe0 << 12) + ($s[2] - 0x80 << 6) + $s[3] - 0x80;
662 }
663 if (0xc0 <= $code) {
664 return ($code - 0xc0 << 6) + $s[2] - 0x80;
665 }
666 return $code;
667 }
668 public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, ?string $encoding = null) : string
669 {
670 if (!\in_array($pad_type, [\STR_PAD_RIGHT, \STR_PAD_LEFT, \STR_PAD_BOTH], \true)) {
671 throw new \ValueError('mb_str_pad(): Argument #4 ($pad_type) must be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH');
672 }
673 if (null === $encoding) {
674 $encoding = self::mb_internal_encoding();
675 } else {
676 self::assertEncoding($encoding, 'mb_str_pad(): Argument #5 ($encoding) must be a valid encoding, "%s" given');
677 }
678 if (self::mb_strlen($pad_string, $encoding) <= 0) {
679 throw new \ValueError('mb_str_pad(): Argument #3 ($pad_string) must be a non-empty string');
680 }
681 $paddingRequired = $length - self::mb_strlen($string, $encoding);
682 if ($paddingRequired < 1) {
683 return $string;
684 }
685 switch ($pad_type) {
686 case \STR_PAD_LEFT:
687 return self::mb_substr(\str_repeat($pad_string, $paddingRequired), 0, $paddingRequired, $encoding) . $string;
688 case \STR_PAD_RIGHT:
689 return $string . self::mb_substr(\str_repeat($pad_string, $paddingRequired), 0, $paddingRequired, $encoding);
690 default:
691 $leftPaddingLength = \floor($paddingRequired / 2);
692 $rightPaddingLength = $paddingRequired - $leftPaddingLength;
693 return self::mb_substr(\str_repeat($pad_string, $leftPaddingLength), 0, $leftPaddingLength, $encoding) . $string . self::mb_substr(\str_repeat($pad_string, $rightPaddingLength), 0, $rightPaddingLength, $encoding);
694 }
695 }
696 public static function mb_ucfirst(string $string, ?string $encoding = null) : string
697 {
698 if (null === $encoding) {
699 $encoding = self::mb_internal_encoding();
700 } else {
701 self::assertEncoding($encoding, 'mb_ucfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given');
702 }
703 $firstChar = \mb_substr($string, 0, 1, $encoding);
704 $firstChar = \mb_convert_case($firstChar, \MB_CASE_TITLE, $encoding);
705 return $firstChar . \mb_substr($string, 1, null, $encoding);
706 }
707 public static function mb_lcfirst(string $string, ?string $encoding = null) : string
708 {
709 if (null === $encoding) {
710 $encoding = self::mb_internal_encoding();
711 } else {
712 self::assertEncoding($encoding, 'mb_lcfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given');
713 }
714 $firstChar = \mb_substr($string, 0, 1, $encoding);
715 $firstChar = \mb_convert_case($firstChar, \MB_CASE_LOWER, $encoding);
716 return $firstChar . \mb_substr($string, 1, null, $encoding);
717 }
718 private static function getSubpart($pos, $part, $haystack, $encoding)
719 {
720 if (\false === $pos) {
721 return \false;
722 }
723 if ($part) {
724 return self::mb_substr($haystack, 0, $pos, $encoding);
725 }
726 return self::mb_substr($haystack, $pos, null, $encoding);
727 }
728 private static function html_encoding_callback(array $m)
729 {
730 $i = 1;
731 $entities = '';
732 $m = \unpack('C*', \htmlentities($m[0], \ENT_COMPAT, 'UTF-8'));
733 while (isset($m[$i])) {
734 if (0x80 > $m[$i]) {
735 $entities .= \chr($m[$i++]);
736 continue;
737 }
738 if (0xf0 <= $m[$i]) {
739 $c = ($m[$i++] - 0xf0 << 18) + ($m[$i++] - 0x80 << 12) + ($m[$i++] - 0x80 << 6) + $m[$i++] - 0x80;
740 } elseif (0xe0 <= $m[$i]) {
741 $c = ($m[$i++] - 0xe0 << 12) + ($m[$i++] - 0x80 << 6) + $m[$i++] - 0x80;
742 } else {
743 $c = ($m[$i++] - 0xc0 << 6) + $m[$i++] - 0x80;
744 }
745 $entities .= '&#' . $c . ';';
746 }
747 return $entities;
748 }
749 private static function title_case(array $s)
750 {
751 return self::mb_convert_case($s[1], \MB_CASE_UPPER, 'UTF-8') . self::mb_convert_case($s[2], \MB_CASE_LOWER, 'UTF-8');
752 }
753 private static function getData($file)
754 {
755 if (\file_exists($file = __DIR__ . '/Resources/unidata/' . $file . '.php')) {
756 return require $file;
757 }
758 return \false;
759 }
760 private static function getEncoding($encoding)
761 {
762 if (null === $encoding) {
763 return self::$internalEncoding;
764 }
765 if ('UTF-8' === $encoding) {
766 return 'UTF-8';
767 }
768 $encoding = \strtoupper($encoding);
769 if ('8BIT' === $encoding || 'BINARY' === $encoding) {
770 return 'CP850';
771 }
772 if ('UTF8' === $encoding) {
773 return 'UTF-8';
774 }
775 return $encoding;
776 }
777 public static function mb_trim(string $string, ?string $characters = null, ?string $encoding = null) : string
778 {
779 return self::mb_internal_trim('{^[%s]+|[%1$s]+$}Du', $string, $characters, $encoding, __FUNCTION__);
780 }
781 public static function mb_ltrim(string $string, ?string $characters = null, ?string $encoding = null) : string
782 {
783 return self::mb_internal_trim('{^[%s]+}Du', $string, $characters, $encoding, __FUNCTION__);
784 }
785 public static function mb_rtrim(string $string, ?string $characters = null, ?string $encoding = null) : string
786 {
787 return self::mb_internal_trim('{[%s]+$}D', $string, $characters, $encoding, __FUNCTION__);
788 }
789 private static function mb_internal_trim(string $regex, string $string, ?string $characters, ?string $encoding, string $function) : string
790 {
791 if (null === $encoding) {
792 $encoding = self::mb_internal_encoding();
793 } else {
794 self::assertEncoding($encoding, $function . '(): Argument #3 ($encoding) must be a valid encoding, "%s" given');
795 }
796 if ('' === $characters) {
797 return null === $encoding ? $string : self::mb_convert_encoding($string, $encoding);
798 }
799 if ('UTF-8' === $encoding) {
800 $encoding = null;
801 if (!\preg_match('//u', $string)) {
802 $string = @\iconv('UTF-8', 'UTF-8//IGNORE', $string);
803 }
804 if (null !== $characters && !\preg_match('//u', $characters)) {
805 $characters = @\iconv('UTF-8', 'UTF-8//IGNORE', $characters);
806 }
807 } else {
808 $string = \iconv($encoding, 'UTF-8//IGNORE', $string);
809 if (null !== $characters) {
810 $characters = \iconv($encoding, 'UTF-8//IGNORE', $characters);
811 }
812 }
813 if (null === $characters) {
814 $characters = "\\0 \f\n\r\t\v       �
815      

   �
816 ";
817 } else {
818 $characters = \preg_quote($characters);
819 }
820 $string = \preg_replace(\sprintf($regex, $characters), '', $string);
821 if (null === $encoding) {
822 return $string;
823 }
824 return \iconv('UTF-8', $encoding . '//IGNORE', $string);
825 }
826 private static function assertEncoding(string $encoding, string $errorFormat) : void
827 {
828 try {
829 $validEncoding = @self::mb_check_encoding('', $encoding);
830 } catch (\ValueError $e) {
831 throw new \ValueError(\sprintf($errorFormat, $encoding));
832 }
833 // BC for PHP 7.3 and lower
834 if (!$validEncoding) {
835 throw new \ValueError(\sprintf($errorFormat, $encoding));
836 }
837 }
838 }
839