summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Sturgeon <email@philsturgeon.co.uk>2011-04-07 00:17:26 +0200
committerPhil Sturgeon <email@philsturgeon.co.uk>2011-04-07 00:17:26 +0200
commita3f1d6d9949d882b15a3b57466fed71428a4e27a (patch)
tree5f451a1da6382480247b16509be0fcbe5839f6bc
parenteda33d5ece128fcc11f6b46df38b3bfd76eb74ad (diff)
parent2f620fe804ae5b7f4f20adc70ceaee1cf616a655 (diff)
Changed the 'plural' function so that it doesn't ruin the captalization of your string. It also take into consideration acronyms which are all caps.
-rw-r--r--system/helpers/inflector_helper.php28
-rw-r--r--user_guide/changelog.html1
2 files changed, 16 insertions, 13 deletions
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php
index 4cd7486b4..c7c113b8a 100644
--- a/system/helpers/inflector_helper.php
+++ b/system/helpers/inflector_helper.php
@@ -41,20 +41,22 @@ if ( ! function_exists('singular'))
{
function singular($str)
{
- $str = strtolower(trim($str));
+ $str = trim($str);
$end = substr($str, -3);
-
- if ($end == 'ies')
+
+ $str = preg_replace('/(.*)?([s|c]h)es/i','$1$2',$str);
+
+ if (strtolower($end) == 'ies')
{
- $str = substr($str, 0, strlen($str)-3).'y';
+ $str = substr($str, 0, strlen($str)-3).(preg_match('/[a-z]/',$end) ? 'y' : 'Y');
}
- elseif ($end == 'ses')
+ elseif (strtolower($end) == 'ses')
{
$str = substr($str, 0, strlen($str)-2);
}
else
{
- $end = substr($str, -1);
+ $end = strtolower(substr($str, -1));
if ($end == 's')
{
@@ -81,19 +83,19 @@ if ( ! function_exists('singular'))
if ( ! function_exists('plural'))
{
function plural($str, $force = FALSE)
- {
- $str = strtolower(trim($str));
+ {
+ $str = trim($str);
$end = substr($str, -1);
- if ($end == 'y')
+ if (preg_match('/y/i',$end))
{
// Y preceded by vowel => regular plural
- $vowels = array('a', 'e', 'i', 'o', 'u');
+ $vowels = array('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U');
$str = in_array(substr($str, -2, 1), $vowels) ? $str.'s' : substr($str, 0, -1).'ies';
}
- elseif ($end == 'h')
+ elseif (preg_match('/h/i',$end))
{
- if (substr($str, -2) == 'ch' OR substr($str, -2) == 'sh')
+ if(preg_match('/^[c|s]h$/i',substr($str, -2)))
{
$str .= 'es';
}
@@ -102,7 +104,7 @@ if ( ! function_exists('plural'))
$str .= 's';
}
}
- elseif ($end == 's')
+ elseif (preg_match('/s/i',$end))
{
if ($force == TRUE)
{
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index ec6e76875..d34f5c8f0 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -78,6 +78,7 @@ Hg Tag: n/a</p>
<li>Helpers
<ul>
<li>Removed the previously deprecated <kbd>dohash()</kbd> from the <a href="./helpers/security_helper.html">Security helper</a>; use <kbd>do_hash()</kbd> instead.</li>
+ <li class="reactor">Changed the 'plural' function so that it doesn't ruin the captalization of your string. It also take into consideration acronyms which are all caps.</li>
</ul>
</li>
<li>Database