Subversion-Projekte lars-tiefland.codeigniter

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 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
8
 * @author		ExpressionEngine Dev Team
9
 * @copyright	Copyright (c) 2008, EllisLab, Inc.
10
 * @license		http://codeigniter.com/user_guide/license.html
11
 * @link		http://codeigniter.com
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
24
 * @author		ExpressionEngine Dev Team
25
 * @link		http://codeigniter.com/user_guide/helpers/directory_helper.html
26
 */
27
 
28
 
29
// --------------------------------------------------------------------
30
 
31
/**
32
 * Singular
33
 *
34
 * Takes a plural word and makes it singular
35
 *
36
 * @access	public
37
 * @param	string
38
 * @return	str
39
 */
40
if ( ! function_exists('singular'))
41
{
42
	function singular($str)
43
	{
44
		$str = strtolower(trim($str));
45
		$end = substr($str, -3);
46
 
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);
58
 
59
			if ($end == 's')
60
			{
61
				$str = substr($str, 0, strlen($str)-1);
62
			}
63
		}
64
 
65
		return $str;
66
	}
67
}
68
 
69
// --------------------------------------------------------------------
70
 
71
/**
72
 * Plural
73
 *
74
 * Takes a singular word and makes it plural
75
 *
76
 * @access	public
77
 * @param	string
78
 * @param	bool
79
 * @return	str
80
 */
81
if ( ! function_exists('plural'))
82
{
83
	function plural($str, $force = FALSE)
84
	{
85
		$str = strtolower(trim($str));
86
		$end = substr($str, -1);
87
 
88
		if ($end == 'y')
89
		{
90
			// Y preceded by vowel => regular plural
91
			$vowels = array('a', 'e', 'i', 'o', 'u');
92
			$str = in_array(substr($str, -2, 1), $vowels) ? $str.'s' : substr($str, 0, -1).'ies';
93
		}
94
		elseif ($end == 's')
95
		{
96
			if ($force == TRUE)
97
			{
98
				$str .= 'es';
99
			}
100
		}
101
		else
102
		{
103
			$str .= 's';
104
		}
105
 
106
		return $str;
107
	}
108
}
109
 
110
// --------------------------------------------------------------------
111
 
112
/**
113
 * Camelize
114
 *
115
 * Takes multiple words separated by spaces or underscores and camelizes them
116
 *
117
 * @access	public
118
 * @param	string
119
 * @return	str
120
 */
121
if ( ! function_exists('camelize'))
122
{
123
	function camelize($str)
124
	{
125
		$str = 'x'.strtolower(trim($str));
126
		$str = ucwords(preg_replace('/[\s_]+/', ' ', $str));
127
		return substr(str_replace(' ', '', $str), 1);
128
	}
129
}
130
 
131
// --------------------------------------------------------------------
132
 
133
/**
134
 * Underscore
135
 *
136
 * Takes multiple words separated by spaces and underscores them
137
 *
138
 * @access	public
139
 * @param	string
140
 * @return	str
141
 */
142
if ( ! function_exists('underscore'))
143
{
144
	function underscore($str)
145
	{
146
		return preg_replace('/[\s]+/', '_', strtolower(trim($str)));
147
	}
148
}
149
 
150
// --------------------------------------------------------------------
151
 
152
/**
153
 * Humanize
154
 *
155
 * Takes multiple words separated by underscores and changes them to spaces
156
 *
157
 * @access	public
158
 * @param	string
159
 * @return	str
160
 */
161
if ( ! function_exists('humanize'))
162
{
163
	function humanize($str)
164
	{
165
		return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str))));
166
	}
167
}
168
 
169
 
170
/* End of file inflector_helper.php */
171
/* Location: ./system/helpers/inflector_helper.php */