示例#1
0
 /**
  * Checks if a word is defined as uncountable.
  *
  * @param string $str word to check
  * @return boolean
  */
 public static function uncountable($str)
 {
     if (self::$uncountable === NULL) {
         // Cache uncountables
         self::$uncountable = AetherDatabaseConfig::retrieve('inflector.uncountable');
         // Make uncountables mirroed
         self::$uncountable = array_combine(self::$uncountable, self::$uncountable);
     }
     return isset(self::$uncountable[strtolower($str)]);
 }
示例#2
0
 /**
  * Makes a singular word plural.
  *
  *     echo Inflector::plural('fish'); // "fish", uncountable
  *     echo Inflector::plural('cat');  // "cats"
  *
  * You can also provide the count to make inflection more intelligent.
  * In this case, it will only return the plural value if the count is
  * not one.
  *
  *     echo Inflector::singular('cats', 3); // "cats"
  *
  * [!!] Special inflections are defined in `config/inflector.php`.
  *
  * @param   string  $str   word to pluralize
  * @param   integer $count count of thing
  *
  * @return  string
  * @uses    Inflector::uncountable
  */
 public static function plural($str, $count = null)
 {
     // $count should always be a float
     $count = $count === null ? 0.0 : (double) $count;
     // Do nothing with singular
     if ($count == 1) {
         return $str;
     }
     // Remove garbage
     $str = trim($str);
     // Cache key name
     $key = 'plural_' . $str . $count;
     // Check uppercase
     $is_uppercase = ctype_upper($str);
     if (isset(Inflector::$cache[$key])) {
         return Inflector::$cache[$key];
     }
     if (Inflector::uncountable($str)) {
         return Inflector::$cache[$key] = $str;
     }
     if (empty(Inflector::$irregular)) {
         // Cache irregular words
         Inflector::$irregular = Kohana::$config->load('inflector')->irregular;
     }
     if (isset(Inflector::$irregular[$str])) {
         $str = Inflector::$irregular[$str];
     } elseif (in_array($str, Inflector::$irregular)) {
         // Do nothing
     } elseif (preg_match('/[sxz]$/', $str) or preg_match('/[^aeioudgkprt]h$/', $str)) {
         $str .= 'es';
     } elseif (preg_match('/[^aeiou]y$/', $str)) {
         // Change "y" to "ies"
         $str = substr_replace($str, 'ies', -1);
     } else {
         $str .= 's';
     }
     // Convert to uppercase if necessary
     if ($is_uppercase) {
         $str = strtoupper($str);
     }
     // Set the cache and return
     return Inflector::$cache[$key] = $str;
 }
示例#3
0
 /**
  * Makes a singular word plural.
  *
  *     echo Inflector::plural('fish'); // "fish", uncountable
  *     echo Inflector::plural('cat');  // "cats"
  *
  * You can also provide the count to make inflection more intelligent.
  * In this case, it will only return the plural value if the count is
  * not one.
  *
  *     echo Inflector::singular('cats', 3); // "cats"
  *
  * [!!] Special inflections are defined in `config/inflector.php`.
  *
  * @param   string  word to pluralize
  * @return  string
  * @uses    Inflector::uncountable
  */
 public static function plural($str, $count = NULL)
 {
     // Remove garbage
     $str = strtolower(trim($str));
     if (is_string($count)) {
         // Convert to integer when using a digit string
         $count = (int) $count;
     }
     // Do nothing with singular
     if ($count === 1) {
         return $str;
     }
     // Cache key name
     $key = 'plural_' . $str . $count;
     if (isset(Inflector::$cache[$key])) {
         return Inflector::$cache[$key];
     }
     if (Inflector::uncountable($str)) {
         return Inflector::$cache[$key] = $str;
     }
     if (empty(Inflector::$irregular)) {
         // Cache irregular words
         Inflector::$irregular = Kohana::config('inflector')->irregular;
     }
     if (isset(Inflector::$irregular[$str])) {
         $str = Inflector::$irregular[$str];
     } elseif (preg_match('/[sxz]$/', $str) or preg_match('/[^aeioudgkprt]h$/', $str)) {
         $str .= 'es';
     } elseif (preg_match('/[^aeiou]y$/', $str)) {
         // Change "y" to "ies"
         $str = substr_replace($str, 'ies', -1);
     } else {
         $str .= 's';
     }
     // Set the cache and return
     return Inflector::$cache[$key] = $str;
 }
 /**
  * Tests Inflector::uncountable
  *
  * @test
  * @dataProvider provider_uncountable
  * @param boolean $input  Input for File::mime
  * @param boolean $expected Output for File::mime
  */
 public function test_uncountable($input, $expected)
 {
     $this->assertSame($expected, Inflector::uncountable($input));
 }
