Skip to content

Commit

Permalink
:all flag for Str.split
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Jul 12, 2009
1 parent 4403ec7 commit d6f9537
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/setting/Any-str.pm
Expand Up @@ -81,7 +81,7 @@ class Any is also {
}
}

our List multi method split(Code $delimiter, $limit = *) {
our List multi method split(Code $delimiter, $limit = *, :$all) {
my $s = ~self;
my $l = $limit ~~ Whatever ?? Inf !! $limit;
my $keep = '';
Expand All @@ -96,6 +96,11 @@ class Any is also {
$s.=substr($/.to)
}
$l--;
next if $l < 1;
if $all {
$l--;
take $/;
}
}
take $keep ~ $s if $l > 0;
}
Expand Down Expand Up @@ -170,8 +175,8 @@ class Any is also {
}
}
multi sub split($delimiter, $target, $limit = *) {
$target.split($delimiter, $limit);
multi sub split($delimiter, $target, $limit = *, :$all) {
$target.split($delimiter, $limit, :$all);
}

# TODO: '$filename as Str' once support for that is in place
Expand Down

0 comments on commit d6f9537

Please sign in to comment.