mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-09 14:56:31 +02:00
Strip leading dashes and underscores with camelize
This commit is contained in:
@@ -134,8 +134,9 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
|||||||
{
|
{
|
||||||
$encoding = $this->encoding;
|
$encoding = $this->encoding;
|
||||||
$stringy = $this->trim()->lowerCaseFirst();
|
$stringy = $this->trim()->lowerCaseFirst();
|
||||||
|
$stringy->str = preg_replace('/^[-_]+/', '', $stringy->str);
|
||||||
|
|
||||||
$camelCase = preg_replace_callback(
|
$stringy->str = preg_replace_callback(
|
||||||
'/[-_\s]+(.)?/u',
|
'/[-_\s]+(.)?/u',
|
||||||
function ($match) use ($encoding) {
|
function ($match) use ($encoding) {
|
||||||
return $match[1] ? mb_strtoupper($match[1], $encoding) : '';
|
return $match[1] ? mb_strtoupper($match[1], $encoding) : '';
|
||||||
@@ -148,7 +149,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
|||||||
function ($match) use ($encoding) {
|
function ($match) use ($encoding) {
|
||||||
return mb_strtoupper($match[0], $encoding);
|
return mb_strtoupper($match[0], $encoding);
|
||||||
},
|
},
|
||||||
$camelCase
|
$stringy->str
|
||||||
);
|
);
|
||||||
|
|
||||||
return $stringy;
|
return $stringy;
|
||||||
|
@@ -367,10 +367,9 @@ class StringyTestCase extends PHPUnit_Framework_TestCase
|
|||||||
array('dataRate', 'data_rate'),
|
array('dataRate', 'data_rate'),
|
||||||
array('backgroundColor', 'background-color'),
|
array('backgroundColor', 'background-color'),
|
||||||
array('yesWeCan', 'yes_we_can'),
|
array('yesWeCan', 'yes_we_can'),
|
||||||
// array('mozSomething', '-moz-something'),
|
array('mozSomething', '-moz-something'),
|
||||||
// array('carSpeed', '_car_speed_'),
|
array('carSpeed', '_car_speed_'),
|
||||||
// array('myFunction', 'MY FUNCTION'),
|
array('serveHTTP', 'ServeHTTP'),
|
||||||
// array('SSLError', 'sslError'),
|
|
||||||
array('1Camel2Case', '1camel2case'),
|
array('1Camel2Case', '1camel2case'),
|
||||||
array('camelΣase', 'camel σase', 'UTF-8'),
|
array('camelΣase', 'camel σase', 'UTF-8'),
|
||||||
array('στανιλCase', 'Στανιλ case', 'UTF-8'),
|
array('στανιλCase', 'Στανιλ case', 'UTF-8'),
|
||||||
|
Reference in New Issue
Block a user