Changeset 2972 for tags

Show
Ignore:
Timestamp:
07/06/2008 06:54:56 PM (5 months ago)
Author:
Shadowhand
Message:

Copied the inflector helper from trunk to tags/2.1.3.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • tags/2.1.3/system/helpers/inflector.php

    r2884 r2972  
    3636                } 
    3737 
    38                 return isset($uncountables[$str]); 
     38                return isset(self::$uncountable[strtolower($str)]); 
    3939        } 
    4040 
     
    6262 
    6363                // Cache key name 
    64                 $key = $str.$count; 
     64                $key = 'singular_'.$str.$count; 
    6565 
    6666                if (isset(self::$cache[$key])) 
     
    8080                        $str = $irregular; 
    8181                } 
    82                 elseif (substr($str, -3) === 'ies') 
    83                 { 
    84                         $str = substr($str, 0, strlen($str) - 3).'y'; 
    85                 } 
    86                 elseif (substr($str, -4) === 'sses' OR substr($str, -3) === 'xes') 
    87                 { 
    88                         $str = substr($str, 0, strlen($str) - 2); 
     82                elseif (preg_match('/[sxz]es$/i', $str) OR preg_match('/[^aeioudgkprt]hes$/i', $str)) 
     83                { 
     84                        // Remove "es" 
     85                        $str = substr($str, 0, -2); 
     86                } 
     87                elseif (preg_match('/[^aeiou]ies$/i', $str)) 
     88                { 
     89                        // Remove "ies" 
     90                        $str = substr($str, 0, -3).'y'; 
    8991                } 
    9092                elseif (substr($str, -1) === 's') 
    9193                { 
     94                        // Remove "s" 
    9295                        $str = substr($str, 0, strlen($str) - 1); 
    9396                } 
     
    118121 
    119122                // Cache key name 
    120                 $key = $str.$count; 
     123                $key = 'plural_'.$str.$count; 
    121124 
    122125                if (isset(self::$cache[$key])) 
     
    137140                if (isset(self::$irregular[strtolower($str)])) 
    138141                { 
    139                         $str = self::$irregular[$str]; 
    140  
    141                         if ($low === FALSE) 
    142                         { 
    143                                 // Make uppercase 
    144                                 $str = strtoupper($str); 
    145                         } 
     142                        $str = self::$irregular[strtolower($str)]; 
    146143                } 
    147144                elseif (preg_match('/[sxz]$/i', $str) OR preg_match('/[^aeioudgkprt]h$/i', $str)) 
     
    163160 
    164161                // Set the cache and return 
    165                 return $cache[$key] = $str; 
     162                return self::$cache[$key] = $str; 
    166163        } 
    167164