Skip to content

Commit

Permalink
Merge pull request #71 from doctrine/ucwords-delimeter
Browse files Browse the repository at this point in the history
Use delimeter in ucwords
  • Loading branch information
malarzm committed Jan 9, 2018
2 parents 8dfc457 + 22dd906 commit 5527a48
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions lib/Doctrine/Common/Inflector/Inflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public static function tableize(string $word) : string
*/
public static function classify(string $word) : string
{
return str_replace(' ', '', ucwords(strtr($word, '_-', ' ')));
return str_replace([' ', '_', '-'], '', ucwords($word, ' _-'));
}

/**
Expand All @@ -287,7 +287,7 @@ public static function camelize(string $word) : string
* Uppercases words with configurable delimeters between words.
*
* Takes a string and capitalizes all of the words, like PHP's built-in
* ucwords function. This extends that behavior, however, by allowing the
* ucwords function. This extends that behavior, however, by allowing the
* word delimeters to be configured, rather than only separating on
* whitespace.
*
Expand All @@ -310,13 +310,7 @@ public static function camelize(string $word) : string
*/
public static function ucwords(string $string, string $delimiters = " \n\t\r\0\x0B-") : string
{
return preg_replace_callback(
'/[^' . preg_quote($delimiters, '/') . ']+/',
function($matches) {
return ucfirst($matches[0]);
},
$string
);
return ucwords($string, $delimiters);
}

/**
Expand Down

0 comments on commit 5527a48

Please sign in to comment.