Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[String] Revert "Fixed u()->snake(), b()->snake() and s()->snake() methods" #57616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2024
Merged
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
6 changes: 3 additions & 3 deletions src/Symfony/Component/String/AbstractUnicodeString.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function ascii(array $rules = []): self
public function camel(): parent
{
$str = clone $this;
$str->string = str_replace(' ', '', preg_replace_callback('/\b.(?![A-Z]{2,})/u', static function ($m) use (&$i) {
$str->string = str_replace(' ', '', preg_replace_callback('/\b.(?!\p{Lu})/u', static function ($m) use (&$i) {
return 1 === ++$i ? ('İ' === $m[0] ? 'i̇' : mb_strtolower($m[0], 'UTF-8')) : mb_convert_case($m[0], \MB_CASE_TITLE, 'UTF-8');
}, preg_replace('/[^\pL0-9]++/u', ' ', $this->string)));

Expand Down Expand Up @@ -366,8 +366,8 @@ public function reverse(): parent

public function snake(): parent
{
$str = clone $this;
$str->string = preg_replace('/[ _]+/', '_', mb_strtolower(preg_replace(['/(\p{Lu}+)(\p{Lu}\p{Ll})/u', '/([\p{Ll}0-9])(\p{Lu})/u'], '\1 \2', $str->string), 'UTF-8'));
$str = $this->camel();
$str->string = mb_strtolower(preg_replace(['/(\p{Lu}+)(\p{Lu}\p{Ll})/u', '/([\p{Ll}0-9])(\p{Lu})/u'], '\1_\2', $str->string), 'UTF-8');

return $str;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/String/ByteString.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ public function slice(int $start = 0, ?int $length = null): parent

public function snake(): parent
{
$str = clone $this;
$str->string = preg_replace('/[ _]+/', '_', strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1 \2', $str->string)));
$str = $this->camel();
$str->string = strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1_\2', $str->string));

return $str;
}
Expand Down
10 changes: 6 additions & 4 deletions src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,7 @@ public static function provideCamel()
['symfonyIsGreat', 'symfony_is_great'],
['symfony5IsGreat', 'symfony_5_is_great'],
['symfonyIsGreat', 'Symfony is great'],
['SYMFONYISGREAT', 'SYMFONY_IS_GREAT'],
['symfonyIsAGreatFramework', 'Symfony is a great framework'],
['symfonyIsGREAT', '*Symfony* is GREAT!!'],
['SYMFONY', 'SYMFONY'],
Expand Down Expand Up @@ -1077,11 +1078,12 @@ public static function provideSnake()
['symfony_is_great', 'symfonyIsGREAT'],
['symfony_is_really_great', 'symfonyIsREALLYGreat'],
['symfony', 'SYMFONY'],
['symfony_is_great', 'SYMFONY IS GREAT'],
['symfony_is_great', 'SYMFONY_IS_GREAT'],
['symfonyisgreat', 'SYMFONY IS GREAT'],
['symfonyisgreat', 'SYMFONY_IS_GREAT'],
['symfony_is_great', 'symfony is great'],
['symfony_is_great', 'SYMFONY IS GREAT'],
['symfony_is_great', 'SYMFONY _ IS _ GREAT'],
['symfonyisgreat', 'SYMFONY IS GREAT'],
['symfonyisgreat', 'SYMFONY _ IS _ GREAT'],
['symfony_isgreat', 'Symfony IS GREAT!'],
];
}

Expand Down