mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 02:26:17 +00:00
Improved Inflector::slug, closes #4678
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6920 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
8313fef72d
commit
550b85fdbb
2 changed files with 13 additions and 0 deletions
|
@ -438,6 +438,7 @@ class Inflector extends Object {
|
||||||
'/ß/' => 'ss',
|
'/ß/' => 'ss',
|
||||||
'/[^\w\s]/' => ' ',
|
'/[^\w\s]/' => ' ',
|
||||||
'/\\s+/' => $replacement,
|
'/\\s+/' => $replacement,
|
||||||
|
String::insert('/^[:replacement]+|[:replacement]+$/', array('replacement' => preg_quote($replacement, '/'))) => '',
|
||||||
);
|
);
|
||||||
$string = preg_replace(array_keys($map), array_values($map), $string);
|
$string = preg_replace(array_keys($map), array_values($map), $string);
|
||||||
return $string;
|
return $string;
|
||||||
|
|
|
@ -147,6 +147,18 @@ class InflectorTest extends UnitTestCase {
|
||||||
$result = Inflector::slug('La langue française est un attribut de souveraineté en France', '-');
|
$result = Inflector::slug('La langue française est un attribut de souveraineté en France', '-');
|
||||||
$expected = 'La-langue-francaise-est-un-attribut-de-souverainete-en-France';
|
$expected = 'La-langue-francaise-est-un-attribut-de-souverainete-en-France';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$result = Inflector::slug('!@$#exciting stuff! - what !@-# was that?', '-');
|
||||||
|
$expected = 'exciting-stuff-what-was-that';
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$result = Inflector::slug('20% of profits went to me!', '-');
|
||||||
|
$expected = '20-of-profits-went-to-me';
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$result = Inflector::slug('#this melts your face1#2#3', '-');
|
||||||
|
$expected = 'this-melts-your-face1-2-3';
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testVariableNaming() {
|
function testVariableNaming() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue