Browse Source

fix functionality, keep each function to do what it supposed to do

tags/2.0.0-beta
Antonio Ramirez 12 years ago
parent
commit
e4e18710dc
  1. 3
      framework/yii/helpers/base/Inflector.php
  2. 2
      tests/unit/framework/helpers/InflectorTest.php

3
framework/yii/helpers/base/Inflector.php

@ -470,6 +470,7 @@ class Inflector
public static function slug($string, $replacement = '-') public static function slug($string, $replacement = '-')
{ {
$map = array( $map = array(
'/[^\w\s]/' => ' ',
'/\\s+/' => $replacement, '/\\s+/' => $replacement,
'/(?<=[a-z])([A-Z])/' => $replacement . '\\1', '/(?<=[a-z])([A-Z])/' => $replacement . '\\1',
str_replace(':rep', preg_quote($replacement, '/'), '/^[:rep]+|[:rep]+$/') => '' str_replace(':rep', preg_quote($replacement, '/'), '/^[:rep]+|[:rep]+$/') => ''
@ -512,7 +513,7 @@ class Inflector
*/ */
public static function ascii($string) public static function ascii($string)
{ {
$map = static::$transliteration + array('/[^\w\s]/' => ' '); $map = static::$transliteration;
return preg_replace(array_keys($map), array_values($map), $string); return preg_replace(array_keys($map), array_values($map), $string);
} }
} }

2
tests/unit/framework/helpers/InflectorTest.php

@ -143,8 +143,6 @@ class InflectorTest extends TestCase
Inflector::ascii("Perché l'erba è verde?", "'")); Inflector::ascii("Perché l'erba è verde?", "'"));
$this->assertEquals("Peux-tu m aider s il te plait", $this->assertEquals("Peux-tu m aider s il te plait",
Inflector::ascii("Peux-tu m'aider s'il te plaît?", "'")); Inflector::ascii("Peux-tu m'aider s'il te plaît?", "'"));
$this->assertEquals("Tank-efter-nu-forrn-vi-foser-dig-bort",
Inflector::slug(Inflector::ascii("Tänk efter nu – förr'n vi föser dig bort")));
$this->assertEquals("Custom delimiter example", $this->assertEquals("Custom delimiter example",
Inflector::ascii("Custom`delimiter*example", array('*', '`'))); Inflector::ascii("Custom`delimiter*example", array('*', '`')));
} }

Loading…
Cancel
Save