Resources
1 year ago
Mbstring.php
6 months ago
bootstrap.php
1 year ago
bootstrap80.php
1 year ago
index.php
3 years ago
Mbstring.php
692 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Polyfill\Mbstring; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | final class Mbstring |
| 5 | { |
| 6 | public const MB_CASE_FOLD = \PHP_INT_MAX; |
| 7 | private const SIMPLE_CASE_FOLD = [['µ', 'ſ', "� |
| 8 | ", 'ς', "ϐ", "ϑ", "ϕ", "ϖ", "ϰ", "ϱ", "ϵ", "ẛ", "ι"], ['μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "ṡ", 'ι']]; |
| 9 | private static $encodingList = ['ASCII', 'UTF-8']; |
| 10 | private static $language = 'neutral'; |
| 11 | private static $internalEncoding = 'UTF-8'; |
| 12 | public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null) |
| 13 | { |
| 14 | if (\is_array($fromEncoding) || null !== $fromEncoding && \false !== \strpos($fromEncoding, ',')) { |
| 15 | $fromEncoding = self::mb_detect_encoding($s, $fromEncoding); |
| 16 | } else { |
| 17 | $fromEncoding = self::getEncoding($fromEncoding); |
| 18 | } |
| 19 | $toEncoding = self::getEncoding($toEncoding); |
| 20 | if ('BASE64' === $fromEncoding) { |
| 21 | $s = \base64_decode($s); |
| 22 | $fromEncoding = $toEncoding; |
| 23 | } |
| 24 | if ('BASE64' === $toEncoding) { |
| 25 | return \base64_encode($s); |
| 26 | } |
| 27 | if ('HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding) { |
| 28 | if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) { |
| 29 | $fromEncoding = 'Windows-1252'; |
| 30 | } |
| 31 | if ('UTF-8' !== $fromEncoding) { |
| 32 | $s = \iconv($fromEncoding, 'UTF-8//IGNORE', $s); |
| 33 | } |
| 34 | return \preg_replace_callback('/[\\x80-\\xFF]+/', [__CLASS__, 'html_encoding_callback'], $s); |
| 35 | } |
| 36 | if ('HTML-ENTITIES' === $fromEncoding) { |
| 37 | $s = \html_entity_decode($s, \ENT_COMPAT, 'UTF-8'); |
| 38 | $fromEncoding = 'UTF-8'; |
| 39 | } |
| 40 | return \iconv($fromEncoding, $toEncoding . '//IGNORE', $s); |
| 41 | } |
| 42 | public static function mb_convert_variables($toEncoding, $fromEncoding, &...$vars) |
| 43 | { |
| 44 | $ok = \true; |
| 45 | \array_walk_recursive($vars, function (&$v) use(&$ok, $toEncoding, $fromEncoding) { |
| 46 | if (\false === ($v = self::mb_convert_encoding($v, $toEncoding, $fromEncoding))) { |
| 47 | $ok = \false; |
| 48 | } |
| 49 | }); |
| 50 | return $ok ? $fromEncoding : \false; |
| 51 | } |
| 52 | public static function mb_decode_mimeheader($s) |
| 53 | { |
| 54 | return \iconv_mime_decode($s, 2, self::$internalEncoding); |
| 55 | } |
| 56 | public static function mb_encode_mimeheader($s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null) |
| 57 | { |
| 58 | \trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', \E_USER_WARNING); |
| 59 | } |
| 60 | public static function mb_decode_numericentity($s, $convmap, $encoding = null) |
| 61 | { |
| 62 | if (null !== $s && !\is_scalar($s) && !(\is_object($s) && \method_exists($s, '__toString'))) { |
| 63 | \trigger_error('mb_decode_numericentity() expects parameter 1 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING); |
| 64 | return null; |
| 65 | } |
| 66 | if (!\is_array($convmap) || 80000 > \PHP_VERSION_ID && !$convmap) { |
| 67 | return \false; |
| 68 | } |
| 69 | if (null !== $encoding && !\is_scalar($encoding)) { |
| 70 | \trigger_error('mb_decode_numericentity() expects parameter 3 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING); |
| 71 | return ''; |
| 72 | // Instead of null (cf. mb_encode_numericentity). |
| 73 | } |
| 74 | $s = (string) $s; |
| 75 | if ('' === $s) { |
| 76 | return ''; |
| 77 | } |
| 78 | $encoding = self::getEncoding($encoding); |
| 79 | if ('UTF-8' === $encoding) { |
| 80 | $encoding = null; |
| 81 | if (!\preg_match('//u', $s)) { |
| 82 | $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s); |
| 83 | } |
| 84 | } else { |
| 85 | $s = \iconv($encoding, 'UTF-8//IGNORE', $s); |
| 86 | } |
| 87 | $cnt = \floor(\count($convmap) / 4) * 4; |
| 88 | for ($i = 0; $i < $cnt; $i += 4) { |
| 89 | // collector_decode_htmlnumericentity ignores $convmap[$i + 3] |
| 90 | $convmap[$i] += $convmap[$i + 2]; |
| 91 | $convmap[$i + 1] += $convmap[$i + 2]; |
| 92 | } |
| 93 | $s = \preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function (array $m) use($cnt, $convmap) { |
| 94 | $c = isset($m[2]) ? (int) \hexdec($m[2]) : $m[1]; |
| 95 | for ($i = 0; $i < $cnt; $i += 4) { |
| 96 | if ($c >= $convmap[$i] && $c <= $convmap[$i + 1]) { |
| 97 | return self::mb_chr($c - $convmap[$i + 2]); |
| 98 | } |
| 99 | } |
| 100 | return $m[0]; |
| 101 | }, $s); |
| 102 | if (null === $encoding) { |
| 103 | return $s; |
| 104 | } |
| 105 | return \iconv('UTF-8', $encoding . '//IGNORE', $s); |
| 106 | } |
| 107 | public static function mb_encode_numericentity($s, $convmap, $encoding = null, $is_hex = \false) |
| 108 | { |
| 109 | if (null !== $s && !\is_scalar($s) && !(\is_object($s) && \method_exists($s, '__toString'))) { |
| 110 | \trigger_error('mb_encode_numericentity() expects parameter 1 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING); |
| 111 | return null; |
| 112 | } |
| 113 | if (!\is_array($convmap) || 80000 > \PHP_VERSION_ID && !$convmap) { |
| 114 | return \false; |
| 115 | } |
| 116 | if (null !== $encoding && !\is_scalar($encoding)) { |
| 117 | \trigger_error('mb_encode_numericentity() expects parameter 3 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING); |
| 118 | return null; |
| 119 | // Instead of '' (cf. mb_decode_numericentity). |
| 120 | } |
| 121 | if (null !== $is_hex && !\is_scalar($is_hex)) { |
| 122 | \trigger_error('mb_encode_numericentity() expects parameter 4 to be boolean, ' . \gettype($s) . ' given', \E_USER_WARNING); |
| 123 | return null; |
| 124 | } |
| 125 | $s = (string) $s; |
| 126 | if ('' === $s) { |
| 127 | return ''; |
| 128 | } |
| 129 | $encoding = self::getEncoding($encoding); |
| 130 | if ('UTF-8' === $encoding) { |
| 131 | $encoding = null; |
| 132 | if (!\preg_match('//u', $s)) { |
| 133 | $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s); |
| 134 | } |
| 135 | } else { |
| 136 | $s = \iconv($encoding, 'UTF-8//IGNORE', $s); |
| 137 | } |
| 138 | static $ulenMask = ["\xc0" => 2, "\xd0" => 2, "\xe0" => 3, "\xf0" => 4]; |
| 139 | $cnt = \floor(\count($convmap) / 4) * 4; |
| 140 | $i = 0; |
| 141 | $len = \strlen($s); |
| 142 | $result = ''; |
| 143 | while ($i < $len) { |
| 144 | $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xf0"]; |
| 145 | $uchr = \substr($s, $i, $ulen); |
| 146 | $i += $ulen; |
| 147 | $c = self::mb_ord($uchr); |
| 148 | for ($j = 0; $j < $cnt; $j += 4) { |
| 149 | if ($c >= $convmap[$j] && $c <= $convmap[$j + 1]) { |
| 150 | $cOffset = $c + $convmap[$j + 2] & $convmap[$j + 3]; |
| 151 | $result .= $is_hex ? \sprintf('&#x%X;', $cOffset) : '&#' . $cOffset . ';'; |
| 152 | continue 2; |
| 153 | } |
| 154 | } |
| 155 | $result .= $uchr; |
| 156 | } |
| 157 | if (null === $encoding) { |
| 158 | return $result; |
| 159 | } |
| 160 | return \iconv('UTF-8', $encoding . '//IGNORE', $result); |
| 161 | } |
| 162 | public static function mb_convert_case($s, $mode, $encoding = null) |
| 163 | { |
| 164 | $s = (string) $s; |
| 165 | if ('' === $s) { |
| 166 | return ''; |
| 167 | } |
| 168 | $encoding = self::getEncoding($encoding); |
| 169 | if ('UTF-8' === $encoding) { |
| 170 | $encoding = null; |
| 171 | if (!\preg_match('//u', $s)) { |
| 172 | $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s); |
| 173 | } |
| 174 | } else { |
| 175 | $s = \iconv($encoding, 'UTF-8//IGNORE', $s); |
| 176 | } |
| 177 | if (\MB_CASE_TITLE == $mode) { |
| 178 | static $titleRegexp = null; |
| 179 | if (null === $titleRegexp) { |
| 180 | $titleRegexp = self::getData('titleCaseRegexp'); |
| 181 | } |
| 182 | $s = \preg_replace_callback($titleRegexp, [__CLASS__, 'title_case'], $s); |
| 183 | } else { |
| 184 | if (\MB_CASE_UPPER == $mode) { |
| 185 | static $upper = null; |
| 186 | if (null === $upper) { |
| 187 | $upper = self::getData('upperCase'); |
| 188 | } |
| 189 | $map = $upper; |
| 190 | } else { |
| 191 | if (self::MB_CASE_FOLD === $mode) { |
| 192 | static $caseFolding = null; |
| 193 | if (null === $caseFolding) { |
| 194 | $caseFolding = self::getData('caseFolding'); |
| 195 | } |
| 196 | $s = \strtr($s, $caseFolding); |
| 197 | } |
| 198 | static $lower = null; |
| 199 | if (null === $lower) { |
| 200 | $lower = self::getData('lowerCase'); |
| 201 | } |
| 202 | $map = $lower; |
| 203 | } |
| 204 | static $ulenMask = ["\xc0" => 2, "\xd0" => 2, "\xe0" => 3, "\xf0" => 4]; |
| 205 | $i = 0; |
| 206 | $len = \strlen($s); |
| 207 | while ($i < $len) { |
| 208 | $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xf0"]; |
| 209 | $uchr = \substr($s, $i, $ulen); |
| 210 | $i += $ulen; |
| 211 | if (isset($map[$uchr])) { |
| 212 | $uchr = $map[$uchr]; |
| 213 | $nlen = \strlen($uchr); |
| 214 | if ($nlen == $ulen) { |
| 215 | $nlen = $i; |
| 216 | do { |
| 217 | $s[--$nlen] = $uchr[--$ulen]; |
| 218 | } while ($ulen); |
| 219 | } else { |
| 220 | $s = \substr_replace($s, $uchr, $i - $ulen, $ulen); |
| 221 | $len += $nlen - $ulen; |
| 222 | $i += $nlen - $ulen; |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | if (null === $encoding) { |
| 228 | return $s; |
| 229 | } |
| 230 | return \iconv('UTF-8', $encoding . '//IGNORE', $s); |
| 231 | } |
| 232 | public static function mb_internal_encoding($encoding = null) |
| 233 | { |
| 234 | if (null === $encoding) { |
| 235 | return self::$internalEncoding; |
| 236 | } |
| 237 | $normalizedEncoding = self::getEncoding($encoding); |
| 238 | if ('UTF-8' === $normalizedEncoding || \false !== @\iconv($normalizedEncoding, $normalizedEncoding, ' ')) { |
| 239 | self::$internalEncoding = $normalizedEncoding; |
| 240 | return \true; |
| 241 | } |
| 242 | if (80000 > \PHP_VERSION_ID) { |
| 243 | return \false; |
| 244 | } |
| 245 | throw new \ValueError(\sprintf('Argument #1 ($encoding) must be a valid encoding, "%s" given', $encoding)); |
| 246 | } |
| 247 | public static function mb_language($lang = null) |
| 248 | { |
| 249 | if (null === $lang) { |
| 250 | return self::$language; |
| 251 | } |
| 252 | switch ($normalizedLang = \strtolower($lang)) { |
| 253 | case 'uni': |
| 254 | case 'neutral': |
| 255 | self::$language = $normalizedLang; |
| 256 | return \true; |
| 257 | } |
| 258 | if (80000 > \PHP_VERSION_ID) { |
| 259 | return \false; |
| 260 | } |
| 261 | throw new \ValueError(\sprintf('Argument #1 ($language) must be a valid language, "%s" given', $lang)); |
| 262 | } |
| 263 | public static function mb_list_encodings() |
| 264 | { |
| 265 | return ['UTF-8']; |
| 266 | } |
| 267 | public static function mb_encoding_aliases($encoding) |
| 268 | { |
| 269 | switch (\strtoupper($encoding)) { |
| 270 | case 'UTF8': |
| 271 | case 'UTF-8': |
| 272 | return ['utf8']; |
| 273 | } |
| 274 | return \false; |
| 275 | } |
| 276 | public static function mb_check_encoding($var = null, $encoding = null) |
| 277 | { |
| 278 | if (\PHP_VERSION_ID < 70200 && \is_array($var)) { |
| 279 | \trigger_error('mb_check_encoding() expects parameter 1 to be string, array given', \E_USER_WARNING); |
| 280 | return null; |
| 281 | } |
| 282 | if (null === $encoding) { |
| 283 | if (null === $var) { |
| 284 | return \false; |
| 285 | } |
| 286 | $encoding = self::$internalEncoding; |
| 287 | } |
| 288 | if (!\is_array($var)) { |
| 289 | return self::mb_detect_encoding($var, [$encoding]) || \false !== @\iconv($encoding, $encoding, $var); |
| 290 | } |
| 291 | foreach ($var as $key => $value) { |
| 292 | if (!self::mb_check_encoding($key, $encoding)) { |
| 293 | return \false; |
| 294 | } |
| 295 | if (!self::mb_check_encoding($value, $encoding)) { |
| 296 | return \false; |
| 297 | } |
| 298 | } |
| 299 | return \true; |
| 300 | } |
| 301 | public static function mb_detect_encoding($str, $encodingList = null, $strict = \false) |
| 302 | { |
| 303 | if (null === $encodingList) { |
| 304 | $encodingList = self::$encodingList; |
| 305 | } else { |
| 306 | if (!\is_array($encodingList)) { |
| 307 | $encodingList = \array_map('trim', \explode(',', $encodingList)); |
| 308 | } |
| 309 | $encodingList = \array_map('strtoupper', $encodingList); |
| 310 | } |
| 311 | foreach ($encodingList as $enc) { |
| 312 | switch ($enc) { |
| 313 | case 'ASCII': |
| 314 | if (!\preg_match('/[\\x80-\\xFF]/', $str)) { |
| 315 | return $enc; |
| 316 | } |
| 317 | break; |
| 318 | case 'UTF8': |
| 319 | case 'UTF-8': |
| 320 | if (\preg_match('//u', $str)) { |
| 321 | return 'UTF-8'; |
| 322 | } |
| 323 | break; |
| 324 | default: |
| 325 | if (0 === \strncmp($enc, 'ISO-8859-', 9)) { |
| 326 | return $enc; |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | return \false; |
| 331 | } |
| 332 | public static function mb_detect_order($encodingList = null) |
| 333 | { |
| 334 | if (null === $encodingList) { |
| 335 | return self::$encodingList; |
| 336 | } |
| 337 | if (!\is_array($encodingList)) { |
| 338 | $encodingList = \array_map('trim', \explode(',', $encodingList)); |
| 339 | } |
| 340 | $encodingList = \array_map('strtoupper', $encodingList); |
| 341 | foreach ($encodingList as $enc) { |
| 342 | switch ($enc) { |
| 343 | default: |
| 344 | if (\strncmp($enc, 'ISO-8859-', 9)) { |
| 345 | return \false; |
| 346 | } |
| 347 | // no break |
| 348 | case 'ASCII': |
| 349 | case 'UTF8': |
| 350 | case 'UTF-8': |
| 351 | } |
| 352 | } |
| 353 | self::$encodingList = $encodingList; |
| 354 | return \true; |
| 355 | } |
| 356 | public static function mb_strlen($s, $encoding = null) |
| 357 | { |
| 358 | $encoding = self::getEncoding($encoding); |
| 359 | if ('CP850' === $encoding || 'ASCII' === $encoding) { |
| 360 | return \strlen($s); |
| 361 | } |
| 362 | return @\iconv_strlen($s, $encoding); |
| 363 | } |
| 364 | public static function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) |
| 365 | { |
| 366 | $encoding = self::getEncoding($encoding); |
| 367 | if ('CP850' === $encoding || 'ASCII' === $encoding) { |
| 368 | return \strpos($haystack, $needle, $offset); |
| 369 | } |
| 370 | $needle = (string) $needle; |
| 371 | if ('' === $needle) { |
| 372 | if (80000 > \PHP_VERSION_ID) { |
| 373 | \trigger_error(__METHOD__ . ': Empty delimiter', \E_USER_WARNING); |
| 374 | return \false; |
| 375 | } |
| 376 | return 0; |
| 377 | } |
| 378 | return \iconv_strpos($haystack, $needle, $offset, $encoding); |
| 379 | } |
| 380 | public static function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) |
| 381 | { |
| 382 | $encoding = self::getEncoding($encoding); |
| 383 | if ('CP850' === $encoding || 'ASCII' === $encoding) { |
| 384 | return \strrpos($haystack, $needle, $offset); |
| 385 | } |
| 386 | if ($offset != (int) $offset) { |
| 387 | $offset = 0; |
| 388 | } elseif ($offset = (int) $offset) { |
| 389 | if ($offset < 0) { |
| 390 | if (0 > ($offset += self::mb_strlen($needle))) { |
| 391 | $haystack = self::mb_substr($haystack, 0, $offset, $encoding); |
| 392 | } |
| 393 | $offset = 0; |
| 394 | } else { |
| 395 | $haystack = self::mb_substr($haystack, $offset, 2147483647, $encoding); |
| 396 | } |
| 397 | } |
| 398 | $pos = '' !== $needle || 80000 > \PHP_VERSION_ID ? \iconv_strrpos($haystack, $needle, $encoding) : self::mb_strlen($haystack, $encoding); |
| 399 | return \false !== $pos ? $offset + $pos : \false; |
| 400 | } |
| 401 | public static function mb_str_split($string, $split_length = 1, $encoding = null) |
| 402 | { |
| 403 | if (null !== $string && !\is_scalar($string) && !(\is_object($string) && \method_exists($string, '__toString'))) { |
| 404 | \trigger_error('mb_str_split() expects parameter 1 to be string, ' . \gettype($string) . ' given', \E_USER_WARNING); |
| 405 | return null; |
| 406 | } |
| 407 | if (1 > ($split_length = (int) $split_length)) { |
| 408 | if (80000 > \PHP_VERSION_ID) { |
| 409 | \trigger_error('The length of each segment must be greater than zero', \E_USER_WARNING); |
| 410 | return \false; |
| 411 | } |
| 412 | throw new \ValueError('Argument #2 ($length) must be greater than 0'); |
| 413 | } |
| 414 | if (null === $encoding) { |
| 415 | $encoding = \mb_internal_encoding(); |
| 416 | } |
| 417 | if ('UTF-8' === ($encoding = self::getEncoding($encoding))) { |
| 418 | $rx = '/('; |
| 419 | while (65535 < $split_length) { |
| 420 | $rx .= '.{65535}'; |
| 421 | $split_length -= 65535; |
| 422 | } |
| 423 | $rx .= '.{' . $split_length . '})/us'; |
| 424 | return \preg_split($rx, $string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY); |
| 425 | } |
| 426 | $result = []; |
| 427 | $length = \mb_strlen($string, $encoding); |
| 428 | for ($i = 0; $i < $length; $i += $split_length) { |
| 429 | $result[] = \mb_substr($string, $i, $split_length, $encoding); |
| 430 | } |
| 431 | return $result; |
| 432 | } |
| 433 | public static function mb_strtolower($s, $encoding = null) |
| 434 | { |
| 435 | return self::mb_convert_case($s, \MB_CASE_LOWER, $encoding); |
| 436 | } |
| 437 | public static function mb_strtoupper($s, $encoding = null) |
| 438 | { |
| 439 | return self::mb_convert_case($s, \MB_CASE_UPPER, $encoding); |
| 440 | } |
| 441 | public static function mb_substitute_character($c = null) |
| 442 | { |
| 443 | if (null === $c) { |
| 444 | return 'none'; |
| 445 | } |
| 446 | if (0 === \strcasecmp($c, 'none')) { |
| 447 | return \true; |
| 448 | } |
| 449 | if (80000 > \PHP_VERSION_ID) { |
| 450 | return \false; |
| 451 | } |
| 452 | if (\is_int($c) || 'long' === $c || 'entity' === $c) { |
| 453 | return \false; |
| 454 | } |
| 455 | throw new \ValueError('Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint'); |
| 456 | } |
| 457 | public static function mb_substr($s, $start, $length = null, $encoding = null) |
| 458 | { |
| 459 | $encoding = self::getEncoding($encoding); |
| 460 | if ('CP850' === $encoding || 'ASCII' === $encoding) { |
| 461 | return (string) \substr($s, $start, null === $length ? 2147483647 : $length); |
| 462 | } |
| 463 | if ($start < 0) { |
| 464 | $start = \iconv_strlen($s, $encoding) + $start; |
| 465 | if ($start < 0) { |
| 466 | $start = 0; |
| 467 | } |
| 468 | } |
| 469 | if (null === $length) { |
| 470 | $length = 2147483647; |
| 471 | } elseif ($length < 0) { |
| 472 | $length = \iconv_strlen($s, $encoding) + $length - $start; |
| 473 | if ($length < 0) { |
| 474 | return ''; |
| 475 | } |
| 476 | } |
| 477 | return (string) \iconv_substr($s, $start, $length, $encoding); |
| 478 | } |
| 479 | public static function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) |
| 480 | { |
| 481 | [$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)]); |
| 482 | return self::mb_strpos($haystack, $needle, $offset, $encoding); |
| 483 | } |
| 484 | public static function mb_stristr($haystack, $needle, $part = \false, $encoding = null) |
| 485 | { |
| 486 | $pos = self::mb_stripos($haystack, $needle, 0, $encoding); |
| 487 | return self::getSubpart($pos, $part, $haystack, $encoding); |
| 488 | } |
| 489 | public static function mb_strrchr($haystack, $needle, $part = \false, $encoding = null) |
| 490 | { |
| 491 | $encoding = self::getEncoding($encoding); |
| 492 | if ('CP850' === $encoding || 'ASCII' === $encoding) { |
| 493 | $pos = \strrpos($haystack, $needle); |
| 494 | } else { |
| 495 | $needle = self::mb_substr($needle, 0, 1, $encoding); |
| 496 | $pos = \iconv_strrpos($haystack, $needle, $encoding); |
| 497 | } |
| 498 | return self::getSubpart($pos, $part, $haystack, $encoding); |
| 499 | } |
| 500 | public static function mb_strrichr($haystack, $needle, $part = \false, $encoding = null) |
| 501 | { |
| 502 | $needle = self::mb_substr($needle, 0, 1, $encoding); |
| 503 | $pos = self::mb_strripos($haystack, $needle, $encoding); |
| 504 | return self::getSubpart($pos, $part, $haystack, $encoding); |
| 505 | } |
| 506 | public static function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) |
| 507 | { |
| 508 | $haystack = self::mb_convert_case($haystack, \MB_CASE_LOWER, $encoding); |
| 509 | $needle = self::mb_convert_case($needle, \MB_CASE_LOWER, $encoding); |
| 510 | $haystack = \str_replace(self::SIMPLE_CASE_FOLD[0], self::SIMPLE_CASE_FOLD[1], $haystack); |
| 511 | $needle = \str_replace(self::SIMPLE_CASE_FOLD[0], self::SIMPLE_CASE_FOLD[1], $needle); |
| 512 | return self::mb_strrpos($haystack, $needle, $offset, $encoding); |
| 513 | } |
| 514 | public static function mb_strstr($haystack, $needle, $part = \false, $encoding = null) |
| 515 | { |
| 516 | $pos = \strpos($haystack, $needle); |
| 517 | if (\false === $pos) { |
| 518 | return \false; |
| 519 | } |
| 520 | if ($part) { |
| 521 | return \substr($haystack, 0, $pos); |
| 522 | } |
| 523 | return \substr($haystack, $pos); |
| 524 | } |
| 525 | public static function mb_get_info($type = 'all') |
| 526 | { |
| 527 | $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']; |
| 528 | if ('all' === $type) { |
| 529 | return $info; |
| 530 | } |
| 531 | if (isset($info[$type])) { |
| 532 | return $info[$type]; |
| 533 | } |
| 534 | return \false; |
| 535 | } |
| 536 | public static function mb_http_input($type = '') |
| 537 | { |
| 538 | return \false; |
| 539 | } |
| 540 | public static function mb_http_output($encoding = null) |
| 541 | { |
| 542 | return null !== $encoding ? 'pass' === $encoding : 'pass'; |
| 543 | } |
| 544 | public static function mb_strwidth($s, $encoding = null) |
| 545 | { |
| 546 | $encoding = self::getEncoding($encoding); |
| 547 | if ('UTF-8' !== $encoding) { |
| 548 | $s = \iconv($encoding, 'UTF-8//IGNORE', $s); |
| 549 | } |
| 550 | $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); |
| 551 | return ($wide << 1) + \iconv_strlen($s, 'UTF-8'); |
| 552 | } |
| 553 | public static function mb_substr_count($haystack, $needle, $encoding = null) |
| 554 | { |
| 555 | return \substr_count($haystack, $needle); |
| 556 | } |
| 557 | public static function mb_output_handler($contents, $status) |
| 558 | { |
| 559 | return $contents; |
| 560 | } |
| 561 | public static function mb_chr($code, $encoding = null) |
| 562 | { |
| 563 | if (0x80 > ($code %= 0x200000)) { |
| 564 | $s = \chr($code); |
| 565 | } elseif (0x800 > $code) { |
| 566 | $s = \chr(0xc0 | $code >> 6) . \chr(0x80 | $code & 0x3f); |
| 567 | } elseif (0x10000 > $code) { |
| 568 | $s = \chr(0xe0 | $code >> 12) . \chr(0x80 | $code >> 6 & 0x3f) . \chr(0x80 | $code & 0x3f); |
| 569 | } else { |
| 570 | $s = \chr(0xf0 | $code >> 18) . \chr(0x80 | $code >> 12 & 0x3f) . \chr(0x80 | $code >> 6 & 0x3f) . \chr(0x80 | $code & 0x3f); |
| 571 | } |
| 572 | if ('UTF-8' !== ($encoding = self::getEncoding($encoding))) { |
| 573 | $s = \mb_convert_encoding($s, $encoding, 'UTF-8'); |
| 574 | } |
| 575 | return $s; |
| 576 | } |
| 577 | public static function mb_ord($s, $encoding = null) |
| 578 | { |
| 579 | if ('UTF-8' !== ($encoding = self::getEncoding($encoding))) { |
| 580 | $s = \mb_convert_encoding($s, 'UTF-8', $encoding); |
| 581 | } |
| 582 | if (1 === \strlen($s)) { |
| 583 | return \ord($s); |
| 584 | } |
| 585 | $code = ($s = \unpack('C*', \substr($s, 0, 4))) ? $s[1] : 0; |
| 586 | if (0xf0 <= $code) { |
| 587 | return ($code - 0xf0 << 18) + ($s[2] - 0x80 << 12) + ($s[3] - 0x80 << 6) + $s[4] - 0x80; |
| 588 | } |
| 589 | if (0xe0 <= $code) { |
| 590 | return ($code - 0xe0 << 12) + ($s[2] - 0x80 << 6) + $s[3] - 0x80; |
| 591 | } |
| 592 | if (0xc0 <= $code) { |
| 593 | return ($code - 0xc0 << 6) + $s[2] - 0x80; |
| 594 | } |
| 595 | return $code; |
| 596 | } |
| 597 | public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT,?string $encoding = null) : string |
| 598 | { |
| 599 | if (!\in_array($pad_type, [\STR_PAD_RIGHT, \STR_PAD_LEFT, \STR_PAD_BOTH], \true)) { |
| 600 | throw new \ValueError('mb_str_pad(): Argument #4 ($pad_type) must be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH'); |
| 601 | } |
| 602 | if (null === $encoding) { |
| 603 | $encoding = self::mb_internal_encoding(); |
| 604 | } |
| 605 | try { |
| 606 | $validEncoding = @self::mb_check_encoding('', $encoding); |
| 607 | } catch (\ValueError $e) { |
| 608 | throw new \ValueError(\sprintf('mb_str_pad(): Argument #5 ($encoding) must be a valid encoding, "%s" given', $encoding)); |
| 609 | } |
| 610 | // BC for PHP 7.3 and lower |
| 611 | if (!$validEncoding) { |
| 612 | throw new \ValueError(\sprintf('mb_str_pad(): Argument #5 ($encoding) must be a valid encoding, "%s" given', $encoding)); |
| 613 | } |
| 614 | if (self::mb_strlen($pad_string, $encoding) <= 0) { |
| 615 | throw new \ValueError('mb_str_pad(): Argument #3 ($pad_string) must be a non-empty string'); |
| 616 | } |
| 617 | $paddingRequired = $length - self::mb_strlen($string, $encoding); |
| 618 | if ($paddingRequired < 1) { |
| 619 | return $string; |
| 620 | } |
| 621 | switch ($pad_type) { |
| 622 | case \STR_PAD_LEFT: |
| 623 | return self::mb_substr(\str_repeat($pad_string, $paddingRequired), 0, $paddingRequired, $encoding) . $string; |
| 624 | case \STR_PAD_RIGHT: |
| 625 | return $string . self::mb_substr(\str_repeat($pad_string, $paddingRequired), 0, $paddingRequired, $encoding); |
| 626 | default: |
| 627 | $leftPaddingLength = \floor($paddingRequired / 2); |
| 628 | $rightPaddingLength = $paddingRequired - $leftPaddingLength; |
| 629 | return self::mb_substr(\str_repeat($pad_string, $leftPaddingLength), 0, $leftPaddingLength, $encoding) . $string . self::mb_substr(\str_repeat($pad_string, $rightPaddingLength), 0, $rightPaddingLength, $encoding); |
| 630 | } |
| 631 | } |
| 632 | private static function getSubpart($pos, $part, $haystack, $encoding) |
| 633 | { |
| 634 | if (\false === $pos) { |
| 635 | return \false; |
| 636 | } |
| 637 | if ($part) { |
| 638 | return self::mb_substr($haystack, 0, $pos, $encoding); |
| 639 | } |
| 640 | return self::mb_substr($haystack, $pos, null, $encoding); |
| 641 | } |
| 642 | private static function html_encoding_callback(array $m) |
| 643 | { |
| 644 | $i = 1; |
| 645 | $entities = ''; |
| 646 | $m = \unpack('C*', \htmlentities($m[0], \ENT_COMPAT, 'UTF-8')); |
| 647 | while (isset($m[$i])) { |
| 648 | if (0x80 > $m[$i]) { |
| 649 | $entities .= \chr($m[$i++]); |
| 650 | continue; |
| 651 | } |
| 652 | if (0xf0 <= $m[$i]) { |
| 653 | $c = ($m[$i++] - 0xf0 << 18) + ($m[$i++] - 0x80 << 12) + ($m[$i++] - 0x80 << 6) + $m[$i++] - 0x80; |
| 654 | } elseif (0xe0 <= $m[$i]) { |
| 655 | $c = ($m[$i++] - 0xe0 << 12) + ($m[$i++] - 0x80 << 6) + $m[$i++] - 0x80; |
| 656 | } else { |
| 657 | $c = ($m[$i++] - 0xc0 << 6) + $m[$i++] - 0x80; |
| 658 | } |
| 659 | $entities .= '&#' . $c . ';'; |
| 660 | } |
| 661 | return $entities; |
| 662 | } |
| 663 | private static function title_case(array $s) |
| 664 | { |
| 665 | return self::mb_convert_case($s[1], \MB_CASE_UPPER, 'UTF-8') . self::mb_convert_case($s[2], \MB_CASE_LOWER, 'UTF-8'); |
| 666 | } |
| 667 | private static function getData($file) |
| 668 | { |
| 669 | if (\file_exists($file = __DIR__ . '/Resources/unidata/' . $file . '.php')) { |
| 670 | return require $file; |
| 671 | } |
| 672 | return \false; |
| 673 | } |
| 674 | private static function getEncoding($encoding) |
| 675 | { |
| 676 | if (null === $encoding) { |
| 677 | return self::$internalEncoding; |
| 678 | } |
| 679 | if ('UTF-8' === $encoding) { |
| 680 | return 'UTF-8'; |
| 681 | } |
| 682 | $encoding = \strtoupper($encoding); |
| 683 | if ('8BIT' === $encoding || 'BINARY' === $encoding) { |
| 684 | return 'CP850'; |
| 685 | } |
| 686 | if ('UTF8' === $encoding) { |
| 687 | return 'UTF-8'; |
| 688 | } |
| 689 | return $encoding; |
| 690 | } |
| 691 | } |
| 692 |