[String] Fix of title() method
This commit is contained in:
parent
14dda4160e
commit
af0f5419bb
@ -348,14 +348,11 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
{
|
||||
$str = clone $this;
|
||||
|
||||
if ($allWords) {
|
||||
$str->string = preg_replace_callback('/\b./u', static function ($m) {
|
||||
return mb_convert_case($m[0], MB_CASE_TITLE, 'UTF-8');
|
||||
}, $str->string);
|
||||
} else {
|
||||
$firstChar = mb_substr($str->string, 0, 1, 'UTF-8');
|
||||
$str->string = mb_convert_case($firstChar, MB_CASE_TITLE, 'UTF-8').substr($str->string, \strlen($firstChar));
|
||||
}
|
||||
$limit = $allWords ? -1 : 1;
|
||||
|
||||
$str->string = preg_replace_callback('/\b./u', static function (array $m): string {
|
||||
return mb_convert_case($m[0], MB_CASE_TITLE, 'UTF-8');
|
||||
}, $str->string, $limit);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
@ -292,6 +292,19 @@ abstract class AbstractUnicodeTestCase extends AbstractAsciiTestCase
|
||||
['DEJa', 'dEJa', false],
|
||||
['ΣσΣ', 'σσΣ', false],
|
||||
['Deja Σσς DEJa ΣσΣ', 'deja σσς dEJa σσΣ', true],
|
||||
|
||||
// Spanish
|
||||
['Última prueba', 'última prueba', false],
|
||||
['ÚLTIMA pRUEBA', 'úLTIMA pRUEBA', false],
|
||||
|
||||
['¡Hola spain!', '¡hola spain!', false],
|
||||
['¡HOLA sPAIN!', '¡hOLA sPAIN!', false],
|
||||
|
||||
['¡Hola Spain!', '¡hola spain!', true],
|
||||
['¡HOLA SPAIN!', '¡hOLA sPAIN!', true],
|
||||
|
||||
['Última Prueba', 'última prueba', true],
|
||||
['ÚLTIMA PRUEBA', 'úLTIMA pRUEBA', true],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user