template/wordpress/code/inflector.php in edge_framework-1.0.0 vs template/wordpress/code/inflector.php in edge_framework-1.1.0
- old
+ new
@@ -1,11 +1,16 @@
<?php
-// Thanks to http://www.eval.ca/articles/php-pluralize (MIT license)
-// http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/inflections.rb (MIT license)
-// http://www.fortunecity.com/bally/durrus/153/gramch13.html
-// http://www2.gsu.edu/~wwwesl/egw/crump.htm
+/*
+ Pluralize or Singularize a verb/noun
+ Thanks to:
+ - http://www.eval.ca/articles/php-pluralize (MIT license)
+ - http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/inflections.rb (MIT license)
+ - http://www.fortunecity.com/bally/durrus/153/gramch13.html
+ - http://www2.gsu.edu/~wwwesl/egw/crump.htm
+*/
+
class Inflector {
static $plural = array(
'/(quiz)$/i' => "$1zes",
'/^(ox)$/i' => "$1en",
'/([m|l])ouse$/i' => "$1ice",
@@ -57,41 +62,41 @@
'/(us)es$/i' => "$1",
'/s$/i' => ""
);
static $irregular = array(
- 'move' => 'moves',
- 'foot' => 'feet',
- 'goose' => 'geese',
- 'sex' => 'sexes',
- 'child' => 'children',
- 'man' => 'men',
- 'tooth' => 'teeth',
- 'person' => 'people'
+ "move" => "moves",
+ "foot" => "feet",
+ "goose" => "geese",
+ "sex" => "sexes",
+ "child" => "children",
+ "man" => "men",
+ "tooth" => "teeth",
+ "person" => "people"
);
static $uncountable = array(
- 'sheep',
- 'fish',
- 'deer',
- 'series',
- 'species',
- 'money',
- 'rice',
- 'information',
- 'equipment'
+ "sheep",
+ "fish",
+ "deer",
+ "series",
+ "species",
+ "money",
+ "rice",
+ "information",
+ "equipment"
);
public static function pluralize( $string ) {
// save some time in the case that singular and plural are the same
if ( in_array( strtolower( $string ), self::$uncountable ) ) {
return $string;
}
// check for irregular singular forms
foreach ( self::$irregular as $pattern => $result ) {
- $pattern = '/' . $pattern . '$/i';
+ $pattern = "/" . $pattern . "$/i";
if ( preg_match( $pattern, $string ) ) {
return preg_replace( $pattern, $result, $string);
}
}
@@ -112,10 +117,10 @@
return $string;
}
// check for irregular plural forms
foreach ( self::$irregular as $result => $pattern ) {
- $pattern = '/' . $pattern . '$/i';
+ $pattern = "/" . $pattern . "$/i";
if ( preg_match( $pattern, $string ) ) {
return preg_replace( $pattern, $result, $string);
}
}
\ No newline at end of file