mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-12 08:14:06 +02:00
Remove leading or trailing replacement from slugified string, if present
This commit is contained in:
@@ -714,14 +714,12 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
|||||||
{
|
{
|
||||||
$stringy = self::create($this->str, $this->encoding);
|
$stringy = self::create($this->str, $this->encoding);
|
||||||
|
|
||||||
$stringy->str = preg_replace("/[^a-zA-Z\d\s-" . preg_quote($replacement) . "]/u", '',
|
$quotedReplacement = preg_quote($replacement);
|
||||||
$stringy->toAscii());
|
$pattern = "/[^a-zA-Z\d\s-_$quotedReplacement]/u";
|
||||||
|
$stringy->str = preg_replace($pattern, '', $stringy->toAscii());
|
||||||
|
|
||||||
$stringy->str = $stringy->collapseWhitespace()->str;
|
return $stringy->toLowerCase()->applyDelimeter($replacement)
|
||||||
$stringy->str = preg_replace('/[-\s]/u', $replacement, strtolower($stringy));
|
->removeLeft($replacement)->removeRight($replacement);
|
||||||
$stringy->str = preg_replace("/[" . preg_quote($replacement) . "]+/u", $replacement, $stringy);
|
|
||||||
|
|
||||||
return $stringy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -341,13 +341,12 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
|||||||
array('numbers-1234', 'numbers 1234'),
|
array('numbers-1234', 'numbers 1234'),
|
||||||
array('perevirka-ryadka', 'перевірка рядка'),
|
array('perevirka-ryadka', 'перевірка рядка'),
|
||||||
array('bukvar-s-bukvoy-y', 'букварь с буквой ы'),
|
array('bukvar-s-bukvoy-y', 'букварь с буквой ы'),
|
||||||
// Conflicts between Russian or Bulgarian
|
|
||||||
//array('barzi-i-yarostni', 'бързи и яростни'),
|
|
||||||
array('podekhal-k-podezdu-moego-doma', 'подъехал к подъезду моего дома'),
|
array('podekhal-k-podezdu-moego-doma', 'подъехал к подъезду моего дома'),
|
||||||
array('foo:bar:baz', 'Foo bar baz', ':'),
|
array('foo:bar:baz', 'Foo bar baz', ':'),
|
||||||
array('a_string_with_underscores', 'A_string with_underscores', '_'),
|
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('a\string\with\dashes', 'A string-with-dashes', '\\'),
|
||||||
|
array('an_odd_string', '-- An odd__ string-_', '_')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user