PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.2.0
Independent Analytics – WordPress Analytics Plugin v2.2.0
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / symfony / polyfill-mbstring / Mbstring.php
independent-analytics / vendor / symfony / polyfill-mbstring Last commit date
Resources 3 years ago Mbstring.php 3 years ago bootstrap.php 3 years ago bootstrap80.php 3 years ago
Mbstring.php
700 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 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 *
51 * Not implemented:
52 * - mb_convert_kana - Convert "kana" one from another ("zen-kaku", "han-kaku" and more)
53 * - mb_ereg_* - Regular expression with multibyte support
54 * - mb_parse_str - Parse GET/POST/COOKIE data and set global variable
55 * - mb_preferred_mime_name - Get MIME charset string
56 * - mb_regex_encoding - Returns current encoding for multibyte regex as string
57 * - mb_regex_set_options - Set/Get the default options for mbregex functions
58 * - mb_send_mail - Send encoded mail
59 * - mb_split - Split multibyte string using regular expression
60 * - mb_strcut - Get part of string
61 * - mb_strimwidth - Get truncated string with specified width
62 *
63 * @author Nicolas Grekas <p@tchwork.com>
64 *
65 * @internal
66 */
67 final class Mbstring
68 {
69 public const MB_CASE_FOLD = \PHP_INT_MAX;
70 private const CASE_FOLD = [['µ', 'ſ', "�
71 ", 'ς', "ϐ", "ϑ", "ϕ", "ϖ", "ϰ", "ϱ", "ϵ", "", ""], ['μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "", 'ι']];
72 private static $encodingList = ['ASCII', 'UTF-8'];
73 private static $language = 'neutral';
74 private static $internalEncoding = 'UTF-8';
75 public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null)
76 {
77 if (\is_array($fromEncoding) || null !== $fromEncoding && \false !== \strpos($fromEncoding, ',')) {
78 $fromEncoding = self::mb_detect_encoding($s, $fromEncoding);
79 } else {
80 $fromEncoding = self::getEncoding($fromEncoding);
81 }
82 $toEncoding = self::getEncoding($toEncoding);
83 if ('BASE64' === $fromEncoding) {
84 $s = \base64_decode($s);
85 $fromEncoding = $toEncoding;
86 }
87 if ('BASE64' === $toEncoding) {
88 return \base64_encode($s);
89 }
90 if ('HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding) {
91 if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) {
92 $fromEncoding = 'Windows-1252';
93 }
94 if ('UTF-8' !== $fromEncoding) {
95 $s = \iconv($fromEncoding, 'UTF-8//IGNORE', $s);
96 }
97 return \preg_replace_callback('/[\\x80-\\xFF]+/', [__CLASS__, 'html_encoding_callback'], $s);
98 }
99 if ('HTML-ENTITIES' === $fromEncoding) {
100 $s = \html_entity_decode($s, \ENT_COMPAT, 'UTF-8');
101 $fromEncoding = 'UTF-8';
102 }
103 return \iconv($fromEncoding, $toEncoding . '//IGNORE', $s);
104 }
105 public static function mb_convert_variables($toEncoding, $fromEncoding, &...$vars)
106 {
107 $ok = \true;
108 \array_walk_recursive($vars, function (&$v) use(&$ok, $toEncoding, $fromEncoding) {
109 if (\false === ($v = self::mb_convert_encoding($v, $toEncoding, $fromEncoding))) {
110 $ok = \false;
111 }
112 });
113 return $ok ? $fromEncoding : \false;
114 }
115 public static function mb_decode_mimeheader($s)
116 {
117 return \iconv_mime_decode($s, 2, self::$internalEncoding);
118 }
119 public static function mb_encode_mimeheader($s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null)
120 {
121 \trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', \E_USER_WARNING);
122 }
123 public static function mb_decode_numericentity($s, $convmap, $encoding = null)
124 {
125 if (null !== $s && !\is_scalar($s) && !(\is_object($s) && \method_exists($s, '__toString'))) {
126 \trigger_error('mb_decode_numericentity() expects parameter 1 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
127 return null;
128 }
129 if (!\is_array($convmap) || 80000 > \PHP_VERSION_ID && !$convmap) {
130 return \false;
131 }
132 if (null !== $encoding && !\is_scalar($encoding)) {
133 \trigger_error('mb_decode_numericentity() expects parameter 3 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
134 return '';
135 // Instead of null (cf. mb_encode_numericentity).
136 }
137 $s = (string) $s;
138 if ('' === $s) {
139 return '';
140 }
141 $encoding = self::getEncoding($encoding);
142 if ('UTF-8' === $encoding) {
143 $encoding = null;
144 if (!\preg_match('//u', $s)) {
145 $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s);
146 }
147 } else {
148 $s = \iconv($encoding, 'UTF-8//IGNORE', $s);
149 }
150 $cnt = \floor(\count($convmap) / 4) * 4;
151 for ($i = 0; $i < $cnt; $i += 4) {
152 // collector_decode_htmlnumericentity ignores $convmap[$i + 3]
153 $convmap[$i] += $convmap[$i + 2];
154 $convmap[$i + 1] += $convmap[$i + 2];
155 }
156 $s = \preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function (array $m) use($cnt, $convmap) {
157 $c = isset($m[2]) ? (int) \hexdec($m[2]) : $m[1];
158 for ($i = 0; $i < $cnt; $i += 4) {
159 if ($c >= $convmap[$i] && $c <= $convmap[$i + 1]) {
160 return self::mb_chr($c - $convmap[$i + 2]);
161 }
162 }
163 return $m[0];
164 }, $s);
165 if (null === $encoding) {
166 return $s;
167 }
168 return \iconv('UTF-8', $encoding . '//IGNORE', $s);
169 }
170 public static function mb_encode_numericentity($s, $convmap, $encoding = null, $is_hex = \false)
171 {
172 if (null !== $s && !\is_scalar($s) && !(\is_object($s) && \method_exists($s, '__toString'))) {
173 \trigger_error('mb_encode_numericentity() expects parameter 1 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
174 return null;
175 }
176 if (!\is_array($convmap) || 80000 > \PHP_VERSION_ID && !$convmap) {
177 return \false;
178 }
179 if (null !== $encoding && !\is_scalar($encoding)) {
180 \trigger_error('mb_encode_numericentity() expects parameter 3 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
181 return null;
182 // Instead of '' (cf. mb_decode_numericentity).
183 }
184 if (null !== $is_hex && !\is_scalar($is_hex)) {
185 \trigger_error('mb_encode_numericentity() expects parameter 4 to be boolean, ' . \gettype($s) . ' given', \E_USER_WARNING);
186 return null;
187 }
188 $s = (string) $s;
189 if ('' === $s) {
190 return '';
191 }
192 $encoding = self::getEncoding($encoding);
193 if ('UTF-8' === $encoding) {
194 $encoding = null;
195 if (!\preg_match('//u', $s)) {
196 $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s);
197 }
198 } else {
199 $s = \iconv($encoding, 'UTF-8//IGNORE', $s);
200 }
201 static $ulenMask = ["\xc0" => 2, "\xd0" => 2, "\xe0" => 3, "\xf0" => 4];
202 $cnt = \floor(\count($convmap) / 4) * 4;
203 $i = 0;
204 $len = \strlen($s);
205 $result = '';
206 while ($i < $len) {
207 $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xf0"];
208 $uchr = \substr($s, $i, $ulen);
209 $i += $ulen;
210 $c = self::mb_ord($uchr);
211 for ($j = 0; $j < $cnt; $j += 4) {
212 if ($c >= $convmap[$j] && $c <= $convmap[$j + 1]) {
213 $cOffset = $c + $convmap[$j + 2] & $convmap[$j + 3];
214 $result .= $is_hex ? \sprintf('&#x%X;', $cOffset) : '&#' . $cOffset . ';';
215 continue 2;
216 }
217 }
218 $result .= $uchr;
219 }
220 if (null === $encoding) {
221 return $result;
222 }
223 return \iconv('UTF-8', $encoding . '//IGNORE', $result);
224 }
225 public static function mb_convert_case($s, $mode, $encoding = null)
226 {
227 $s = (string) $s;
228 if ('' === $s) {
229 return '';
230 }
231 $encoding = self::getEncoding($encoding);
232 if ('UTF-8' === $encoding) {
233 $encoding = null;
234 if (!\preg_match('//u', $s)) {
235 $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s);
236 }
237 } else {
238 $s = \iconv($encoding, 'UTF-8//IGNORE', $s);
239 }
240 if (\MB_CASE_TITLE == $mode) {
241 static $titleRegexp = null;
242 if (null === $titleRegexp) {
243 $titleRegexp = self::getData('titleCaseRegexp');
244 }
245 $s = \preg_replace_callback($titleRegexp, [__CLASS__, 'title_case'], $s);
246 } else {
247 if (\MB_CASE_UPPER == $mode) {
248 static $upper = null;
249 if (null === $upper) {
250 $upper = self::getData('upperCase');
251 }
252 $map = $upper;
253 } else {
254 if (self::MB_CASE_FOLD === $mode) {
255 $s = \str_replace(self::CASE_FOLD[0], self::CASE_FOLD[1], $s);
256 }
257 static $lower = null;
258 if (null === $lower) {
259 $lower = self::getData('lowerCase');
260 }
261 $map = $lower;
262 }
263 static $ulenMask = ["\xc0" => 2, "\xd0" => 2, "\xe0" => 3, "\xf0" => 4];
264 $i = 0;
265 $len = \strlen($s);
266 while ($i < $len) {
267 $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xf0"];
268 $uchr = \substr($s, $i, $ulen);
269 $i += $ulen;
270 if (isset($map[$uchr])) {
271 $uchr = $map[$uchr];
272 $nlen = \strlen($uchr);
273 if ($nlen == $ulen) {
274 $nlen = $i;
275 do {
276 $s[--$nlen] = $uchr[--$ulen];
277 } while ($ulen);
278 } else {
279 $s = \substr_replace($s, $uchr, $i - $ulen, $ulen);
280 $len += $nlen - $ulen;
281 $i += $nlen - $ulen;
282 }
283 }
284 }
285 }
286 if (null === $encoding) {
287 return $s;
288 }
289 return \iconv('UTF-8', $encoding . '//IGNORE', $s);
290 }
291 public static function mb_internal_encoding($encoding = null)
292 {
293 if (null === $encoding) {
294 return self::$internalEncoding;
295 }
296 $normalizedEncoding = self::getEncoding($encoding);
297 if ('UTF-8' === $normalizedEncoding || \false !== @\iconv($normalizedEncoding, $normalizedEncoding, ' ')) {
298 self::$internalEncoding = $normalizedEncoding;
299 return \true;
300 }
301 if (80000 > \PHP_VERSION_ID) {
302 return \false;
303 }
304 throw new \ValueError(\sprintf('Argument #1 ($encoding) must be a valid encoding, "%s" given', $encoding));
305 }
306 public static function mb_language($lang = null)
307 {
308 if (null === $lang) {
309 return self::$language;
310 }
311 switch ($normalizedLang = \strtolower($lang)) {
312 case 'uni':
313 case 'neutral':
314 self::$language = $normalizedLang;
315 return \true;
316 }
317 if (80000 > \PHP_VERSION_ID) {
318 return \false;
319 }
320 throw new \ValueError(\sprintf('Argument #1 ($language) must be a valid language, "%s" given', $lang));
321 }
322 public static function mb_list_encodings()
323 {
324 return ['UTF-8'];
325 }
326 public static function mb_encoding_aliases($encoding)
327 {
328 switch (\strtoupper($encoding)) {
329 case 'UTF8':
330 case 'UTF-8':
331 return ['utf8'];
332 }
333 return \false;
334 }
335 public static function mb_check_encoding($var = null, $encoding = null)
336 {
337 if (null === $encoding) {
338 if (null === $var) {
339 return \false;
340 }
341 $encoding = self::$internalEncoding;
342 }
343 return self::mb_detect_encoding($var, [$encoding]) || \false !== @\iconv($encoding, $encoding, $var);
344 }
345 public static function mb_detect_encoding($str, $encodingList = null, $strict = \false)
346 {
347 if (null === $encodingList) {
348 $encodingList = self::$encodingList;
349 } else {
350 if (!\is_array($encodingList)) {
351 $encodingList = \array_map('trim', \explode(',', $encodingList));
352 }
353 $encodingList = \array_map('strtoupper', $encodingList);
354 }
355 foreach ($encodingList as $enc) {
356 switch ($enc) {
357 case 'ASCII':
358 if (!\preg_match('/[\\x80-\\xFF]/', $str)) {
359 return $enc;
360 }
361 break;
362 case 'UTF8':
363 case 'UTF-8':
364 if (\preg_match('//u', $str)) {
365 return 'UTF-8';
366 }
367 break;
368 default:
369 if (0 === \strncmp($enc, 'ISO-8859-', 9)) {
370 return $enc;
371 }
372 }
373 }
374 return \false;
375 }
376 public static function mb_detect_order($encodingList = null)
377 {
378 if (null === $encodingList) {
379 return self::$encodingList;
380 }
381 if (!\is_array($encodingList)) {
382 $encodingList = \array_map('trim', \explode(',', $encodingList));
383 }
384 $encodingList = \array_map('strtoupper', $encodingList);
385 foreach ($encodingList as $enc) {
386 switch ($enc) {
387 default:
388 if (\strncmp($enc, 'ISO-8859-', 9)) {
389 return \false;
390 }
391 // no break
392 case 'ASCII':
393 case 'UTF8':
394 case 'UTF-8':
395 }
396 }
397 self::$encodingList = $encodingList;
398 return \true;
399 }
400 public static function mb_strlen($s, $encoding = null)
401 {
402 $encoding = self::getEncoding($encoding);
403 if ('CP850' === $encoding || 'ASCII' === $encoding) {
404 return \strlen($s);
405 }
406 return @\iconv_strlen($s, $encoding);
407 }
408 public static function mb_strpos($haystack, $needle, $offset = 0, $encoding = null)
409 {
410 $encoding = self::getEncoding($encoding);
411 if ('CP850' === $encoding || 'ASCII' === $encoding) {
412 return \strpos($haystack, $needle, $offset);
413 }
414 $needle = (string) $needle;
415 if ('' === $needle) {
416 if (80000 > \PHP_VERSION_ID) {
417 \trigger_error(__METHOD__ . ': Empty delimiter', \E_USER_WARNING);
418 return \false;
419 }
420 return 0;
421 }
422 return \iconv_strpos($haystack, $needle, $offset, $encoding);
423 }
424 public static function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null)
425 {
426 $encoding = self::getEncoding($encoding);
427 if ('CP850' === $encoding || 'ASCII' === $encoding) {
428 return \strrpos($haystack, $needle, $offset);
429 }
430 if ($offset != (int) $offset) {
431 $offset = 0;
432 } elseif ($offset = (int) $offset) {
433 if ($offset < 0) {
434 if (0 > ($offset += self::mb_strlen($needle))) {
435 $haystack = self::mb_substr($haystack, 0, $offset, $encoding);
436 }
437 $offset = 0;
438 } else {
439 $haystack = self::mb_substr($haystack, $offset, 2147483647, $encoding);
440 }
441 }
442 $pos = '' !== $needle || 80000 > \PHP_VERSION_ID ? \iconv_strrpos($haystack, $needle, $encoding) : self::mb_strlen($haystack, $encoding);
443 return \false !== $pos ? $offset + $pos : \false;
444 }
445 public static function mb_str_split($string, $split_length = 1, $encoding = null)
446 {
447 if (null !== $string && !\is_scalar($string) && !(\is_object($string) && \method_exists($string, '__toString'))) {
448 \trigger_error('mb_str_split() expects parameter 1 to be string, ' . \gettype($string) . ' given', \E_USER_WARNING);
449 return null;
450 }
451 if (1 > ($split_length = (int) $split_length)) {
452 if (80000 > \PHP_VERSION_ID) {
453 \trigger_error('The length of each segment must be greater than zero', \E_USER_WARNING);
454 return \false;
455 }
456 throw new \ValueError('Argument #2 ($length) must be greater than 0');
457 }
458 if (null === $encoding) {
459 $encoding = \mb_internal_encoding();
460 }
461 if ('UTF-8' === ($encoding = self::getEncoding($encoding))) {
462 $rx = '/(';
463 while (65535 < $split_length) {
464 $rx .= '.{65535}';
465 $split_length -= 65535;
466 }
467 $rx .= '.{' . $split_length . '})/us';
468 return \preg_split($rx, $string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY);
469 }
470 $result = [];
471 $length = \mb_strlen($string, $encoding);
472 for ($i = 0; $i < $length; $i += $split_length) {
473 $result[] = \mb_substr($string, $i, $split_length, $encoding);
474 }
475 return $result;
476 }
477 public static function mb_strtolower($s, $encoding = null)
478 {
479 return self::mb_convert_case($s, \MB_CASE_LOWER, $encoding);
480 }
481 public static function mb_strtoupper($s, $encoding = null)
482 {
483 return self::mb_convert_case($s, \MB_CASE_UPPER, $encoding);
484 }
485 public static function mb_substitute_character($c = null)
486 {
487 if (null === $c) {
488 return 'none';
489 }
490 if (0 === \strcasecmp($c, 'none')) {
491 return \true;
492 }
493 if (80000 > \PHP_VERSION_ID) {
494 return \false;
495 }
496 if (\is_int($c) || 'long' === $c || 'entity' === $c) {
497 return \false;
498 }
499 throw new \ValueError('Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint');
500 }
501 public static function mb_substr($s, $start, $length = null, $encoding = null)
502 {
503 $encoding = self::getEncoding($encoding);
504 if ('CP850' === $encoding || 'ASCII' === $encoding) {
505 return (string) \substr($s, $start, null === $length ? 2147483647 : $length);
506 }
507 if ($start < 0) {
508 $start = \iconv_strlen($s, $encoding) + $start;
509 if ($start < 0) {
510 $start = 0;
511 }
512 }
513 if (null === $length) {
514 $length = 2147483647;
515 } elseif ($length < 0) {
516 $length = \iconv_strlen($s, $encoding) + $length - $start;
517 if ($length < 0) {
518 return '';
519 }
520 }
521 return (string) \iconv_substr($s, $start, $length, $encoding);
522 }
523 public static function mb_stripos($haystack, $needle, $offset = 0, $encoding = null)
524 {
525 $haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding);
526 $needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding);
527 return self::mb_strpos($haystack, $needle, $offset, $encoding);
528 }
529 public static function mb_stristr($haystack, $needle, $part = \false, $encoding = null)
530 {
531 $pos = self::mb_stripos($haystack, $needle, 0, $encoding);
532 return self::getSubpart($pos, $part, $haystack, $encoding);
533 }
534 public static function mb_strrchr($haystack, $needle, $part = \false, $encoding = null)
535 {
536 $encoding = self::getEncoding($encoding);
537 if ('CP850' === $encoding || 'ASCII' === $encoding) {
538 $pos = \strrpos($haystack, $needle);
539 } else {
540 $needle = self::mb_substr($needle, 0, 1, $encoding);
541 $pos = \iconv_strrpos($haystack, $needle, $encoding);
542 }
543 return self::getSubpart($pos, $part, $haystack, $encoding);
544 }
545 public static function mb_strrichr($haystack, $needle, $part = \false, $encoding = null)
546 {
547 $needle = self::mb_substr($needle, 0, 1, $encoding);
548 $pos = self::mb_strripos($haystack, $needle, $encoding);
549 return self::getSubpart($pos, $part, $haystack, $encoding);
550 }
551 public static function mb_strripos($haystack, $needle, $offset = 0, $encoding = null)
552 {
553 $haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding);
554 $needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding);
555 return self::mb_strrpos($haystack, $needle, $offset, $encoding);
556 }
557 public static function mb_strstr($haystack, $needle, $part = \false, $encoding = null)
558 {
559 $pos = \strpos($haystack, $needle);
560 if (\false === $pos) {
561 return \false;
562 }
563 if ($part) {
564 return \substr($haystack, 0, $pos);
565 }
566 return \substr($haystack, $pos);
567 }
568 public static function mb_get_info($type = 'all')
569 {
570 $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'];
571 if ('all' === $type) {
572 return $info;
573 }
574 if (isset($info[$type])) {
575 return $info[$type];
576 }
577 return \false;
578 }
579 public static function mb_http_input($type = '')
580 {
581 return \false;
582 }
583 public static function mb_http_output($encoding = null)
584 {
585 return null !== $encoding ? 'pass' === $encoding : 'pass';
586 }
587 public static function mb_strwidth($s, $encoding = null)
588 {
589 $encoding = self::getEncoding($encoding);
590 if ('UTF-8' !== $encoding) {
591 $s = \iconv($encoding, 'UTF-8//IGNORE', $s);
592 }
593 $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);
594 return ($wide << 1) + \iconv_strlen($s, 'UTF-8');
595 }
596 public static function mb_substr_count($haystack, $needle, $encoding = null)
597 {
598 return \substr_count($haystack, $needle);
599 }
600 public static function mb_output_handler($contents, $status)
601 {
602 return $contents;
603 }
604 public static function mb_chr($code, $encoding = null)
605 {
606 if (0x80 > ($code %= 0x200000)) {
607 $s = \chr($code);
608 } elseif (0x800 > $code) {
609 $s = \chr(0xc0 | $code >> 6) . \chr(0x80 | $code & 0x3f);
610 } elseif (0x10000 > $code) {
611 $s = \chr(0xe0 | $code >> 12) . \chr(0x80 | $code >> 6 & 0x3f) . \chr(0x80 | $code & 0x3f);
612 } else {
613 $s = \chr(0xf0 | $code >> 18) . \chr(0x80 | $code >> 12 & 0x3f) . \chr(0x80 | $code >> 6 & 0x3f) . \chr(0x80 | $code & 0x3f);
614 }
615 if ('UTF-8' !== ($encoding = self::getEncoding($encoding))) {
616 $s = \mb_convert_encoding($s, $encoding, 'UTF-8');
617 }
618 return $s;
619 }
620 public static function mb_ord($s, $encoding = null)
621 {
622 if ('UTF-8' !== ($encoding = self::getEncoding($encoding))) {
623 $s = \mb_convert_encoding($s, 'UTF-8', $encoding);
624 }
625 if (1 === \strlen($s)) {
626 return \ord($s);
627 }
628 $code = ($s = \unpack('C*', \substr($s, 0, 4))) ? $s[1] : 0;
629 if (0xf0 <= $code) {
630 return ($code - 0xf0 << 18) + ($s[2] - 0x80 << 12) + ($s[3] - 0x80 << 6) + $s[4] - 0x80;
631 }
632 if (0xe0 <= $code) {
633 return ($code - 0xe0 << 12) + ($s[2] - 0x80 << 6) + $s[3] - 0x80;
634 }
635 if (0xc0 <= $code) {
636 return ($code - 0xc0 << 6) + $s[2] - 0x80;
637 }
638 return $code;
639 }
640 private static function getSubpart($pos, $part, $haystack, $encoding)
641 {
642 if (\false === $pos) {
643 return \false;
644 }
645 if ($part) {
646 return self::mb_substr($haystack, 0, $pos, $encoding);
647 }
648 return self::mb_substr($haystack, $pos, null, $encoding);
649 }
650 private static function html_encoding_callback(array $m)
651 {
652 $i = 1;
653 $entities = '';
654 $m = \unpack('C*', \htmlentities($m[0], \ENT_COMPAT, 'UTF-8'));
655 while (isset($m[$i])) {
656 if (0x80 > $m[$i]) {
657 $entities .= \chr($m[$i++]);
658 continue;
659 }
660 if (0xf0 <= $m[$i]) {
661 $c = ($m[$i++] - 0xf0 << 18) + ($m[$i++] - 0x80 << 12) + ($m[$i++] - 0x80 << 6) + $m[$i++] - 0x80;
662 } elseif (0xe0 <= $m[$i]) {
663 $c = ($m[$i++] - 0xe0 << 12) + ($m[$i++] - 0x80 << 6) + $m[$i++] - 0x80;
664 } else {
665 $c = ($m[$i++] - 0xc0 << 6) + $m[$i++] - 0x80;
666 }
667 $entities .= '&#' . $c . ';';
668 }
669 return $entities;
670 }
671 private static function title_case(array $s)
672 {
673 return self::mb_convert_case($s[1], \MB_CASE_UPPER, 'UTF-8') . self::mb_convert_case($s[2], \MB_CASE_LOWER, 'UTF-8');
674 }
675 private static function getData($file)
676 {
677 if (\file_exists($file = __DIR__ . '/Resources/unidata/' . $file . '.php')) {
678 return require $file;
679 }
680 return \false;
681 }
682 private static function getEncoding($encoding)
683 {
684 if (null === $encoding) {
685 return self::$internalEncoding;
686 }
687 if ('UTF-8' === $encoding) {
688 return 'UTF-8';
689 }
690 $encoding = \strtoupper($encoding);
691 if ('8BIT' === $encoding || 'BINARY' === $encoding) {
692 return 'CP850';
693 }
694 if ('UTF8' === $encoding) {
695 return 'UTF-8';
696 }
697 return $encoding;
698 }
699 }
700