5 # Part of the ScoutLib application support library 6 # Copyright 2016 Edward Almasy and Internet Scout Research Group 7 # http://scout.wisc.edu 17 # ---- PUBLIC INTERFACE -------------------------------------------------- 25 $Trace = version_compare(PHP_VERSION,
"5.4.0",
">=")
26 ? debug_backtrace(FALSE, 2) : debug_backtrace(FALSE);
27 $Caller = basename($Trace[1][
"file"]).
":".$Trace[1][
"line"];
47 public static function CheckMyCaller($DesiredCaller, $ExceptionMsg = NULL)
49 # retrieve caller info 50 $Trace = version_compare(PHP_VERSION,
"5.4.0",
">=")
51 ? debug_backtrace(FALSE, 3) : debug_backtrace(FALSE);
52 $FullFile = $Trace[1][
"file"];
53 $File = basename($FullFile);
54 $Line = $Trace[1][
"line"];
55 $Class = isset($Trace[2][
"class"]) ? $Trace[2][
"class"] :
"";
56 $Function = isset($Trace[2][
"function"]) ? $Trace[2][
"function"] :
"";
58 # if caller does not match desired caller 59 if (($DesiredCaller != $Class)
60 && ($DesiredCaller != $Class.
"::".$Function)
61 && ($DesiredCaller != $Class.$Function)
62 && ($DesiredCaller != $File)
63 && ($DesiredCaller != $File.
":".$Line))
65 # if exception message supplied 66 if ($ExceptionMsg !== NULL)
68 # make any needed substitutions in exception message 83 $Class.
"::".$Function),
87 throw new Exception($Msg);
91 # report to our caller that their caller was not the desired one 96 # report to our caller that their caller was not the desired one 107 # return word unchanged if singular and plural are the same 108 if (in_array(strtolower($Word), self::$UncountableWords))
113 # check for irregular singular forms 114 foreach (self::$IrregularWords as $Pattern => $Result)
116 $Pattern =
'/'.$Pattern.
'$/i';
117 if (preg_match($Pattern, $Word))
119 return preg_replace($Pattern, $Result, $Word);
123 # check for matches using regular expressions 124 foreach (self::$PluralizePatterns as $Pattern => $Result)
126 if (preg_match($Pattern, $Word))
128 return preg_replace($Pattern, $Result, $Word);
132 # return word unchanged if we could not process it 143 # return word unchanged if singular and plural are the same 144 if (in_array(strtolower($Word), self::$UncountableWords))
149 # check for irregular plural forms 150 foreach (self::$IrregularWords as $Result => $Pattern)
152 $Pattern =
'/'.$Pattern.
'$/i';
153 if (preg_match($Pattern, $Word))
155 return preg_replace($Pattern, $Result, $Word);
159 # check for matches using regular expressions 160 foreach (self::$SingularizePatterns as $Pattern => $Result)
162 if (preg_match($Pattern, $Word))
164 return preg_replace($Pattern, $Result, $Word);
168 # return word unchanged if we could not process it 173 # ---- PRIVATE INTERFACE ------------------------------------------------- 175 private static $PluralizePatterns = array(
176 '/(quiz)$/i' =>
"$1zes",
177 '/^(ox)$/i' =>
"$1en",
178 '/([m|l])ouse$/i' =>
"$1ice",
179 '/(matr|vert|ind)ix|ex$/i' =>
"$1ices",
180 '/(x|ch|ss|sh)$/i' =>
"$1es",
181 '/([^aeiouy]|qu)y$/i' =>
"$1ies",
182 '/(hive)$/i' =>
"$1s",
183 '/(?:([^f])fe|([lr])f)$/i' =>
"$1$2ves",
184 '/(shea|lea|loa|thie)f$/i' =>
"$1ves",
186 '/([ti])um$/i' =>
"$1a",
187 '/(tomat|potat|ech|her|vet)o$/i'=>
"$1oes",
188 '/(bu)s$/i' =>
"$1ses",
189 '/(alias)$/i' =>
"$1es",
190 '/(octop)us$/i' =>
"$1i",
191 '/(ax|test)is$/i' =>
"$1es",
192 '/(us)$/i' =>
"$1es",
196 private static $SingularizePatterns = array(
197 '/(quiz)zes$/i' =>
"$1",
198 '/(matr)ices$/i' =>
"$1ix",
199 '/(vert|ind)ices$/i' =>
"$1ex",
200 '/^(ox)en$/i' =>
"$1",
201 '/(alias)es$/i' =>
"$1",
202 '/(octop|vir)i$/i' =>
"$1us",
203 '/(cris|ax|test)es$/i' =>
"$1is",
204 '/(shoe)s$/i' =>
"$1",
206 '/(bus)es$/i' =>
"$1",
207 '/([m|l])ice$/i' =>
"$1ouse",
208 '/(x|ch|ss|sh)es$/i' =>
"$1",
209 '/(m)ovies$/i' =>
"$1ovie",
210 '/(s)eries$/i' =>
"$1eries",
211 '/([^aeiouy]|qu)ies$/i' =>
"$1y",
212 '/([lr])ves$/i' =>
"$1f",
213 '/(tive)s$/i' =>
"$1",
214 '/(hive)s$/i' =>
"$1",
215 '/(li|wi|kni)ves$/i' =>
"$1fe",
216 '/(shea|loa|lea|thie)ves$/i'=>
"$1f",
217 '/(^analy)ses$/i' =>
"$1sis",
218 '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' =>
"$1$2sis",
219 '/([ti])a$/i' =>
"$1um",
220 '/(n)ews$/i' =>
"$1ews",
221 '/(h|bl)ouses$/i' =>
"$1ouse",
222 '/(corpse)s$/i' =>
"$1",
223 '/(us)es$/i' =>
"$1",
226 private static $IrregularWords = array(
231 'child' =>
'children',
236 private static $UncountableWords = array(
static CheckMyCaller($DesiredCaller, $ExceptionMsg=NULL)
Check the caller of the current function.
static GetMyCaller()
Get string with file and line number for call to current function.
static Pluralize($Word)
Pluralize an English word.
Standard utility library.
static Singularize($Word)
Singularize an English word.