Skip to content

Commit a382cfb

Browse files
committed
normalize underscores in snake()
1 parent 065a961 commit a382cfb

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

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
public function snake(): 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
}

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
public function snake(): 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
}

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)