Skip to content

[String] Fix snake conversion #47185

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
Aug 4, 2022
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
[String] Fix snake conversion
  • Loading branch information
simPod committed Aug 4, 2022
commit 1416dbcc7b064a7cfb35cad6d28aef1eb6d2cb8f
2 changes: 1 addition & 1 deletion src/Symfony/Component/String/AbstractUnicodeString.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public function reverse(): parent

public function snake(): parent
{
$str = $this->camel()->title();
$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
2 changes: 1 addition & 1 deletion src/Symfony/Component/String/ByteString.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public function slice(int $start = 0, int $length = null): parent

public function snake(): parent
{
$str = $this->camel()->title();
$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
3 changes: 3 additions & 0 deletions src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,7 @@ public static function provideCamel()
{
return [
['', ''],
['xY', 'x_y'],
['symfonyIsGreat', 'symfony_is_great'],
['symfony5IsGreat', 'symfony_5_is_great'],
['symfonyIsGreat', 'Symfony is great'],
Expand All @@ -1063,6 +1064,8 @@ public static function provideSnake()
{
return [
['', ''],
['x_y', 'x_y'],
['x_y', 'X_Y'],
['symfony_is_great', 'symfonyIsGreat'],
['symfony5_is_great', 'symfony5IsGreat'],
['symfony5is_great', 'symfony5isGreat'],
Expand Down