$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) {
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];
# 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;
}
}
}