Skip to content

Commit

Permalink
Item13074: fix definition of $count
Browse files Browse the repository at this point in the history
- added $hits variable to clearly distinguish it from $count
  • Loading branch information
MichaelDaum committed Sep 9, 2016
1 parent 4102bcc commit 2c61cfd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
14 changes: 7 additions & 7 deletions .gitignore
@@ -1,9 +1,9 @@
*.swp
*,v
FilterPlugin.md5
FilterPlugin.sha1
FilterPlugin.tgz
FilterPlugin.txt
FilterPlugin.zip
FilterPlugin_installer
FilterPlugin_installer.pl
/FilterPlugin.md5
/FilterPlugin.sha1
/FilterPlugin.tgz
/FilterPlugin.txt
/FilterPlugin.zip
/FilterPlugin_installer
/FilterPlugin_installer.pl
6 changes: 4 additions & 2 deletions data/System/FilterPlugin.txt
Expand Up @@ -96,8 +96,9 @@ The pattern string shall group matching substrings in the list item to which
you can refer to by using $1, $2, ... in the format string. Any format string
(=format=, =header=, =footer=) may contain variables =$percnt$=, =$nop=,
=$dollar= and =$n=. The variable =$index= referse to the position number within
the list being formatted; =$count= refers to the total number of matched list
elementsr;=$marker= is set if the =selection= regular expression matches the
the list being formatted; =$hits= refers to the total number of matched list
elements; =$count= expands to the total number of elements in the list;
=$marker= is set if the =selection= regular expression matches the
current item. The =$map(key)= macro returns the value for "key" as specified in
the =map= argument.

Expand Down Expand Up @@ -253,6 +254,7 @@ compare with [[http://en.wikipedia.org/wiki/Category:Philosophy_articles_needing
---++ Change History

%TABLE{columnwidths="7em" tablewidth="100%"}%
| 05 Sep 2016: | added =$hits= to FORMATLIST to distinguish it from =$count= and =$index= |
| 29 Apr 2016: | don't fallback to unidecode if an explicit mapping is given; don't use Foswiki's internal anchor creator as it does not support unicode |
| 20 Apr 2016: | added =transliterate= parameter, including custom mappings; upgraded Text::Unidecode fallback shipped with this plugin |
| 31 Aug 2015: | fixing deprecated unescaped left brace in regexes |
Expand Down
4 changes: 2 additions & 2 deletions lib/Foswiki/Plugins/FilterPlugin.pm
Expand Up @@ -21,8 +21,8 @@ use warnings;

use Foswiki::Func();

our $VERSION = '4.23';
our $RELEASE = '29 Apr 2016';
our $VERSION = '4.30';
our $RELEASE = '05 Sep 2016';
our $NO_PREFS_IN_TOPIC = 1;
our $SHORTDESCRIPTION = 'Substitute and extract information from content by using regular expressions';
our $core;
Expand Down
15 changes: 9 additions & 6 deletions lib/Foswiki/Plugins/FilterPlugin/Core.pm
Expand Up @@ -610,7 +610,7 @@ sub handleFormatList {
}
@theList = reverse @theList if $theReverse;

my $count = 0;
my $index = 0;
my $hits = 0;
my @result;

Expand All @@ -623,8 +623,8 @@ sub handleFormatList {
next if $theInclude && $item !~ /^($theInclude)$/;
next if $item =~ /^$/; # skip empty elements

$count++;
next if $count <= $theSkip;
$index++;
next if $index <= $theSkip;
last if $theLimit > 0 && $hits >= $theLimit;

my $arg1 = '';
Expand Down Expand Up @@ -680,7 +680,7 @@ sub handleFormatList {
$seen{$line} = 1;
}

$line =~ s/\$index/$count/ge;
$line =~ s/\$index/$index/ge;
if ($theSelection && $item =~ /$theSelection/) {
$line =~ s/\$marker/$theMarker/g
} else {
Expand All @@ -696,16 +696,19 @@ sub handleFormatList {
return '' unless $theNullFormat;
$result = $theNullFormat;
} else {
if (defined($theLastSeparator) && ($count > 1)) {
if (defined($theLastSeparator) && ($index > 1)) {
my $lastElement = pop(@result);
$result = join($theSeparator, @result) . $theLastSeparator . $lastElement;
} else {
$result = join($theSeparator, @result);
}
}

my $count = scalar(@theList);

$result = $theHeader.$result.$theFooter;
$result =~ s/\$count/$hits/g;
$result =~ s/\$hits/$hits/g;
$result =~ s/\$count/$count/g;

expandVariables($result);
return $result;
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/FilterPlugin/build.pl
@@ -1,4 +1,4 @@
#!/usr/bin/perl -w
#!/usr/bin/env perl
#
# Build for FilterPlugin
#
Expand Down

0 comments on commit 2c61cfd

Please sign in to comment.