summaryrefslogtreecommitdiffstats
path: root/system/helpers/inflector_helper.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/helpers/inflector_helper.php')
-rw-r--r--system/helpers/inflector_helper.php53
1 files changed, 35 insertions, 18 deletions
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php
index 3393bda8f..9cf015d2b 100644
--- a/system/helpers/inflector_helper.php
+++ b/system/helpers/inflector_helper.php
@@ -1,8 +1,8 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -18,15 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Inflector Helpers
*
@@ -34,10 +32,9 @@
* @subpackage Helpers
* @category Helpers
* @author EllisLab Dev Team
- * @link http://codeigniter.com/user_guide/helpers/directory_helper.html
+ * @link http://codeigniter.com/user_guide/helpers/inflector_helper.html
*/
-
// --------------------------------------------------------------------
/**
@@ -45,7 +42,6 @@
*
* Takes a plural word and makes it singular
*
- * @access public
* @param string
* @return str
*/
@@ -55,6 +51,11 @@ if ( ! function_exists('singular'))
{
$result = strval($str);
+ if ( ! is_countable($result))
+ {
+ return $result;
+ }
+
$singular_rules = array(
'/(matr)ices$/' => '\1ix',
'/(vert|ind)ices$/' => '\1ex',
@@ -82,7 +83,7 @@ if ( ! function_exists('singular'))
'/(s)tatuses$/' => '\1\2tatus',
'/(c)hildren$/' => '\1\2hild',
'/(n)ews$/' => '\1\2ews',
- '/([^u])s$/' => '\1',
+ '/([^us])s$/' => '\1',
);
foreach ($singular_rules as $rule => $replacement)
@@ -105,7 +106,6 @@ if ( ! function_exists('singular'))
*
* Takes a singular word and makes it plural
*
- * @access public
* @param string
* @param bool
* @return str
@@ -116,6 +116,11 @@ if ( ! function_exists('plural'))
{
$result = strval($str);
+ if ( ! is_countable($result))
+ {
+ return $result;
+ }
+
$plural_rules = array(
'/^(ox)$/' => '\1\2en', // ox
'/([m|l])ouse$/' => '\1ice', // mouse, louse
@@ -131,7 +136,7 @@ if ( ! function_exists('plural'))
'/(c)hild$/' => '\1hildren', // child
'/(buffal|tomat)o$/' => '\1\2oes', // buffalo, tomato
'/(bu|campu)s$/' => '\1\2ses', // bus, campus
- '/(alias|status|virus)/' => '\1es', // alias
+ '/(alias|status|virus)$/' => '\1es', // alias
'/(octop)us$/' => '\1i', // octopus
'/(ax|cris|test)is$/' => '\1es', // axis, crisis
'/s$/' => 's', // no change (compatibility)
@@ -158,7 +163,6 @@ if ( ! function_exists('plural'))
*
* Takes multiple words separated by spaces or underscores and camelizes them
*
- * @access public
* @param string
* @return str
*/
@@ -166,9 +170,7 @@ if ( ! function_exists('camelize'))
{
function camelize($str)
{
- $str = 'x'.strtolower(trim($str));
- $str = ucwords(preg_replace('/[\s_]+/', ' ', $str));
- return substr(str_replace(' ', '', $str), 1);
+ return str_replace(' ', '', ucwords(preg_replace('/[\s_]+/', ' ', strtolower($str))));
}
}
@@ -179,7 +181,6 @@ if ( ! function_exists('camelize'))
*
* Takes multiple words separated by spaces and underscores them
*
- * @access public
* @param string
* @return str
*/
@@ -198,7 +199,6 @@ if ( ! function_exists('underscore'))
*
* Takes multiple words separated by the separator and changes them to spaces
*
- * @access public
* @param string $str
* @param string $separator
* @return str
@@ -211,5 +211,22 @@ if ( ! function_exists('humanize'))
}
}
+/**
+ * Checks if the given word has a plural version.
+ *
+ * @param string the word to check
+ * @return bool if the word is countable
+ */
+if ( ! function_exists('is_countable'))
+{
+ function is_countable($word)
+ {
+ return ! (in_array(strtolower(strval($word)), array(
+ 'equipment', 'information', 'rice', 'money',
+ 'species', 'series', 'fish', 'meta'
+ )));
+ }
+}
+
/* End of file inflector_helper.php */
-/* Location: ./system/helpers/inflector_helper.php */ \ No newline at end of file
+/* Location: ./system/helpers/inflector_helper.php */