CodeIgniter Forums
Inflector bug fix in singular() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Inflector bug fix in singular() (/thread-23301.html)



Inflector bug fix in singular() - El Forum - 10-06-2009

[eluser]Unknown[/eluser]
Currently, singular() results in the following:

horses -> hors
bases -> bas

I recommend the following code change in the singular() function:

Code:
$last3 = substr($str, -3);
$last4 = substr($str, -4);

if ($last3 == 'ies')
{
...
}
elseif ($last4 == 'sses')
{
...
}

Those few line changes fix the singular() function.


Inflector bug fix in singular() - El Forum - 10-06-2009

[eluser]sophistry[/eluser]
welcome to CI CaptSaltyJack -

it's always good to come out of the gate with a bug fix! nicely done.

but...

squashing inflector bugs is like stepping on roaches... if you see one, that just means that there are 500 more in the wall and the one you saw got claustrophobia.

i suggest that you look at these threads (one has a wiki page: "inflector" - the regex he uses there is a work of art, it's really worth a peek):

http://ellislab.com/forums/viewthread/97116/
http://ellislab.com/forums/viewthread/100997/
http://ellislab.com/forums/viewthread/99938/

cheers.


Inflector bug fix in singular() - El Forum - 10-06-2009

[eluser]Unknown[/eluser]
Ahh I see I'm not the first to notice this Smile I'll defer to the more comprehensive solutions. Thanks!