Skip to content

Commit

Permalink
Updated Inflector's 'pluralize and singularize to correctly handle ad…
Browse files Browse the repository at this point in the history
…disional words.

Updated InflectorTest to test new words.
  • Loading branch information
wernerhp committed Jul 10, 2013
1 parent 9383236 commit a27499d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 13 additions & 0 deletions lib/Cake/Test/Case/Utility/InflectorTest.php
Expand Up @@ -109,6 +109,11 @@ public function testInflectingSingulars() {
$this->assertEquals(Inflector::singularize('foes'), 'foe');
$this->assertEquals(Inflector::singularize('databases'), 'database');
$this->assertEquals(Inflector::singularize('cookies'), 'cookie');
$this->assertEquals(Inflector::singularize('thieves'), 'thief');
$this->assertEquals(Inflector::singularize('potatoes'), 'potato');
$this->assertEquals(Inflector::singularize('heroes'), 'hero');
$this->assertEquals(Inflector::singularize('buffalos'), 'buffalo');
$this->assertEquals(Inflector::singularize('babies'), 'baby');

$this->assertEquals(Inflector::singularize(''), '');
}
Expand Down Expand Up @@ -161,6 +166,14 @@ public function testInflectingPlurals() {
$this->assertEquals(Inflector::pluralize('roof'), 'roofs');
$this->assertEquals(Inflector::pluralize('foe'), 'foes');
$this->assertEquals(Inflector::pluralize('cookie'), 'cookies');
$this->assertEquals(Inflector::pluralize('wolf'), 'wolves');
$this->assertEquals(Inflector::pluralize('thief'), 'thieves');
$this->assertEquals(Inflector::pluralize('potato'), 'potatoes');
$this->assertEquals(Inflector::pluralize('hero'), 'heroes');
$this->assertEquals(Inflector::pluralize('buffalo'), 'buffalo');
$this->assertEquals(Inflector::pluralize('tooth'), 'teeth');
$this->assertEquals(Inflector::pluralize('goose'), 'geese');
$this->assertEquals(Inflector::pluralize('foot'), 'feet');
$this->assertEquals(Inflector::pluralize(''), '');
}

Expand Down
13 changes: 9 additions & 4 deletions lib/Cake/Utility/Inflector.php
Expand Up @@ -40,7 +40,7 @@ class Inflector {
'/(x|ch|ss|sh)$/i' => '\1es',
'/([^aeiouy]|qu)y$/i' => '\1ies',
'/(hive)$/i' => '\1s',
'/(?:([^f])fe|([lr])f)$/i' => '\1\2ves',
'/(?:([^f])fe|([lre])f)$/i' => '\1\2ves',
'/sis$/i' => 'ses',
'/([ti])um$/i' => '\1a',
'/(p)erson$/i' => '\1eople',
Expand Down Expand Up @@ -90,7 +90,12 @@ class Inflector {
'soliloquy' => 'soliloquies',
'testis' => 'testes',
'trilby' => 'trilbys',
'turf' => 'turfs'
'turf' => 'turfs',
'potato' => 'potatoes',
'hero' => 'heroes',
'tooth' => 'teeth',
'goose' => 'geese',
'foot' => 'feet'
)
);

Expand Down Expand Up @@ -120,11 +125,11 @@ class Inflector {
'/(m)ovies$/i' => '\1\2ovie',
'/(s)eries$/i' => '\1\2eries',
'/([^aeiouy]|qu)ies$/i' => '\1y',
'/([lr])ves$/i' => '\1f',
'/([lre])ves$/i' => '\1f',
'/([^fo])ves$/i' => '\1fe',
'/(tive)s$/i' => '\1',
'/(hive)s$/i' => '\1',
'/(drive)s$/i' => '\1',
'/([^fo])ves$/i' => '\1fe',
'/(^analy)ses$/i' => '\1sis',
'/(analy|diagno|^ba|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
'/([ti])a$/i' => '\1um',
Expand Down

0 comments on commit a27499d

Please sign in to comment.