2020-06-20 17:12:03 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
|
*
|
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
|
*/
|
2020-09-25 14:44:17 +00:00
|
|
|
|
namespace WPMailSMTP\Vendor\Symfony\Polyfill\Mbstring;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Partial mbstring implementation in PHP, iconv based, UTF-8 centric.
|
|
|
|
|
*
|
|
|
|
|
* Implemented:
|
|
|
|
|
* - mb_chr - Returns a specific character from its Unicode code point
|
|
|
|
|
* - mb_convert_encoding - Convert character encoding
|
|
|
|
|
* - mb_convert_variables - Convert character code in variable(s)
|
|
|
|
|
* - mb_decode_mimeheader - Decode string in MIME header field
|
|
|
|
|
* - mb_encode_mimeheader - Encode string for MIME header XXX NATIVE IMPLEMENTATION IS REALLY BUGGED
|
|
|
|
|
* - mb_decode_numericentity - Decode HTML numeric string reference to character
|
|
|
|
|
* - mb_encode_numericentity - Encode character to HTML numeric string reference
|
|
|
|
|
* - mb_convert_case - Perform case folding on a string
|
|
|
|
|
* - mb_detect_encoding - Detect character encoding
|
|
|
|
|
* - mb_get_info - Get internal settings of mbstring
|
|
|
|
|
* - mb_http_input - Detect HTTP input character encoding
|
|
|
|
|
* - mb_http_output - Set/Get HTTP output character encoding
|
|
|
|
|
* - mb_internal_encoding - Set/Get internal character encoding
|
|
|
|
|
* - mb_list_encodings - Returns an array of all supported encodings
|
|
|
|
|
* - mb_ord - Returns the Unicode code point of a character
|
|
|
|
|
* - mb_output_handler - Callback function converts character encoding in output buffer
|
|
|
|
|
* - mb_scrub - Replaces ill-formed byte sequences with substitute characters
|
|
|
|
|
* - mb_strlen - Get string length
|
|
|
|
|
* - mb_strpos - Find position of first occurrence of string in a string
|
|
|
|
|
* - mb_strrpos - Find position of last occurrence of a string in a string
|
|
|
|
|
* - mb_str_split - Convert a string to an array
|
|
|
|
|
* - mb_strtolower - Make a string lowercase
|
|
|
|
|
* - mb_strtoupper - Make a string uppercase
|
|
|
|
|
* - mb_substitute_character - Set/Get substitution character
|
|
|
|
|
* - mb_substr - Get part of string
|
|
|
|
|
* - mb_stripos - Finds position of first occurrence of a string within another, case insensitive
|
|
|
|
|
* - mb_stristr - Finds first occurrence of a string within another, case insensitive
|
|
|
|
|
* - mb_strrchr - Finds the last occurrence of a character in a string within another
|
|
|
|
|
* - mb_strrichr - Finds the last occurrence of a character in a string within another, case insensitive
|
|
|
|
|
* - mb_strripos - Finds position of last occurrence of a string within another, case insensitive
|
|
|
|
|
* - mb_strstr - Finds first occurrence of a string within another
|
|
|
|
|
* - mb_strwidth - Return width of string
|
|
|
|
|
* - mb_substr_count - Count the number of substring occurrences
|
|
|
|
|
*
|
|
|
|
|
* Not implemented:
|
|
|
|
|
* - mb_convert_kana - Convert "kana" one from another ("zen-kaku", "han-kaku" and more)
|
|
|
|
|
* - mb_ereg_* - Regular expression with multibyte support
|
|
|
|
|
* - mb_parse_str - Parse GET/POST/COOKIE data and set global variable
|
|
|
|
|
* - mb_preferred_mime_name - Get MIME charset string
|
|
|
|
|
* - mb_regex_encoding - Returns current encoding for multibyte regex as string
|
|
|
|
|
* - mb_regex_set_options - Set/Get the default options for mbregex functions
|
|
|
|
|
* - mb_send_mail - Send encoded mail
|
|
|
|
|
* - mb_split - Split multibyte string using regular expression
|
|
|
|
|
* - mb_strcut - Get part of string
|
|
|
|
|
* - mb_strimwidth - Get truncated string with specified width
|
|
|
|
|
*
|
|
|
|
|
* @author Nicolas Grekas <p@tchwork.com>
|
|
|
|
|
*
|
|
|
|
|
* @internal
|
|
|
|
|
*/
|
|
|
|
|
final class Mbstring
|
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
const MB_CASE_FOLD = \PHP_INT_MAX;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
private static $encodingList = array('ASCII', 'UTF-8');
|
|
|
|
|
private static $language = 'neutral';
|
|
|
|
|
private static $internalEncoding = 'UTF-8';
|
2020-09-25 14:44:17 +00:00
|
|
|
|
private static $caseFold = array(array('µ', 'ſ', "ͅ", 'ς', "ϐ", "ϑ", "ϕ", "ϖ", "ϰ", "ϱ", "ϵ", "ẛ", "ι"), array('μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "ṡ", 'ι'));
|
2020-06-20 17:12:03 +00:00
|
|
|
|
public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null)
|
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (\is_array($fromEncoding) || \false !== \strpos($fromEncoding, ',')) {
|
2020-06-20 17:12:03 +00:00
|
|
|
|
$fromEncoding = self::mb_detect_encoding($s, $fromEncoding);
|
|
|
|
|
} else {
|
|
|
|
|
$fromEncoding = self::getEncoding($fromEncoding);
|
|
|
|
|
}
|
|
|
|
|
$toEncoding = self::getEncoding($toEncoding);
|
|
|
|
|
if ('BASE64' === $fromEncoding) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$s = \base64_decode($s);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
$fromEncoding = $toEncoding;
|
|
|
|
|
}
|
|
|
|
|
if ('BASE64' === $toEncoding) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \base64_encode($s);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
if ('HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding) {
|
|
|
|
|
if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) {
|
|
|
|
|
$fromEncoding = 'Windows-1252';
|
|
|
|
|
}
|
|
|
|
|
if ('UTF-8' !== $fromEncoding) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$s = \iconv($fromEncoding, 'UTF-8//IGNORE', $s);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \preg_replace_callback('/[\\x80-\\xFF]+/', array(__CLASS__, 'html_encoding_callback'), $s);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
if ('HTML-ENTITIES' === $fromEncoding) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$s = \html_entity_decode($s, \ENT_COMPAT, 'UTF-8');
|
2020-06-20 17:12:03 +00:00
|
|
|
|
$fromEncoding = 'UTF-8';
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \iconv($fromEncoding, $toEncoding . '//IGNORE', $s);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_convert_variables($toEncoding, $fromEncoding, &$a = null, &$b = null, &$c = null, &$d = null, &$e = null, &$f = null)
|
|
|
|
|
{
|
|
|
|
|
$vars = array(&$a, &$b, &$c, &$d, &$e, &$f);
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$ok = \true;
|
|
|
|
|
\array_walk_recursive($vars, function (&$v) use(&$ok, $toEncoding, $fromEncoding) {
|
|
|
|
|
if (\false === ($v = \WPMailSMTP\Vendor\Symfony\Polyfill\Mbstring\Mbstring::mb_convert_encoding($v, $toEncoding, $fromEncoding))) {
|
|
|
|
|
$ok = \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return $ok ? $fromEncoding : \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_decode_mimeheader($s)
|
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \iconv_mime_decode($s, 2, self::$internalEncoding);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_encode_mimeheader($s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null)
|
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
\trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', \E_USER_WARNING);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_decode_numericentity($s, $convmap, $encoding = null)
|
|
|
|
|
{
|
|
|
|
|
if (null !== $s && !\is_scalar($s) && !(\is_object($s) && \method_exists($s, '__toString'))) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
\trigger_error('mb_decode_numericentity() expects parameter 1 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (!\is_array($convmap) || !$convmap) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
if (null !== $encoding && !\is_scalar($encoding)) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
\trigger_error('mb_decode_numericentity() expects parameter 3 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
|
|
|
|
|
return '';
|
|
|
|
|
// Instead of null (cf. mb_encode_numericentity).
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
$s = (string) $s;
|
|
|
|
|
if ('' === $s) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
$encoding = self::getEncoding($encoding);
|
|
|
|
|
if ('UTF-8' === $encoding) {
|
|
|
|
|
$encoding = null;
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (!\preg_match('//u', $s)) {
|
|
|
|
|
$s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$s = \iconv($encoding, 'UTF-8//IGNORE', $s);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$cnt = \floor(\count($convmap) / 4) * 4;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
for ($i = 0; $i < $cnt; $i += 4) {
|
|
|
|
|
// collector_decode_htmlnumericentity ignores $convmap[$i + 3]
|
|
|
|
|
$convmap[$i] += $convmap[$i + 2];
|
|
|
|
|
$convmap[$i + 1] += $convmap[$i + 2];
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$s = \preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function (array $m) use($cnt, $convmap) {
|
|
|
|
|
$c = isset($m[2]) ? (int) \hexdec($m[2]) : $m[1];
|
2020-06-20 17:12:03 +00:00
|
|
|
|
for ($i = 0; $i < $cnt; $i += 4) {
|
|
|
|
|
if ($c >= $convmap[$i] && $c <= $convmap[$i + 1]) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \WPMailSMTP\Vendor\Symfony\Polyfill\Mbstring\Mbstring::mb_chr($c - $convmap[$i + 2]);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $m[0];
|
|
|
|
|
}, $s);
|
|
|
|
|
if (null === $encoding) {
|
|
|
|
|
return $s;
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \iconv('UTF-8', $encoding . '//IGNORE', $s);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
public static function mb_encode_numericentity($s, $convmap, $encoding = null, $is_hex = \false)
|
2020-06-20 17:12:03 +00:00
|
|
|
|
{
|
|
|
|
|
if (null !== $s && !\is_scalar($s) && !(\is_object($s) && \method_exists($s, '__toString'))) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
\trigger_error('mb_encode_numericentity() expects parameter 1 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (!\is_array($convmap) || !$convmap) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
if (null !== $encoding && !\is_scalar($encoding)) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
\trigger_error('mb_encode_numericentity() expects parameter 3 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
|
|
|
|
|
return null;
|
|
|
|
|
// Instead of '' (cf. mb_decode_numericentity).
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
if (null !== $is_hex && !\is_scalar($is_hex)) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
\trigger_error('mb_encode_numericentity() expects parameter 4 to be boolean, ' . \gettype($s) . ' given', \E_USER_WARNING);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
$s = (string) $s;
|
|
|
|
|
if ('' === $s) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
$encoding = self::getEncoding($encoding);
|
|
|
|
|
if ('UTF-8' === $encoding) {
|
|
|
|
|
$encoding = null;
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (!\preg_match('//u', $s)) {
|
|
|
|
|
$s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$s = \iconv($encoding, 'UTF-8//IGNORE', $s);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
static $ulenMask = array("<EFBFBD>" => 2, "<EFBFBD>" => 2, "<EFBFBD>" => 3, "<EFBFBD>" => 4);
|
|
|
|
|
$cnt = \floor(\count($convmap) / 4) * 4;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
$i = 0;
|
|
|
|
|
$len = \strlen($s);
|
|
|
|
|
$result = '';
|
|
|
|
|
while ($i < $len) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$ulen = $s[$i] < "<EFBFBD>" ? 1 : $ulenMask[$s[$i] & "<EFBFBD>"];
|
|
|
|
|
$uchr = \substr($s, $i, $ulen);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
$i += $ulen;
|
|
|
|
|
$c = self::mb_ord($uchr);
|
|
|
|
|
for ($j = 0; $j < $cnt; $j += 4) {
|
|
|
|
|
if ($c >= $convmap[$j] && $c <= $convmap[$j + 1]) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$cOffset = $c + $convmap[$j + 2] & $convmap[$j + 3];
|
|
|
|
|
$result .= $is_hex ? \sprintf('&#x%X;', $cOffset) : '&#' . $cOffset . ';';
|
2020-06-20 17:12:03 +00:00
|
|
|
|
continue 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$result .= $uchr;
|
|
|
|
|
}
|
|
|
|
|
if (null === $encoding) {
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \iconv('UTF-8', $encoding . '//IGNORE', $result);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_convert_case($s, $mode, $encoding = null)
|
|
|
|
|
{
|
|
|
|
|
$s = (string) $s;
|
|
|
|
|
if ('' === $s) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
$encoding = self::getEncoding($encoding);
|
|
|
|
|
if ('UTF-8' === $encoding) {
|
|
|
|
|
$encoding = null;
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (!\preg_match('//u', $s)) {
|
|
|
|
|
$s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$s = \iconv($encoding, 'UTF-8//IGNORE', $s);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (\MB_CASE_TITLE == $mode) {
|
2020-06-20 17:12:03 +00:00
|
|
|
|
static $titleRegexp = null;
|
|
|
|
|
if (null === $titleRegexp) {
|
|
|
|
|
$titleRegexp = self::getData('titleCaseRegexp');
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$s = \preg_replace_callback($titleRegexp, array(__CLASS__, 'title_case'), $s);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
} else {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (\MB_CASE_UPPER == $mode) {
|
2020-06-20 17:12:03 +00:00
|
|
|
|
static $upper = null;
|
|
|
|
|
if (null === $upper) {
|
|
|
|
|
$upper = self::getData('upperCase');
|
|
|
|
|
}
|
|
|
|
|
$map = $upper;
|
|
|
|
|
} else {
|
|
|
|
|
if (self::MB_CASE_FOLD === $mode) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$s = \str_replace(self::$caseFold[0], self::$caseFold[1], $s);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
static $lower = null;
|
|
|
|
|
if (null === $lower) {
|
|
|
|
|
$lower = self::getData('lowerCase');
|
|
|
|
|
}
|
|
|
|
|
$map = $lower;
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
static $ulenMask = array("<EFBFBD>" => 2, "<EFBFBD>" => 2, "<EFBFBD>" => 3, "<EFBFBD>" => 4);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
$i = 0;
|
|
|
|
|
$len = \strlen($s);
|
|
|
|
|
while ($i < $len) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$ulen = $s[$i] < "<EFBFBD>" ? 1 : $ulenMask[$s[$i] & "<EFBFBD>"];
|
|
|
|
|
$uchr = \substr($s, $i, $ulen);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
$i += $ulen;
|
|
|
|
|
if (isset($map[$uchr])) {
|
|
|
|
|
$uchr = $map[$uchr];
|
|
|
|
|
$nlen = \strlen($uchr);
|
|
|
|
|
if ($nlen == $ulen) {
|
|
|
|
|
$nlen = $i;
|
|
|
|
|
do {
|
|
|
|
|
$s[--$nlen] = $uchr[--$ulen];
|
|
|
|
|
} while ($ulen);
|
|
|
|
|
} else {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$s = \substr_replace($s, $uchr, $i - $ulen, $ulen);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
$len += $nlen - $ulen;
|
|
|
|
|
$i += $nlen - $ulen;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (null === $encoding) {
|
|
|
|
|
return $s;
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \iconv('UTF-8', $encoding . '//IGNORE', $s);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_internal_encoding($encoding = null)
|
|
|
|
|
{
|
|
|
|
|
if (null === $encoding) {
|
|
|
|
|
return self::$internalEncoding;
|
|
|
|
|
}
|
|
|
|
|
$encoding = self::getEncoding($encoding);
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if ('UTF-8' === $encoding || \false !== @\iconv($encoding, $encoding, ' ')) {
|
2020-06-20 17:12:03 +00:00
|
|
|
|
self::$internalEncoding = $encoding;
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \true;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_language($lang = null)
|
|
|
|
|
{
|
|
|
|
|
if (null === $lang) {
|
|
|
|
|
return self::$language;
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
switch ($lang = \strtolower($lang)) {
|
2020-06-20 17:12:03 +00:00
|
|
|
|
case 'uni':
|
|
|
|
|
case 'neutral':
|
|
|
|
|
self::$language = $lang;
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \true;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_list_encodings()
|
|
|
|
|
{
|
|
|
|
|
return array('UTF-8');
|
|
|
|
|
}
|
|
|
|
|
public static function mb_encoding_aliases($encoding)
|
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
switch (\strtoupper($encoding)) {
|
2020-06-20 17:12:03 +00:00
|
|
|
|
case 'UTF8':
|
|
|
|
|
case 'UTF-8':
|
|
|
|
|
return array('utf8');
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_check_encoding($var = null, $encoding = null)
|
|
|
|
|
{
|
|
|
|
|
if (null === $encoding) {
|
|
|
|
|
if (null === $var) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
$encoding = self::$internalEncoding;
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return self::mb_detect_encoding($var, array($encoding)) || \false !== @\iconv($encoding, $encoding, $var);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
public static function mb_detect_encoding($str, $encodingList = null, $strict = \false)
|
2020-06-20 17:12:03 +00:00
|
|
|
|
{
|
|
|
|
|
if (null === $encodingList) {
|
|
|
|
|
$encodingList = self::$encodingList;
|
|
|
|
|
} else {
|
|
|
|
|
if (!\is_array($encodingList)) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$encodingList = \array_map('trim', \explode(',', $encodingList));
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$encodingList = \array_map('strtoupper', $encodingList);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
foreach ($encodingList as $enc) {
|
|
|
|
|
switch ($enc) {
|
|
|
|
|
case 'ASCII':
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (!\preg_match('/[\\x80-\\xFF]/', $str)) {
|
2020-06-20 17:12:03 +00:00
|
|
|
|
return $enc;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'UTF8':
|
|
|
|
|
case 'UTF-8':
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (\preg_match('//u', $str)) {
|
2020-06-20 17:12:03 +00:00
|
|
|
|
return 'UTF-8';
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (0 === \strncmp($enc, 'ISO-8859-', 9)) {
|
2020-06-20 17:12:03 +00:00
|
|
|
|
return $enc;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_detect_order($encodingList = null)
|
|
|
|
|
{
|
|
|
|
|
if (null === $encodingList) {
|
|
|
|
|
return self::$encodingList;
|
|
|
|
|
}
|
|
|
|
|
if (!\is_array($encodingList)) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$encodingList = \array_map('trim', \explode(',', $encodingList));
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$encodingList = \array_map('strtoupper', $encodingList);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
foreach ($encodingList as $enc) {
|
|
|
|
|
switch ($enc) {
|
|
|
|
|
default:
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (\strncmp($enc, 'ISO-8859-', 9)) {
|
|
|
|
|
return \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
// no break
|
2020-06-20 17:12:03 +00:00
|
|
|
|
case 'ASCII':
|
|
|
|
|
case 'UTF8':
|
|
|
|
|
case 'UTF-8':
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self::$encodingList = $encodingList;
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \true;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_strlen($s, $encoding = null)
|
|
|
|
|
{
|
|
|
|
|
$encoding = self::getEncoding($encoding);
|
|
|
|
|
if ('CP850' === $encoding || 'ASCII' === $encoding) {
|
|
|
|
|
return \strlen($s);
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return @\iconv_strlen($s, $encoding);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_strpos($haystack, $needle, $offset = 0, $encoding = null)
|
|
|
|
|
{
|
|
|
|
|
$encoding = self::getEncoding($encoding);
|
|
|
|
|
if ('CP850' === $encoding || 'ASCII' === $encoding) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \strpos($haystack, $needle, $offset);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
$needle = (string) $needle;
|
|
|
|
|
if ('' === $needle) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
\trigger_error(__METHOD__ . ': Empty delimiter', \E_USER_WARNING);
|
|
|
|
|
return \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \iconv_strpos($haystack, $needle, $offset, $encoding);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null)
|
|
|
|
|
{
|
|
|
|
|
$encoding = self::getEncoding($encoding);
|
|
|
|
|
if ('CP850' === $encoding || 'ASCII' === $encoding) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \strrpos($haystack, $needle, $offset);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
if ($offset != (int) $offset) {
|
|
|
|
|
$offset = 0;
|
|
|
|
|
} elseif ($offset = (int) $offset) {
|
|
|
|
|
if ($offset < 0) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (0 > ($offset += self::mb_strlen($needle))) {
|
2020-06-20 17:12:03 +00:00
|
|
|
|
$haystack = self::mb_substr($haystack, 0, $offset, $encoding);
|
|
|
|
|
}
|
|
|
|
|
$offset = 0;
|
|
|
|
|
} else {
|
|
|
|
|
$haystack = self::mb_substr($haystack, $offset, 2147483647, $encoding);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$pos = \iconv_strrpos($haystack, $needle, $encoding);
|
|
|
|
|
return \false !== $pos ? $offset + $pos : \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_str_split($string, $split_length = 1, $encoding = null)
|
|
|
|
|
{
|
|
|
|
|
if (null !== $string && !\is_scalar($string) && !(\is_object($string) && \method_exists($string, '__toString'))) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
\trigger_error('mb_str_split() expects parameter 1 to be string, ' . \gettype($string) . ' given', \E_USER_WARNING);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
return null;
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (1 > ($split_length = (int) $split_length)) {
|
|
|
|
|
\trigger_error('The length of each segment must be greater than zero', \E_USER_WARNING);
|
|
|
|
|
return \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
if (null === $encoding) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$encoding = \mb_internal_encoding();
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if ('UTF-8' === ($encoding = self::getEncoding($encoding))) {
|
2020-06-20 17:12:03 +00:00
|
|
|
|
$rx = '/(';
|
|
|
|
|
while (65535 < $split_length) {
|
|
|
|
|
$rx .= '.{65535}';
|
|
|
|
|
$split_length -= 65535;
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$rx .= '.{' . $split_length . '})/us';
|
|
|
|
|
return \preg_split($rx, $string, null, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
$result = array();
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$length = \mb_strlen($string, $encoding);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
for ($i = 0; $i < $length; $i += $split_length) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$result[] = \mb_substr($string, $i, $split_length, $encoding);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
public static function mb_strtolower($s, $encoding = null)
|
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return self::mb_convert_case($s, \MB_CASE_LOWER, $encoding);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_strtoupper($s, $encoding = null)
|
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return self::mb_convert_case($s, \MB_CASE_UPPER, $encoding);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_substitute_character($c = null)
|
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (0 === \strcasecmp($c, 'none')) {
|
|
|
|
|
return \true;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return null !== $c ? \false : 'none';
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_substr($s, $start, $length = null, $encoding = null)
|
|
|
|
|
{
|
|
|
|
|
$encoding = self::getEncoding($encoding);
|
|
|
|
|
if ('CP850' === $encoding || 'ASCII' === $encoding) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return (string) \substr($s, $start, null === $length ? 2147483647 : $length);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
if ($start < 0) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$start = \iconv_strlen($s, $encoding) + $start;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
if ($start < 0) {
|
|
|
|
|
$start = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (null === $length) {
|
|
|
|
|
$length = 2147483647;
|
|
|
|
|
} elseif ($length < 0) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$length = \iconv_strlen($s, $encoding) + $length - $start;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
if ($length < 0) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return (string) \iconv_substr($s, $start, $length, $encoding);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_stripos($haystack, $needle, $offset = 0, $encoding = null)
|
|
|
|
|
{
|
|
|
|
|
$haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding);
|
|
|
|
|
$needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding);
|
|
|
|
|
return self::mb_strpos($haystack, $needle, $offset, $encoding);
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
public static function mb_stristr($haystack, $needle, $part = \false, $encoding = null)
|
2020-06-20 17:12:03 +00:00
|
|
|
|
{
|
|
|
|
|
$pos = self::mb_stripos($haystack, $needle, 0, $encoding);
|
|
|
|
|
return self::getSubpart($pos, $part, $haystack, $encoding);
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
public static function mb_strrchr($haystack, $needle, $part = \false, $encoding = null)
|
2020-06-20 17:12:03 +00:00
|
|
|
|
{
|
|
|
|
|
$encoding = self::getEncoding($encoding);
|
|
|
|
|
if ('CP850' === $encoding || 'ASCII' === $encoding) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \strrchr($haystack, $needle, $part);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
$needle = self::mb_substr($needle, 0, 1, $encoding);
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$pos = \iconv_strrpos($haystack, $needle, $encoding);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
return self::getSubpart($pos, $part, $haystack, $encoding);
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
public static function mb_strrichr($haystack, $needle, $part = \false, $encoding = null)
|
2020-06-20 17:12:03 +00:00
|
|
|
|
{
|
|
|
|
|
$needle = self::mb_substr($needle, 0, 1, $encoding);
|
|
|
|
|
$pos = self::mb_strripos($haystack, $needle, $encoding);
|
|
|
|
|
return self::getSubpart($pos, $part, $haystack, $encoding);
|
|
|
|
|
}
|
|
|
|
|
public static function mb_strripos($haystack, $needle, $offset = 0, $encoding = null)
|
|
|
|
|
{
|
|
|
|
|
$haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding);
|
|
|
|
|
$needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding);
|
|
|
|
|
return self::mb_strrpos($haystack, $needle, $offset, $encoding);
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
public static function mb_strstr($haystack, $needle, $part = \false, $encoding = null)
|
2020-06-20 17:12:03 +00:00
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$pos = \strpos($haystack, $needle);
|
|
|
|
|
if (\false === $pos) {
|
|
|
|
|
return \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
if ($part) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \substr($haystack, 0, $pos);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \substr($haystack, $pos);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_get_info($type = 'all')
|
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$info = array('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');
|
2020-06-20 17:12:03 +00:00
|
|
|
|
if ('all' === $type) {
|
|
|
|
|
return $info;
|
|
|
|
|
}
|
|
|
|
|
if (isset($info[$type])) {
|
|
|
|
|
return $info[$type];
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_http_input($type = '')
|
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_http_output($encoding = null)
|
|
|
|
|
{
|
|
|
|
|
return null !== $encoding ? 'pass' === $encoding : 'pass';
|
|
|
|
|
}
|
|
|
|
|
public static function mb_strwidth($s, $encoding = null)
|
|
|
|
|
{
|
|
|
|
|
$encoding = self::getEncoding($encoding);
|
|
|
|
|
if ('UTF-8' !== $encoding) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$s = \iconv($encoding, 'UTF-8//IGNORE', $s);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$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);
|
|
|
|
|
return ($wide << 1) + \iconv_strlen($s, 'UTF-8');
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_substr_count($haystack, $needle, $encoding = null)
|
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \substr_count($haystack, $needle);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
public static function mb_output_handler($contents, $status)
|
|
|
|
|
{
|
|
|
|
|
return $contents;
|
|
|
|
|
}
|
|
|
|
|
public static function mb_chr($code, $encoding = null)
|
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (0x80 > ($code %= 0x200000)) {
|
2020-06-20 17:12:03 +00:00
|
|
|
|
$s = \chr($code);
|
|
|
|
|
} elseif (0x800 > $code) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$s = \chr(0xc0 | $code >> 6) . \chr(0x80 | $code & 0x3f);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
} elseif (0x10000 > $code) {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$s = \chr(0xe0 | $code >> 12) . \chr(0x80 | $code >> 6 & 0x3f) . \chr(0x80 | $code & 0x3f);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
} else {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$s = \chr(0xf0 | $code >> 18) . \chr(0x80 | $code >> 12 & 0x3f) . \chr(0x80 | $code >> 6 & 0x3f) . \chr(0x80 | $code & 0x3f);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if ('UTF-8' !== ($encoding = self::getEncoding($encoding))) {
|
|
|
|
|
$s = \mb_convert_encoding($s, $encoding, 'UTF-8');
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
public static function mb_ord($s, $encoding = null)
|
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if ('UTF-8' !== ($encoding = self::getEncoding($encoding))) {
|
|
|
|
|
$s = \mb_convert_encoding($s, 'UTF-8', $encoding);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
if (1 === \strlen($s)) {
|
|
|
|
|
return \ord($s);
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$code = ($s = \unpack('C*', \substr($s, 0, 4))) ? $s[1] : 0;
|
|
|
|
|
if (0xf0 <= $code) {
|
|
|
|
|
return ($code - 0xf0 << 18) + ($s[2] - 0x80 << 12) + ($s[3] - 0x80 << 6) + $s[4] - 0x80;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (0xe0 <= $code) {
|
|
|
|
|
return ($code - 0xe0 << 12) + ($s[2] - 0x80 << 6) + $s[3] - 0x80;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (0xc0 <= $code) {
|
|
|
|
|
return ($code - 0xc0 << 6) + $s[2] - 0x80;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
return $code;
|
|
|
|
|
}
|
|
|
|
|
private static function getSubpart($pos, $part, $haystack, $encoding)
|
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (\false === $pos) {
|
|
|
|
|
return \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
if ($part) {
|
|
|
|
|
return self::mb_substr($haystack, 0, $pos, $encoding);
|
|
|
|
|
}
|
|
|
|
|
return self::mb_substr($haystack, $pos, null, $encoding);
|
|
|
|
|
}
|
|
|
|
|
private static function html_encoding_callback(array $m)
|
|
|
|
|
{
|
|
|
|
|
$i = 1;
|
|
|
|
|
$entities = '';
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$m = \unpack('C*', \htmlentities($m[0], \ENT_COMPAT, 'UTF-8'));
|
2020-06-20 17:12:03 +00:00
|
|
|
|
while (isset($m[$i])) {
|
|
|
|
|
if (0x80 > $m[$i]) {
|
|
|
|
|
$entities .= \chr($m[$i++]);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (0xf0 <= $m[$i]) {
|
|
|
|
|
$c = ($m[$i++] - 0xf0 << 18) + ($m[$i++] - 0x80 << 12) + ($m[$i++] - 0x80 << 6) + $m[$i++] - 0x80;
|
|
|
|
|
} elseif (0xe0 <= $m[$i]) {
|
|
|
|
|
$c = ($m[$i++] - 0xe0 << 12) + ($m[$i++] - 0x80 << 6) + $m[$i++] - 0x80;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
} else {
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$c = ($m[$i++] - 0xc0 << 6) + $m[$i++] - 0x80;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$entities .= '&#' . $c . ';';
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
return $entities;
|
|
|
|
|
}
|
|
|
|
|
private static function title_case(array $s)
|
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return self::mb_convert_case($s[1], \MB_CASE_UPPER, 'UTF-8') . self::mb_convert_case($s[2], \MB_CASE_LOWER, 'UTF-8');
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
private static function getData($file)
|
|
|
|
|
{
|
2020-09-25 14:44:17 +00:00
|
|
|
|
if (\file_exists($file = __DIR__ . '/Resources/unidata/' . $file . '.php')) {
|
2020-06-20 17:12:03 +00:00
|
|
|
|
return require $file;
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
return \false;
|
2020-06-20 17:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
private static function getEncoding($encoding)
|
|
|
|
|
{
|
|
|
|
|
if (null === $encoding) {
|
|
|
|
|
return self::$internalEncoding;
|
|
|
|
|
}
|
|
|
|
|
if ('UTF-8' === $encoding) {
|
|
|
|
|
return 'UTF-8';
|
|
|
|
|
}
|
2020-09-25 14:44:17 +00:00
|
|
|
|
$encoding = \strtoupper($encoding);
|
2020-06-20 17:12:03 +00:00
|
|
|
|
if ('8BIT' === $encoding || 'BINARY' === $encoding) {
|
|
|
|
|
return 'CP850';
|
|
|
|
|
}
|
|
|
|
|
if ('UTF8' === $encoding) {
|
|
|
|
|
return 'UTF-8';
|
|
|
|
|
}
|
|
|
|
|
return $encoding;
|
|
|
|
|
}
|
|
|
|
|
}
|