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

Merge pull request #79 from vlakoff/tweak

Just a little bit of tweaking
This commit is contained in:
Daniel St. Jules
2015-02-03 02:21:24 -08:00
2 changed files with 7 additions and 7 deletions

View File

@@ -169,8 +169,8 @@ class StaticStringy
* replaced with their closest ASCII counterparts, and the rest are removed * replaced with their closest ASCII counterparts, and the rest are removed
* unless instructed otherwise. * unless instructed otherwise.
* *
* @param string $str A string with non-ASCII characters * @param string $str A string with non-ASCII characters
* @param bool $removeUnsupported Whether to remove or not the unsupported characters * @param bool $removeUnsupported Whether or not to remove the unsupported characters
* @return string A string containing only ASCII characters * @return string A string containing only ASCII characters
*/ */
public static function toAscii($str, $removeUnsupported = true) public static function toAscii($str, $removeUnsupported = true)

View File

@@ -235,14 +235,14 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
public function camelize() public function camelize()
{ {
$encoding = $this->encoding; $encoding = $this->encoding;
$stringy = static::create($this->str, $this->encoding); $stringy = $this->trim()->lowerCaseFirst();
$camelCase = preg_replace_callback( $camelCase = 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) : '';
}, },
$stringy->trim()->lowerCaseFirst()->str $stringy->str
); );
$stringy->str = preg_replace_callback( $stringy->str = preg_replace_callback(
@@ -422,7 +422,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
* replaced with their closest ASCII counterparts, and the rest are removed * replaced with their closest ASCII counterparts, and the rest are removed
* unless instructed otherwise. * unless instructed otherwise.
* *
* @param bool $removeUnsupported Whether to remove or not the unsupported characters * @param bool $removeUnsupported Whether or not to remove the unsupported characters
* @return Stringy Object whose $str contains only ASCII characters * @return Stringy Object whose $str contains only ASCII characters
*/ */
public function toAscii($removeUnsupported = true) public function toAscii($removeUnsupported = true)
@@ -784,11 +784,11 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
*/ */
public function slugify($replacement = '-') public function slugify($replacement = '-')
{ {
$stringy = static::create($this->str, $this->encoding); $stringy = $this->toAscii();
$quotedReplacement = preg_quote($replacement); $quotedReplacement = preg_quote($replacement);
$pattern = "/[^a-zA-Z\d\s-_$quotedReplacement]/u"; $pattern = "/[^a-zA-Z\d\s-_$quotedReplacement]/u";
$stringy->str = preg_replace($pattern, '', $stringy->toAscii()); $stringy->str = preg_replace($pattern, '', $stringy);
return $stringy->toLowerCase()->applyDelimiter($replacement) return $stringy->toLowerCase()->applyDelimiter($replacement)
->removeLeft($replacement)->removeRight($replacement); ->removeLeft($replacement)->removeRight($replacement);