1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-09 06:46:40 +02:00

Strip leading dashes and underscores with camelize

This commit is contained in:
Daniel St. Jules
2015-07-28 22:07:04 -07:00
parent e1c562b7e8
commit f12b40cc29
2 changed files with 6 additions and 6 deletions

View File

@@ -134,8 +134,9 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
{
$encoding = $this->encoding;
$stringy = $this->trim()->lowerCaseFirst();
$stringy->str = preg_replace('/^[-_]+/', '', $stringy->str);
$camelCase = preg_replace_callback(
$stringy->str = preg_replace_callback(
'/[-_\s]+(.)?/u',
function ($match) use ($encoding) {
return $match[1] ? mb_strtoupper($match[1], $encoding) : '';
@@ -148,7 +149,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
function ($match) use ($encoding) {
return mb_strtoupper($match[0], $encoding);
},
$camelCase
$stringy->str
);
return $stringy;

View File

@@ -367,10 +367,9 @@ class StringyTestCase extends PHPUnit_Framework_TestCase
array('dataRate', 'data_rate'),
array('backgroundColor', 'background-color'),
array('yesWeCan', 'yes_we_can'),
// array('mozSomething', '-moz-something'),
// array('carSpeed', '_car_speed_'),
// array('myFunction', 'MY FUNCTION'),
// array('SSLError', 'sslError'),
array('mozSomething', '-moz-something'),
array('carSpeed', '_car_speed_'),
array('serveHTTP', 'ServeHTTP'),
array('1Camel2Case', '1camel2case'),
array('camelΣase', 'camel σase', 'UTF-8'),
array('στανιλCase', 'Στανιλ case', 'UTF-8'),