Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Tests/StringHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ public static function seedTestUcwords(): array
['мога', 'Мога'],
['αβγ δεζ', 'Αβγ Δεζ'],
['åbc öde', 'Åbc Öde'],
'form feed separator' => ["a\x0cbc def", "A\x0cBc Def"],
'vertical tab separator' => ["a\x0bbc def", "A\x0bBc Def"],
'several separators and leading whitespace' => [" \t\x0c åbc\x0c\x0cöde", " \t\x0c Åbc\x0c\x0cÖde"],
];
}

Expand Down
7 changes: 2 additions & 5 deletions src/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
*/
public static function str_pad($input, $length, $padStr = ' ', $type = STR_PAD_RIGHT)
{
return mb_str_pad($input, $length, $padStr, $type);

Check failure on line 333 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Function mb_str_pad not found.
}

/**
Expand Down Expand Up @@ -605,10 +605,10 @@
}

if ($charlist === false) {
return mb_ltrim($str);

Check failure on line 608 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Function mb_ltrim not found.
}

return mb_ltrim($str, $charlist);

Check failure on line 611 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Function mb_ltrim not found.
}

/**
Expand All @@ -632,10 +632,10 @@
}

if ($charlist === false) {
return mb_rtrim($str);

Check failure on line 635 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Function mb_rtrim not found.
}

return mb_rtrim($str, $charlist);

Check failure on line 638 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Function mb_rtrim not found.
}

/**
Expand All @@ -659,10 +659,10 @@
}

if ($charlist === false) {
return mb_trim($str);

Check failure on line 662 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Function mb_trim not found.
}

return mb_trim($str, $charlist);

Check failure on line 665 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Function mb_trim not found.
}

/**
Expand All @@ -684,14 +684,14 @@
public static function ucfirst($str, $delimiter = null, $newDelimiter = null)
{
if ($delimiter === null) {
return mb_ucfirst($str);

Check failure on line 687 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Function mb_ucfirst not found.
}

if ($newDelimiter === null) {
$newDelimiter = $delimiter;
}

return implode($newDelimiter, array_map('mb_ucfirst', explode($delimiter, $str)));

Check failure on line 694 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Parameter #1 $callback of function array_map expects (callable(string): mixed)|null, 'mb_ucfirst' given.
}

/**
Expand All @@ -711,13 +711,10 @@
// Note: [\x0c\x09\x0b\x0a\x0d\x20] matches;
// form feeds, horizontal tabs, vertical tabs, linefeeds and carriage returns
// This corresponds to the definition of a "word" defined at http://www.php.net/ucwords
$pattern = '/(^|([\x0c\x09\x0b\x0a\x0d\x20]+))([^\x0c\x09\x0b\x0a\x0d\x20]{1})[^\x0c\x09\x0b\x0a\x0d\x20]*/u';
$pattern = '/(^|([\x0c\x09\x0b\x0a\x0d\x20]+))([^\x0c\x09\x0b\x0a\x0d\x20]{1})([^\x0c\x09\x0b\x0a\x0d\x20]*)/u';

return preg_replace_callback($pattern, function ($matches) {
$leadingws = $matches[2];
$ucfirst = mb_strtoupper($matches[3]);
$ucword = StringHelper::substr_replace(ltrim($matches[0]), $ucfirst, 0, 1);
return $leadingws . $ucword;
return $matches[2] . mb_strtoupper($matches[3]) . $matches[4];
}, $str);
}

Expand Down
Loading