Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
| 2 | /**
|
| 3 | * CodeIgniter
|
| 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 8 | * @author ExpressionEngine Dev Team
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html
|
| 11 | * @link http://codeigniter.com
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 12 | * @since Version 1.0
|
| 13 | * @filesource
|
| 14 | */
|
| 15 |
|
| 16 | // ------------------------------------------------------------------------
|
| 17 |
|
| 18 | /**
|
| 19 | * CodeIgniter Inflector Helpers
|
| 20 | *
|
| 21 | * @package CodeIgniter
|
| 22 | * @subpackage Helpers
|
| 23 | * @category Helpers
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 24 | * @author ExpressionEngine Dev Team
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 25 | * @link http://codeigniter.com/user_guide/helpers/directory_helper.html
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 26 | */
|
| 27 |
|
| 28 |
|
| 29 | // --------------------------------------------------------------------
|
| 30 |
|
| 31 | /**
|
| 32 | * Singular
|
| 33 | *
|
Derek Jones | eea2bda | 2007-07-11 22:09:45 +0000 | [diff] [blame] | 34 | * Takes a plural word and makes it singular
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 35 | *
|
| 36 | * @access public
|
| 37 | * @param string
|
| 38 | * @return str
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 39 | */
|
| 40 | if (! function_exists('singular'))
|
| 41 | {
|
| 42 | function singular($str)
|
| 43 | {
|
| 44 | $str = strtolower(trim($str));
|
| 45 | $end = substr($str, -3);
|
Derek Allard | f5a5198 | 2007-07-11 19:35:09 +0000 | [diff] [blame] | 46 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 47 | if ($end == 'ies')
|
| 48 | {
|
| 49 | $str = substr($str, 0, strlen($str)-3).'y';
|
| 50 | }
|
| 51 | elseif ($end == 'ses')
|
| 52 | {
|
| 53 | $str = substr($str, 0, strlen($str)-2);
|
| 54 | }
|
| 55 | else
|
| 56 | {
|
| 57 | $end = substr($str, -1);
|
Derek Allard | f5a5198 | 2007-07-11 19:35:09 +0000 | [diff] [blame] | 58 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 59 | if ($end == 's')
|
| 60 | {
|
| 61 | $str = substr($str, 0, strlen($str)-1);
|
| 62 | }
|
| 63 | }
|
Derek Allard | f5a5198 | 2007-07-11 19:35:09 +0000 | [diff] [blame] | 64 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 65 | return $str;
|
| 66 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 67 | }
|
| 68 |
|
| 69 | // --------------------------------------------------------------------
|
| 70 |
|
| 71 | /**
|
| 72 | * Plural
|
| 73 | *
|
Derek Jones | eea2bda | 2007-07-11 22:09:45 +0000 | [diff] [blame] | 74 | * Takes a singular word and makes it plural
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 75 | *
|
| 76 | * @access public
|
| 77 | * @param string
|
Derek Allard | f5a5198 | 2007-07-11 19:35:09 +0000 | [diff] [blame] | 78 | * @param bool
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 79 | * @return str
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 80 | */
|
| 81 | if (! function_exists('plural'))
|
| 82 | {
|
| 83 | function plural($str, $force = FALSE)
|
| 84 | {
|
| 85 | $str = strtolower(trim($str));
|
| 86 | $end = substr($str, -1);
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 87 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 88 | if ($end == 'y')
|
| 89 | {
|
| 90 | $str = substr($str, 0, strlen($str)-1).'ies';
|
| 91 | }
|
| 92 | elseif ($end == 's')
|
| 93 | {
|
| 94 | if ($force == TRUE)
|
| 95 | {
|
| 96 | $str .= 'es';
|
| 97 | }
|
| 98 | }
|
| 99 | else
|
| 100 | {
|
| 101 | $str .= 's';
|
| 102 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 103 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 104 | return $str;
|
| 105 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 106 | }
|
| 107 |
|
| 108 | // --------------------------------------------------------------------
|
| 109 |
|
| 110 | /**
|
| 111 | * Camelize
|
| 112 | *
|
| 113 | * Takes multiple words separated by spaces or underscores and camelizes them
|
| 114 | *
|
| 115 | * @access public
|
| 116 | * @param string
|
| 117 | * @return str
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 118 | */
|
| 119 | if (! function_exists('camelize'))
|
| 120 | {
|
| 121 | function camelize($str)
|
| 122 | {
|
| 123 | $str = 'x'.strtolower(trim($str));
|
| 124 | $str = ucwords(preg_replace('/[\s_]+/', ' ', $str));
|
| 125 | return substr(str_replace(' ', '', $str), 1);
|
| 126 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 127 | }
|
| 128 |
|
| 129 | // --------------------------------------------------------------------
|
| 130 |
|
| 131 | /**
|
| 132 | * Underscore
|
| 133 | *
|
| 134 | * Takes multiple words separated by spaces and underscores them
|
| 135 | *
|
| 136 | * @access public
|
| 137 | * @param string
|
| 138 | * @return str
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 139 | */
|
| 140 | if (! function_exists('underscore'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 141 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 142 | function underscore($str)
|
| 143 | {
|
| 144 | return preg_replace('/[\s]+/', '_', strtolower(trim($str)));
|
| 145 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 146 | }
|
| 147 |
|
| 148 | // --------------------------------------------------------------------
|
| 149 |
|
| 150 | /**
|
| 151 | * Humanize
|
| 152 | *
|
| 153 | * Takes multiple words separated by underscores and changes them to spaces
|
| 154 | *
|
| 155 | * @access public
|
| 156 | * @param string
|
| 157 | * @return str
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 158 | */
|
| 159 | if (! function_exists('humanize'))
|
| 160 | {
|
| 161 | function humanize($str)
|
| 162 | {
|
| 163 | return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str))));
|
| 164 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 165 | }
|
| 166 |
|
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame^] | 167 | |
| 168 | /* End of file inflector_helper.php */ |
| 169 | /* Location: ./system/helpers/inflector_helper.php */ |