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:
@@ -170,7 +170,7 @@ class StaticStringy
|
||||
* unless instructed otherwise.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public static function toAscii($str, $removeUnsupported = true)
|
||||
|
@@ -235,14 +235,14 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
public function camelize()
|
||||
{
|
||||
$encoding = $this->encoding;
|
||||
$stringy = static::create($this->str, $this->encoding);
|
||||
$stringy = $this->trim()->lowerCaseFirst();
|
||||
|
||||
$camelCase = preg_replace_callback(
|
||||
'/[-_\s]+(.)?/u',
|
||||
function ($match) use ($encoding) {
|
||||
return $match[1] ? mb_strtoupper($match[1], $encoding) : '';
|
||||
},
|
||||
$stringy->trim()->lowerCaseFirst()->str
|
||||
$stringy->str
|
||||
);
|
||||
|
||||
$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
|
||||
* 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
|
||||
*/
|
||||
public function toAscii($removeUnsupported = true)
|
||||
@@ -784,11 +784,11 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
*/
|
||||
public function slugify($replacement = '-')
|
||||
{
|
||||
$stringy = static::create($this->str, $this->encoding);
|
||||
$stringy = $this->toAscii();
|
||||
|
||||
$quotedReplacement = preg_quote($replacement);
|
||||
$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)
|
||||
->removeLeft($replacement)->removeRight($replacement);
|
||||
|
Reference in New Issue
Block a user