git.shiar.nl
/
perl
/
list-index.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a0438ad
)
lookbehind penalty
author
Mischa POSLAWSKY
<perl@shiar.org>
Fri, 13 Nov 2009 16:00:38 +0000
(17:00 +0100)
committer
Mischa POSLAWSKY
<perl@shiar.org>
Sat, 14 Nov 2009 16:26:28 +0000
(17:26 +0100)
lib/List/Index.pm
patch
|
blob
|
history
diff --git
a/lib/List/Index.pm
b/lib/List/Index.pm
index 4a2118910cf3708c11ada4bc07644930a33f3486..06c27273fcbd67193e9eb4f751ab280a93f0a8ac 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) {
+ if ($offset > $context - 1
+ $penalty
) {
# take a value slightly before the current offset
# 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) {
# 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,9
@@
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;
+# $offset += $context + 1;
+ $self->[$offset + ++$penalty] =~ /^\Q$link/
+ while $offset + $penalty < $#$self;
}
}
}
}
}
}