Skip to content

Commit

Permalink
fix Str.split for zero-width matches
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Feb 23, 2009
1 parent 2cc539b commit e074bf4
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/setting/Str.pm
Expand Up @@ -6,13 +6,20 @@ class Str is also {
our List multi method split(Code $delimiter, $limit = *) {
my $s = self;
my $l = $limit ~~ Whatever ?? Inf !! $limit;
my $keep = '';
return gather {
while $l > 1 && $s ~~ $delimiter {
take $s.substr(0, $/.from);
$s.=substr([max] $/.to, 1);
take $keep ~ $s.substr(0, $/.from);
if $/.from == $/.to {
$keep = $s.substr($/.to, 1);
$s.=substr($/.to + 1);
} else {
$keep = '';
$s.=substr($/.to)
}
$l--;
}
take $s if $l > 0;
take $keep ~ $s if $l > 0;
}
}

Expand All @@ -21,6 +28,11 @@ class Str is also {
my Int $prev = 0;
my $l = $limit ~~ Whatever ?? Inf !! $limit;
$delimiter = ~$delimiter;
if $delimiter eq '' {
return gather {
take self.substr($_, 1) for 0 .. self.chars - 1;
}
}
return gather {
my $pos;
while $l > 1
Expand Down

0 comments on commit e074bf4

Please sign in to comment.