function Mbstring::mb_convert_case
5 calls to Mbstring::mb_convert_case()
- Mbstring::mb_stripos in vendor/
symfony/ polyfill-mbstring/ Mbstring.php - Mbstring::mb_strripos in vendor/
symfony/ polyfill-mbstring/ Mbstring.php - Mbstring::mb_strtolower in vendor/
symfony/ polyfill-mbstring/ Mbstring.php - Mbstring::mb_strtoupper in vendor/
symfony/ polyfill-mbstring/ Mbstring.php - Mbstring::title_case in vendor/
symfony/ polyfill-mbstring/ Mbstring.php
File
-
vendor/
symfony/ polyfill-mbstring/ Mbstring.php, line 285
Class
- Mbstring
- Partial mbstring implementation in PHP, iconv based, UTF-8 centric.
Namespace
Symfony\Polyfill\MbstringCode
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;
if (!preg_match('//u', $s)) {
$s = @iconv('UTF-8', 'UTF-8//IGNORE', $s);
}
}
else {
$s = iconv($encoding, 'UTF-8//IGNORE', $s);
}
if (\MB_CASE_TITLE == $mode) {
static $titleRegexp = null;
if (null === $titleRegexp) {
$titleRegexp = self::getData('titleCaseRegexp');
}
$s = preg_replace_callback($titleRegexp, [
__CLASS__,
'title_case',
], $s);
}
else {
if (\MB_CASE_UPPER == $mode) {
static $upper = null;
if (null === $upper) {
$upper = self::getData('upperCase');
}
$map = $upper;
}
else {
if (self::MB_CASE_FOLD === $mode) {
static $caseFolding = null;
if (null === $caseFolding) {
$caseFolding = self::getData('caseFolding');
}
$s = strtr($s, $caseFolding);
}
static $lower = null;
if (null === $lower) {
$lower = self::getData('lowerCase');
}
$map = $lower;
}
static $ulenMask = [
"\xc0" => 2,
"\xd0" => 2,
"\xe0" => 3,
"\xf0" => 4,
];
$i = 0;
$len = \strlen($s);
while ($i < $len) {
$ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xf0"];
$uchr = substr($s, $i, $ulen);
$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 {
$s = substr_replace($s, $uchr, $i - $ulen, $ulen);
$len += $nlen - $ulen;
$i += $nlen - $ulen;
}
}
}
}
if (null === $encoding) {
return $s;
}
return iconv('UTF-8', $encoding . '//IGNORE', $s);
}