From b6d480274eff8424a5ee22894a96bba261d3d4ae Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Fri, 13 Nov 2009 17:00:38 +0100 Subject: [PATCH] lookbehind penalty --- lib/List/Index.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/List/Index.pm b/lib/List/Index.pm index 4a21189..06c2727 100644 --- a/lib/List/Index.pm +++ b/lib/List/Index.pm @@ -24,13 +24,14 @@ sub ranges { $pagesize = @$self / $pages; my $offset = $pagesize + .5; + my $penalty = 0; my @links = (''); while ($offset < @$self) { my $link = substr $self->[$offset], 0, $length; if ($context) { - if ($offset > $context - 1) { + if ($offset > $context - 1 + $penalty) { # take a value slightly before the current offset - my $before = $self->[$offset - $context - 1]; + my $before = $self->[$offset - $context - 1 + $penalty]; # see how much of it matches the current link my $trim = 1; for my $match (split //, $before) { @@ -41,6 +42,7 @@ sub ranges { substr($link, $trim) = '' unless $trim > length $link; } + $penalty = 0; if ($offset + $context < $#$self) { # take a value after the current offset my $after = $self->[$offset + $context]; @@ -53,6 +55,9 @@ sub ranges { # use this link if it's shorter if ($trim < length $link) { $link = substr $after, 0, $trim; +# $offset += $context + 1; + $self->[$offset + ++$penalty] =~ /^\Q$link/ + while $offset + $penalty < $#$self; } } } -- 2.30.0