Skip to content

Commit 76d8b2b

Browse files
nicolas-grekasfabpot
authored andcommitted
[String] Revert "Fixed u()->snake(), b()->snake() and s()->snake() methods"
1 parent a382cfb commit 76d8b2b

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

AbstractUnicodeString.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function ascii(array $rules = []): self
162162
public function camel(): parent
163163
{
164164
$str = clone $this;
165-
$str->string = str_replace(' ', '', preg_replace_callback('/\b.(?![A-Z]{2,})/u', static function ($m) use (&$i) {
165+
$str->string = str_replace(' ', '', preg_replace_callback('/\b.(?!\p{Lu})/u', static function ($m) use (&$i) {
166166
return 1 === ++$i ? ('İ' === $m[0] ? '' : mb_strtolower($m[0], 'UTF-8')) : mb_convert_case($m[0], \MB_CASE_TITLE, 'UTF-8');
167167
}, preg_replace('/[^\pL0-9]++/u', ' ', $this->string)));
168168

@@ -366,8 +366,8 @@ public function reverse(): parent
366366

367367
public function snake(): parent
368368
{
369-
$str = clone $this;
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'));
369+
$str = $this->camel();
370+
$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');
371371

372372
return $str;
373373
}

ByteString.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ public function slice(int $start = 0, ?int $length = null): parent
366366

367367
public function snake(): parent
368368
{
369-
$str = clone $this;
370-
$str->string = preg_replace('/[ _]+/', '_', strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1 \2', $str->string)));
369+
$str = $this->camel();
370+
$str->string = 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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ public static function provideCamel()
10461046
['symfonyIsGreat', 'symfony_is_great'],
10471047
['symfony5IsGreat', 'symfony_5_is_great'],
10481048
['symfonyIsGreat', 'Symfony is great'],
1049+
['SYMFONYISGREAT', 'SYMFONY_IS_GREAT'],
10491050
['symfonyIsAGreatFramework', 'Symfony is a great framework'],
10501051
['symfonyIsGREAT', '*Symfony* is GREAT!!'],
10511052
['SYMFONY', 'SYMFONY'],
@@ -1077,11 +1078,12 @@ public static function provideSnake()
10771078
['symfony_is_great', 'symfonyIsGREAT'],
10781079
['symfony_is_really_great', 'symfonyIsREALLYGreat'],
10791080
['symfony', 'SYMFONY'],
1080-
['symfony_is_great', 'SYMFONY IS GREAT'],
1081-
['symfony_is_great', 'SYMFONY_IS_GREAT'],
1081+
['symfonyisgreat', 'SYMFONY IS GREAT'],
1082+
['symfonyisgreat', 'SYMFONY_IS_GREAT'],
10821083
['symfony_is_great', 'symfony is great'],
1083-
['symfony_is_great', 'SYMFONY IS GREAT'],
1084-
['symfony_is_great', 'SYMFONY _ IS _ GREAT'],
1084+
['symfonyisgreat', 'SYMFONY IS GREAT'],
1085+
['symfonyisgreat', 'SYMFONY _ IS _ GREAT'],
1086+
['symfony_isgreat', 'Symfony IS GREAT!'],
10851087
];
10861088
}
10871089

0 commit comments

Comments
 (0)