示例#5
0
Inflector::singular('/([octop|vir])i$/i', '\\1us');
Inflector::singular('/(alias|status)es$/i', '\\1');
Inflector::singular('/^(ox)en/i', '\\1');
Inflector::singular('/(vert|ind)ices$/i', '\\1ex');
Inflector::singular('/(matr)ices$/i', '\\1ix');
Inflector::singular('/(quiz)zes$/i', '\\1');
Inflector::plural('/$/', 's');
Inflector::plural('/s$/i', 's');
Inflector::plural('/(ax|test)is$/i', '\\1es');
Inflector::plural('/(octop|vir)us$/i', '\\1i');
Inflector::plural('/(alias|status)$/i', '\\1es');
Inflector::plural('/(bu)s$/i', '\\1ses');
Inflector::plural('/(buffal|tomat)o$/i', '\\1oes');
Inflector::plural('/([ti])um$/i', '\\1a');
Inflector::plural('/sis$/i', 'ses');
Inflector::plural('/(?:([^f])fe|([lr])f)$/i', '\\1\\2ves');
Inflector::plural('/(hive)$/i', '\\1s');
Inflector::plural('/([^aeiouy]|qu)y$/i', '\\1ies');
Inflector::plural('/([^aeiouy]|qu)ies$/i', '\\1y');
Inflector::plural('/(x|ch|ss|sh)$/i', '\\1es');
Inflector::plural('/(matr|vert|ind)ix|ex$/i', '\\1ices');
Inflector::plural('/([m|l])ouse$/i', '\\1ice');
Inflector::plural('/^(ox)$/i', '\\1en');
Inflector::plural('/(quiz)$/i', '\\1zes');
Inflector::irregular('person', 'people');
Inflector::irregular('man', 'men');
Inflector::irregular('child', 'children');
Inflector::irregular('sex', 'sexes');
Inflector::irregular('move', 'moves');
Inflector::uncountable(array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'deer', 'elk', 'cattle'));
Inflector::singular('/([ti])a$/i', '\\1um');
Inflector::singular('/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i', '\\1\\2sis');
Inflector::singular('/(^analy)ses$/i', '\\1sis');
Inflector::singular('/([^f])ves$/i', '\\1fe');
Inflector::singular('/(hive)s$/i', '\\1');
Inflector::singular('/(tive)s$/i', '\\1');
Inflector::singular('/([lr])ves$/i', '\\1f');
Inflector::singular('/([^aeiouy]|qu)ies$/i', '\\1y');
Inflector::singular('/(s)eries$/i', '\\1eries');
Inflector::singular('/(m)ovies$/i', '\\1ovie');
Inflector::singular('/(x|ch|ss|sh)es$/i', '\\1');
Inflector::singular('/([m|l])ice$/i', '\\1ouse');
Inflector::singular('/(bus)es$/i', '\\1');
Inflector::singular('/(o)es$/i', '\\1');
Inflector::singular('/(shoe)s$/i', '\\1');
Inflector::singular('/(cris|ax|test)es$/i', '\\1is');
Inflector::singular('/(octop|vir)i$/i', '\\1us');
Inflector::singular('/(alias|status)es$/i', '\\1');
Inflector::singular('/^(ox)en/i', '\\1');
Inflector::singular('/(vert|ind)ices$/i', '\\1ex');
Inflector::singular('/(matr)ices$/i', '\\1ix');
Inflector::singular('/(quiz)zes$/i', '\\1');
Inflector::singular('/(database)s$/i', '\\1');
Inflector::irregular('person', 'people');
Inflector::irregular('man', 'men');
Inflector::irregular('child', 'children');
Inflector::irregular('sex', 'sexes');
Inflector::irregular('move', 'moves');
Inflector::irregular('cow', 'cattle');
Inflector::uncountable(array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans'));