Changeset 63
- Timestamp:
- 05/22/2007 02:22:50 PM (19 months ago)
- Files:
-
- 1 modified
-
trunk/system/helpers/inflector_helper.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/helpers/inflector_helper.php
r24 r63 37 37 * @param string 38 38 * @return str 39 */ 39 */ 40 40 function singular($str) 41 41 { 42 $str = strtolower(trim($str));42 $str = trim(rtrim($str)); 43 43 $end = substr($str, -3); 44 44 45 45 if ($end == 'ies') 46 46 { 47 47 $str = substr($str, 0, strlen($str)-3).'y'; 48 48 } 49 elseif ($end == 'ses' || $end == 'zes' || $end == 'xes') 50 { 51 $str = substr($str, 0, strlen($str)-2); 52 } 49 53 else 50 54 { 51 55 $end = substr($str, -1); 52 56 53 57 if ($end == 's') 54 58 { … … 56 60 } 57 61 } 58 62 59 63 return $str; 60 64 } … … 70 74 * @param string 71 75 * @return str 72 */ 76 */ 73 77 function plural($str) 74 78 { 75 $str = strtolower(trim($str));79 $str = trim(rtrim($str)); 76 80 $end = substr($str, -1); 81 $low = (strcmp($end, strtolower($end)) === 0) ? TRUE : FALSE; 77 82 78 if ( $end == 'y')83 if (preg_match('/[sxz]$/i', $str) OR preg_match('/[^aeioudgkprt]h$/i', $str)) 79 84 { 80 $str = substr($str, 0, strlen($str)-1).'ies'; 85 $end = 'es'; 86 $str .= ($low == FALSE) ? strtoupper($end) : $end; 81 87 } 82 elseif ( $end != 's')88 elseif (preg_match('/[^aeiou]y$/i', $str)) 83 89 { 84 $str .= 's'; 90 $end = 'ies'; 91 $end = ($low == FALSE) ? strtoupper($end) : $end; 92 $str = substr_replace($str, $end, -1) 93 } 94 else 95 { 96 $end = 's'; 97 $str .= ($low == FALSE) ? strtoupper($end) : $end; 85 98 } 86 99 87 return $str; 100 return $str; 88 101 } 89 102 … … 98 111 * @param string 99 112 * @return str 100 */ 113 */ 101 114 function camelize($str) 102 { 115 { 103 116 $str = 'x'.strtolower(trim($str)); 104 117 $str = ucwords(preg_replace('/[\s_]+/', ' ', $str)); … … 116 129 * @param string 117 130 * @return str 118 */ 131 */ 119 132 function underscore($str) 120 133 { … … 132 145 * @param string 133 146 * @return str 134 */ 147 */ 135 148 function humanize($str) 136 149 { 137 150 return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str)))); 138 151 } 139 152 140 153 ?>
