summaryrefslogtreecommitdiffstats
path: root/system/helpers/inflector_helper.php
diff options
context:
space:
mode:
authorDerek Allard <derek.allard@ellislab.com>2007-07-11 21:35:09 +0200
committerDerek Allard <derek.allard@ellislab.com>2007-07-11 21:35:09 +0200
commitf5a519822db2201b98f822ad4f8659bad2ce9bcd (patch)
tree0f08cc25e63174b3b4bc8fe257e7e686d9605b23 /system/helpers/inflector_helper.php
parentc39a41f4615378b9b7b112a1b6cd37f358533493 (diff)
inflector helper changes to account for words ending in "s"
Diffstat (limited to 'system/helpers/inflector_helper.php')
-rw-r--r--system/helpers/inflector_helper.php78
1 files changed, 46 insertions, 32 deletions
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php
index fbe851f3b..28ecf5201 100644
--- a/system/helpers/inflector_helper.php
+++ b/system/helpers/inflector_helper.php
@@ -39,26 +39,31 @@
*/
function singular($str)
{
- $str = strtolower(trim($str));
- $end = substr($str, -3);
-
- if ($end == 'ies')
- {
- $str = substr($str, 0, strlen($str)-3).'y';
- }
- else
- {
- $end = substr($str, -1);
-
- if ($end == 's')
- {
- $str = substr($str, 0, strlen($str)-1);
- }
- }
-
- return $str;
+ $str = strtolower(trim($str));
+ $end = substr($str, -3);
+
+ if ($end == 'ies')
+ {
+ $str = substr($str, 0, strlen($str)-3).'y';
+ }
+ elseif ($end == 'ses')
+ {
+ $str = substr($str, 0, strlen($str)-2);
+ }
+ else
+ {
+ $end = substr($str, -1);
+
+ if ($end == 's')
+ {
+ $str = substr($str, 0, strlen($str)-1);
+ }
+ }
+
+ return $str;
}
+
// --------------------------------------------------------------------
/**
@@ -68,25 +73,34 @@ function singular($str)
*
* @access public
* @param string
+ * @param bool
* @return str
*/
-function plural($str)
+function plural($str, $force = FALSE)
{
- $str = strtolower(trim($str));
- $end = substr($str, -1);
-
- if ($end == 'y')
- {
- $str = substr($str, 0, strlen($str)-1).'ies';
- }
- elseif ($end != 's')
- {
- $str .= 's';
- }
-
- return $str;
+ $str = strtolower(trim($str));
+ $end = substr($str, -1);
+
+ if ($end == 'y')
+ {
+ $str = substr($str, 0, strlen($str)-1).'ies';
+ }
+ elseif ($end == 's')
+ {
+ if ($force == TRUE)
+ {
+ $str .= 'es';
+ }
+ }
+ else
+ {
+ $str .= 's';
+ }
+
+ return $str;
}
+
// --------------------------------------------------------------------
/**