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

Skip to content

Commit 9f16206

Browse files
committed
improve performance of snake case.
1 parent 0ab4b33 commit 9f16206

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

src/Illuminate/Support/Str.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,9 @@ public static function slug($title, $separator = '-')
196196
*/
197197
public static function snake($value, $delimiter = '_')
198198
{
199-
return trim(preg_replace_callback('/[A-Z]/', function($match) use ($delimiter)
200-
{
201-
return $delimiter.strtolower($match[0]);
199+
$replace = '$1'.$delimiter.'$2';
202200

203-
}, $value), $delimiter);
201+
return ctype_lower($value) ? $value : strtolower(preg_replace('/(.)([A-Z])/', $replace, $value));
204202
}
205203

206204
/**

0 commit comments

Comments
 (0)