*** Search.pm.orig Fri May 13 14:41:42 2005 --- Search.pm Fri May 13 14:59:49 2005 *************** *** 974,979 **** --- 974,980 ---- $tempVal =~ s/\$formfield\(\s*([^\)]*)\s*\)/getMetaFormField( $meta, $1 )/geos; $tempVal =~ s/\$formname/_getMetaFormName( $meta )/geos; $tempVal =~ s/\$pattern\((.*?\s*\.\*)\)/getTextPattern( $text, $1 )/geos; + $tempVal =~ s/\$count\((.*?\s*\.\*)\)/getCountPattern( $text, $1 )/geos; $tempVal =~ s/\$nop(\(\))?//gos; # remove filler, useful for nested search $tempVal =~ s/\$quot(\(\))?/\"/gos; # expand double quote $tempVal =~ s/\$percnt(\(\))?/\%/gos; # expand percent *************** *** 1213,1218 **** --- 1214,1245 ---- $theText = "" unless( $OK ); return $theText; + } + + #========================= + =pod + + ---++ sub getCountPattern ( $theText, $thePattern ) + + With the same argument as $pattern, returns a number which is the count of + occurences of the pattern argument. + + =cut + + sub getCountPattern + { + my( $theText, $thePattern ) = @_; + + $thePattern =~ s/([^\\])([\$\@\%\&\#\'\`\/])/$1\\$2/go; # escape some special chars + $thePattern =~ /(.*)/; # untaint + $thePattern = $1; + my $OK = 0; + eval { + # counting hack, see: http://dev.perl.org/perl6/rfc/110.html + $OK = () = $theText =~ /$thePattern/g; + }; + + return $OK; } #=========================