diff --git a/src/Stringy.php b/src/Stringy.php index b215c32..9c379f6 100644 --- a/src/Stringy.php +++ b/src/Stringy.php @@ -714,14 +714,12 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess { $stringy = self::create($this->str, $this->encoding); - $stringy->str = preg_replace("/[^a-zA-Z\d\s-" . preg_quote($replacement) . "]/u", '', - $stringy->toAscii()); + $quotedReplacement = preg_quote($replacement); + $pattern = "/[^a-zA-Z\d\s-_$quotedReplacement]/u"; + $stringy->str = preg_replace($pattern, '', $stringy->toAscii()); - $stringy->str = $stringy->collapseWhitespace()->str; - $stringy->str = preg_replace('/[-\s]/u', $replacement, strtolower($stringy)); - $stringy->str = preg_replace("/[" . preg_quote($replacement) . "]+/u", $replacement, $stringy); - - return $stringy; + return $stringy->toLowerCase()->applyDelimeter($replacement) + ->removeLeft($replacement)->removeRight($replacement); } /** diff --git a/tests/CommonTest.php b/tests/CommonTest.php index bb223e2..e30b293 100644 --- a/tests/CommonTest.php +++ b/tests/CommonTest.php @@ -341,13 +341,12 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase array('numbers-1234', 'numbers 1234'), array('perevirka-ryadka', 'перевірка рядка'), array('bukvar-s-bukvoy-y', 'букварь с буквой ы'), - // Conflicts between Russian or Bulgarian - //array('barzi-i-yarostni', 'бързи и яростни'), array('podekhal-k-podezdu-moego-doma', 'подъехал к подъезду моего дома'), array('foo:bar:baz', 'Foo bar baz', ':'), array('a_string_with_underscores', 'A_string with_underscores', '_'), array('a_string_with_dashes', 'A string-with-dashes', '_'), - array('a\string\with\dashes', 'A string-with-dashes', '\\') + array('a\string\with\dashes', 'A string-with-dashes', '\\'), + array('an_odd_string', '-- An odd__ string-_', '_') ); }