laravel/laravel — pull request #1238 by matthew-muscat (2012-09-18 07:51:50+00:00)
Title: Added custom macros to Str Class

Added the ability to use custom macros for the Str Class

for example... can be used to add possessive form to a string

/*
|--------------------------------------------------------------------------
| Load the possessive string macro
|--------------------------------------------------------------------------
|
| Get the possessive form of the given word.
|
|
|	// Returns the possessive form of "John"
|	$plural = Str::possessive('John', 10);
|
|
| @param string $value
| @return string
|
*/
Str::macro('possessive', function($value)
{
// append an apostrophe to indicate possession
$value .= '\'';

// append an s for all strings that do not end with the letter s
if($value[strlen($value)-2] != 's')
$value .= 's';

return $value;
});