Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4e57b84

Browse files
bug#57594 [String] Normalize underscores in snake() (xabbuh)
This PR was merged into the 5.4 branch.Discussion----------[String] Normalize underscores in snake()| Q | A| ------------- | ---| Branch? | 5.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Issues |Fix#57497 (comment)| License | MITCommits-------0e6cd07 normalize underscores in snake()
2 parents19b4bf0 +0e6cd07 commit4e57b84

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

‎src/Symfony/Component/String/AbstractUnicodeString.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public function reverse(): parent
367367
publicfunctionsnake():parent
368368
{
369369
$str =clone$this;
370-
$str->string =str_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'));
370+
$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'));
371371

372372
return$str;
373373
}

‎src/Symfony/Component/String/ByteString.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public function slice(int $start = 0, ?int $length = null): parent
367367
publicfunctionsnake():parent
368368
{
369369
$str =clone$this;
370-
$str->string =str_replace('','_',strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/','/([a-z\d])([A-Z])/'],'\1 \2',$str->string)));
370+
$str->string =preg_replace('/[ _]+/','_',strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/','/([a-z\d])([A-Z])/'],'\1 \2',$str->string)));
371371

372372
return$str;
373373
}

‎src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,9 @@ public static function provideSnake()
10791079
['symfony','SYMFONY'],
10801080
['symfony_is_great','SYMFONY IS GREAT'],
10811081
['symfony_is_great','SYMFONY_IS_GREAT'],
1082+
['symfony_is_great','symfony is great'],
1083+
['symfony_is_great','SYMFONY IS GREAT'],
1084+
['symfony_is_great','SYMFONY _ IS _ GREAT'],
10821085
];
10831086
}
10841087

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp