Skip to content

Commit

Permalink
Item2068:Item8008:
Browse files Browse the repository at this point in the history
   * added =include= counterpart to already existing =exclude= params
   * fixed SUBST not to forget about the non-matching tail of a char sequence



git-svn-id: http://svn.foswiki.org/trunk/FilterPlugin@4918 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Sep 14, 2009
1 parent 03a24e5 commit 8c295da
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions data/System/FilterPlugin.txt
Expand Up @@ -44,6 +44,7 @@ insert a topic by processing its content.
start of the text (defaults to =100000= aka all hits)
* =skip="<n>"= skip the first n occurences
* =exclude="..."=: skip occurences that match this regular expression
* =include="..."=: skip occurences that don't match this regular expression
* sort="on,off,alpha,num" order of the formatted items (default "off")
* =expand="on,off"=: toggle expansion of markup before filtering
(defaults to =on=)
Expand Down Expand Up @@ -94,6 +95,7 @@ prepended with a header and appended with a footer in case the list is not empty
* reverse="on,off": reverse the sortion of the list
* unique="on,off": remove dupplicates from the list
* exclude="...": remove list items that match this regular expression
* include="...": remove list items that don't match this regular expression
* selection="...": regular expression that a list item must match to be "selected"; if this matches the =$marker= is inserted
* marker="...": string to be inserted when the =selection= regex matches; this will be inserted at the position =$marker= as
indicated in =format= .
Expand Down Expand Up @@ -122,6 +124,7 @@ parameters:
* sort="on,off,alpha,num,nocase": sort the list (default "on")
* unique="on/off": removed duplicates (default "off")
* exclude="...": pattern to check against items in the list to be excluded
* include="...": pattern to check against items in the list to be included
* reverse="on/off": reverse the list (default "off")
* header="...": format string to prepend to the result
* footer="..." format string to be appended to the result
Expand Down Expand Up @@ -179,6 +182,8 @@ compare with [[http://en.wikipedia.org/wiki/Category:Philosophy_articles_needing
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 14 Sep 2009: | added =include= counterpart to already existing =exclude= params; \
fixed SUBST not to forget about the non-matching tail of a char sequence |
| 17 Apr 2009: | converted to foswiki, added numerical sorting to MAKETEXT |
| 08 Oct 2008: | added =$anchors= to MAKEINDEX (by Dirk Zimoch); \
added =nocase= option to FORMATLIST (by Dirk Zimoch); \
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/FilterPlugin.pm
Expand Up @@ -25,7 +25,7 @@ use vars qw(
);

$VERSION = '$Rev$';
$RELEASE = '1.80';
$RELEASE = '1.90';
$NO_PREFS_IN_TOPIC = 1;
$SHORTDESCRIPTION = 'Substitute and extract information from content by using regular expressions';

Expand Down
17 changes: 14 additions & 3 deletions lib/Foswiki/Plugins/FilterPlugin/Core.pm
Expand Up @@ -82,6 +82,7 @@ sub handleFilter {
my $theExpand = $params->{expand} || 'on';
my $theSeparator = $params->{separator};
my $theExclude = $params->{exclude} || '';
my $theInclude = $params->{include} || '';
my $theSort = $params->{sort} || 'off';
my $theReverse = $params->{reverse} || '';
my $theNoCase = $params->{nocase} || 'off';
Expand Down Expand Up @@ -150,6 +151,7 @@ sub handleFilter {
$match =~ s/\$8/$arg8/g;
$match =~ s/\$9/$arg9/g;
next if $theExclude && $match =~ /^($theExclude)$/;
next if $theInclude && $match !~ /^($theInclude)$/;
next if $skip-- > 0;
push @result,$match;
$hits--;
Expand All @@ -167,7 +169,7 @@ sub handleFilter {
} elsif ($theMode == 1) {
# substitution mode
$result = '';
while($text =~ /(.*?)$thePattern/gs) {
while($text =~ /(.*?)$thePattern/gcs) {
my $prefix = $1;
my $arg1 = $2;
my $arg2 = $3;
Expand Down Expand Up @@ -203,13 +205,17 @@ sub handleFilter {
$match =~ s/\$8/$arg8/g;
$match =~ s/\$9/$arg9/g;
next if $theExclude && $match =~ /^($theExclude)$/;
next if $theInclude && $match !~ /^($theInclude)$/;
next if $skip-- > 0;
#writeDebug("match=$match");
$result .= $prefix.$match;
#writeDebug("($hits) result=$result");
$hits--;
last if $theLimit > 0 && $hits <= 0;
}
if ($text =~ /\G(.*)$/) {
$result .= $1;
}
}
$result = $theNullFormat unless $result;
$result = $theHeader.$result.$theFooter;
Expand Down Expand Up @@ -244,6 +250,7 @@ sub handleMakeIndex {
my $theSplit = $params->{split} || ',';
my $theUnique = $params->{unique} || '';
my $theExclude = $params->{exclude} || '';
my $theInclude = $params->{include} || '';
my $theReverse = $params->{reverse} || '';
my $thePattern = $params->{pattern} || '';
my $theHeader = $params->{header} || '';
Expand Down Expand Up @@ -273,6 +280,7 @@ sub handleMakeIndex {
my %seen = ();
foreach my $item (split(/$theSplit/, $theList)) {
next if $theExclude && $item =~ /^($theExclude)$/;
next if $theInclude && $item !~ /^($theInclude)$/;

$item =~ s/<nop>//go;
$item =~ s/^\s+//go;
Expand All @@ -287,7 +295,7 @@ sub handleMakeIndex {
}

my $crit = $item;
if ($crit =~ /^\((.*?)\)(.*)$/) {
if ($crit =~ /\((.*?)\)/) {
$crit = $1;
}
if ($theSort eq 'nocase') {
Expand Down Expand Up @@ -341,7 +349,7 @@ sub handleMakeIndex {
group=>$group,
format=>$itemFormat,
);
writeDebug("group=$descriptor{group}, item=$descriptor{item} crit=$descriptor{crit}");
#writeDebug("group=$descriptor{group}, item=$descriptor{item} crit=$descriptor{crit}");
push @theList, \%descriptor;
}

Expand Down Expand Up @@ -501,6 +509,7 @@ sub handleFormatList {
my $theSort = $params->{sort} || 'off';
my $theUnique = $params->{unique} || '';
my $theExclude = $params->{exclude} || '';
my $theInclude = $params->{include} || '';
my $theReverse = $params->{reverse} || '';
my $theSelection = $params->{selection};
my $theMarker = $params->{marker};
Expand All @@ -522,6 +531,7 @@ sub handleFormatList {
#writeDebug("theSort='$theSort'");
#writeDebug("theUnique='$theUnique'");
#writeDebug("theExclude='$theExclude'");
#writeDebug("theInclude='$theInclude'");

my @theList = split(/$theSplit/, $theList);
if ($theSort ne 'off') {
Expand All @@ -540,6 +550,7 @@ sub handleFormatList {
foreach my $item (@theList) {
#writeDebug("found '$item'");
next if $theExclude && $item =~ /^($theExclude)$/;
next if $theInclude && $item !~ /^($theInclude)$/;
next if $item =~ /^$/; # skip empty elements
my $arg1 = '';
my $arg2 = '';
Expand Down

0 comments on commit 8c295da

Please sign in to comment.