diff options
author | Phil Sturgeon <email@philsturgeon.co.uk> | 2012-01-06 23:03:39 +0100 |
---|---|---|
committer | Phil Sturgeon <email@philsturgeon.co.uk> | 2012-01-06 23:03:39 +0100 |
commit | cad20a23c067e3790ab050e71db34d290211a32e (patch) | |
tree | af5bf5545f8bac0cc6b2e832924cfa519bd048dc /system/helpers/inflector_helper.php | |
parent | 8f1de004f4e9f2ef2364d8b39734110d6192dfdb (diff) | |
parent | 1e6b72cca80354619cf7ddceb2b5f23d37b972e9 (diff) |
Merge pull request #872 from narfbg/develop-helpers-hil
Improve html, inflector & language helpers
Diffstat (limited to 'system/helpers/inflector_helper.php')
-rw-r--r-- | system/helpers/inflector_helper.php | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index f093dd921..0bd1e112f 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -1,4 +1,4 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * @@ -85,16 +85,7 @@ if ( ! function_exists('singular')) '/([^u])s$/' => '\1', ); - foreach ($singular_rules as $rule => $replacement) - { - if (preg_match($rule, $result)) - { - $result = preg_replace($rule, $replacement, $result); - break; - } - } - - return $result; + return preg_replace(array_keys($singular_values), $singular_values, $result); } } @@ -138,16 +129,7 @@ if ( ! function_exists('plural')) '/$/' => 's', ); - foreach ($plural_rules as $rule => $replacement) - { - if (preg_match($rule, $result)) - { - $result = preg_replace($rule, $replacement, $result); - break; - } - } - - return $result; + return preg_replace(array_keys($plural_rules), $plural_rules, $result); } } @@ -166,9 +148,7 @@ if ( ! function_exists('camelize')) { function camelize($str) { - $str = 'x'.strtolower(trim($str)); - $str = ucwords(preg_replace('/[\s_]+/', ' ', $str)); - return substr(str_replace(' ', '', $str), 1); + return substr(str_replace(' ', '', ucwords(preg_replace('/[\s_]+/', ' ', $str))), 1); } } @@ -212,4 +192,4 @@ if ( ! function_exists('humanize')) } /* End of file inflector_helper.php */ -/* Location: ./system/helpers/inflector_helper.php */
\ No newline at end of file +/* Location: ./system/helpers/inflector_helper.php */ |