Skip to content

Commit

Permalink
Item13139: share code with TablesContrib
Browse files Browse the repository at this point in the history
  • Loading branch information
Comment committed Dec 15, 2014
1 parent c206955 commit 362b694
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions core/lib/Foswiki/Tables/Reader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,39 @@ BEGIN {
}
}

# Foswiki 1.1.9 didn't define findFirstOccurenceAttrs. Monkey-patch it.
unless ( defined &Foswiki::Attrs::findFirstOccurenceAttrs ) {
*Foswiki::Attrs::findFirstOccurenceAttrs = sub {
my ( $macro, $text ) = @_;
return undef unless $text =~ /\%${macro}[%{]/s;
my @queue = split( /(%[A-Za-z0-9_]*{|}%|\%${macro}\%)/, $text );
my $eat = 0;
my $eaten = '';
while ( scalar(@queue) ) {
my $token = shift @queue;
if ($eat) {
if ( $token =~ /^%[A-Za-z0-9_]*{$/ ) {
$eat++;
}
elsif ( $eat && $token eq '}%' ) {
$eat--;
return $eaten if ( !$eat );
}
$eaten .= $token;
}
else {
if ( $token eq "\%${macro}%" ) {
return '';
}
elsif ( $token eq "\%${macro}\{" ) {
$eat = 1;
}
}
}
return '';
}
}

=begin TML
---++ ClassMethod new($table_class) -> $parser
Expand Down

0 comments on commit 362b694

Please sign in to comment.