1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5
* An open source application development framework for PHP 5.1.6 or newer
8
* @author ExpressionEngine Dev Team
9
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
10
* @license http://codeigniter.com/user_guide/license.html
11
* @link http://codeigniter.com
16
// ------------------------------------------------------------------------
19
* CodeIgniter Inflector Helpers
21
* @package CodeIgniter
24
* @author ExpressionEngine Dev Team
25
* @link http://codeigniter.com/user_guide/helpers/directory_helper.html
29
// --------------------------------------------------------------------
34
* Takes a plural word and makes it singular
40
if ( ! function_exists('singular'))
42
function singular($str)
44
$result = strval($str);
46
$singular_rules = array(
47
'/(matr)ices$/' => '\1ix',
48
'/(vert|ind)ices$/' => '\1ex',
50
'/(alias)es$/' => '\1',
51
'/([octop|vir])i$/' => '\1us',
52
'/(cris|ax|test)es$/' => '\1is',
55
'/(bus|campus)es$/' => '\1',
56
'/([m|l])ice$/' => '\1ouse',
57
'/(x|ch|ss|sh)es$/' => '\1',
58
'/(m)ovies$/' => '\1\2ovie',
59
'/(s)eries$/' => '\1\2eries',
60
'/([^aeiouy]|qu)ies$/' => '\1y',
61
'/([lr])ves$/' => '\1f',
64
'/([^f])ves$/' => '\1fe',
65
'/(^analy)ses$/' => '\1sis',
66
'/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/' => '\1\2sis',
67
'/([ti])a$/' => '\1um',
68
'/(p)eople$/' => '\1\2erson',
70
'/(s)tatuses$/' => '\1\2tatus',
71
'/(c)hildren$/' => '\1\2hild',
72
'/(n)ews$/' => '\1\2ews',
76
foreach ($singular_rules as $rule => $replacement)
78
if (preg_match($rule, $result))
80
$result = preg_replace($rule, $replacement, $result);
89
// --------------------------------------------------------------------
94
* Takes a singular word and makes it plural
101
if ( ! function_exists('plural'))
103
function plural($str, $force = FALSE)
105
$result = strval($str);
107
$plural_rules = array(
108
'/^(ox)$/' => '\1\2en', // ox
109
'/([m|l])ouse$/' => '\1ice', // mouse, louse
110
'/(matr|vert|ind)ix|ex$/' => '\1ices', // matrix, vertex, index
111
'/(x|ch|ss|sh)$/' => '\1es', // search, switch, fix, box, process, address
112
'/([^aeiouy]|qu)y$/' => '\1ies', // query, ability, agency
113
'/(hive)$/' => '\1s', // archive, hive
114
'/(?:([^f])fe|([lr])f)$/' => '\1\2ves', // half, safe, wife
115
'/sis$/' => 'ses', // basis, diagnosis
116
'/([ti])um$/' => '\1a', // datum, medium
117
'/(p)erson$/' => '\1eople', // person, salesperson
118
'/(m)an$/' => '\1en', // man, woman, spokesman
119
'/(c)hild$/' => '\1hildren', // child
120
'/(buffal|tomat)o$/' => '\1\2oes', // buffalo, tomato
121
'/(bu|campu)s$/' => '\1\2ses', // bus, campus
122
'/(alias|status|virus)/' => '\1es', // alias
123
'/(octop)us$/' => '\1i', // octopus
124
'/(ax|cris|test)is$/' => '\1es', // axis, crisis
125
'/s$/' => 's', // no change (compatibility)
129
foreach ($plural_rules as $rule => $replacement)
131
if (preg_match($rule, $result))
133
$result = preg_replace($rule, $replacement, $result);
142
// --------------------------------------------------------------------
147
* Takes multiple words separated by spaces or underscores and camelizes them
153
if ( ! function_exists('camelize'))
155
function camelize($str)
157
$str = 'x'.strtolower(trim($str));
158
$str = ucwords(preg_replace('/[\s_]+/', ' ', $str));
159
return substr(str_replace(' ', '', $str), 1);
163
// --------------------------------------------------------------------
168
* Takes multiple words separated by spaces and underscores them
174
if ( ! function_exists('underscore'))
176
function underscore($str)
178
return preg_replace('/[\s]+/', '_', strtolower(trim($str)));
182
// --------------------------------------------------------------------
187
* Takes multiple words separated by underscores and changes them to spaces
193
if ( ! function_exists('humanize'))
195
function humanize($str)
197
return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str))));
202
/* End of file inflector_helper.php */
203
/* Location: ./system/helpers/inflector_helper.php */
b'\\ No newline at end of file'