git.shiar.nl
/
perl
/
list-index.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
XXX: distribution test
[perl/list-index.git]
/
lib
/
List
/
Index.pm
diff --git
a/lib/List/Index.pm
b/lib/List/Index.pm
index 5b46313d7272168dea172ddf5135ce9ef480dae0..339bd7d8710b6ede1e44fef6b207d28e0e26f766 100644
(file)
--- a/
lib/List/Index.pm
+++ b/
lib/List/Index.pm
@@
-24,13
+24,14
@@
sub ranges {
$pagesize = @$self / $pages;
my $offset = $pagesize + .5;
$pagesize = @$self / $pages;
my $offset = $pagesize + .5;
+ my $penalty = 0;
my @links = ('');
while ($offset < @$self) {
my $link = substr $self->[$offset], 0, $length;
if ($context) {
my @links = ('');
while ($offset < @$self) {
my $link = substr $self->[$offset], 0, $length;
if ($context) {
- {
+
if ($offset > $context - 1 + $penalty)
{
# take a value slightly before the current offset
# take a value slightly before the current offset
- my $before = $
offset > $context ? $self->[$offset - $context] : '.'
;
+ my $before = $
self->[$offset - $context - 1 + $penalty]
;
# see how much of it matches the current link
my $trim = 1;
for my $match (split //, $before) {
# 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;
}
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];
if ($offset + $context < $#$self) {
# take a value after the current offset
my $after = $self->[$offset + $context];
@@
-53,6
+55,10
@@
sub ranges {
# use this link if it's shorter
if ($trim < length $link) {
$link = substr $after, 0, $trim;
# use this link if it's shorter
if ($trim < length $link) {
$link = substr $after, 0, $trim;
+ for ($offset .. $#$self) {
+ last if $self->[$offset + $penalty] =~ /^\Q$link/;
+ $penalty++;
+ }
}
}
}
}
}
}