| @@ 114-146 (lines=33) @@ | ||
| 111 | * @param string $string Word to pluralise |
|
| 112 | * @return string Pluralised word |
|
| 113 | */ |
|
| 114 | public static function getPlural($string) |
|
| 115 | { |
|
| 116 | // save some time in the case that singular and plural are the same |
|
| 117 | if (in_array(strtolower($string), self::$uncountable)) { |
|
| 118 | return $string; |
|
| 119 | } |
|
| 120 | ||
| 121 | // check to see if already plural and irregular |
|
| 122 | foreach (self::$irregular as $pattern => $result) { |
|
| 123 | $_pattern = '/' . $result . '$/i'; |
|
| 124 | if (preg_match($_pattern, $string)) { |
|
| 125 | return $string; |
|
| 126 | } |
|
| 127 | } |
|
| 128 | ||
| 129 | // check for irregular singular forms |
|
| 130 | foreach (self::$irregular as $pattern => $result) { |
|
| 131 | $pattern = '/' . $pattern . '$/i'; |
|
| 132 | if (preg_match($pattern, $string)) { |
|
| 133 | return preg_replace($pattern, $result, $string); |
|
| 134 | } |
|
| 135 | } |
|
| 136 | ||
| 137 | // check for matches using regular expressions |
|
| 138 | foreach (self::$plural as $pattern => $result) { |
|
| 139 | if (preg_match($pattern, $string)) { |
|
| 140 | return preg_replace($pattern, $result, $string); |
|
| 141 | } |
|
| 142 | } |
|
| 143 | ||
| 144 | // No pattern match. Add an "s". |
|
| 145 | return $string . 's'; |
|
| 146 | } |
|
| 147 | ||
| 148 | /** |
|
| 149 | * Get the singular of the word passed in. |
|
| @@ 153-184 (lines=32) @@ | ||
| 150 | * @param string $string Word to singularise |
|
| 151 | * @return string Singularised word |
|
| 152 | */ |
|
| 153 | public static function getSingular($string) |
|
| 154 | { |
|
| 155 | // save some time in the case that singular and plural are the same |
|
| 156 | if (in_array(strtolower($string), self::$uncountable)) { |
|
| 157 | return $string; |
|
| 158 | } |
|
| 159 | ||
| 160 | // check to see if already singular and irregular |
|
| 161 | foreach (self::$irregular as $pattern => $result) { |
|
| 162 | $_pattern = '/' . $pattern . '$/i'; |
|
| 163 | if (preg_match($_pattern, $string)) { |
|
| 164 | return $string; |
|
| 165 | } |
|
| 166 | } |
|
| 167 | ||
| 168 | // check for irregular plural forms |
|
| 169 | foreach (self::$irregular as $result => $pattern) { |
|
| 170 | $pattern = '/' . $pattern . '$/i'; |
|
| 171 | if (preg_match($pattern, $string)) { |
|
| 172 | return preg_replace($pattern, $result, $string); |
|
| 173 | } |
|
| 174 | } |
|
| 175 | ||
| 176 | // check for matches using regular expressions |
|
| 177 | foreach (self::$singular as $pattern => $result) { |
|
| 178 | if (preg_match($pattern, $string)) { |
|
| 179 | return preg_replace($pattern, $result, $string); |
|
| 180 | } |
|
| 181 | } |
|
| 182 | ||
| 183 | return $string; |
|
| 184 | } |
|
| 185 | } |
|
| 186 | ||