Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Introduce Str.split :skip-empty
  • Loading branch information
lizmat committed Nov 5, 2015
1 parent 64bd8a5 commit d7a817a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/core/Str.pm
Expand Up @@ -1017,7 +1017,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
}.new(self,$limit));
}
}
multi method split(Str:D: @needles;; :$all, :$keep-indices) {
multi method split(Str:D: @needles;; :$all, :$keep-indices, :$skip-empty) {
return self.split(rx/ @needles /,:$all)
if Rakudo::Internals.NOT_ALL_DEFINED_TYPE(@needles,Cool);

Expand Down Expand Up @@ -1055,6 +1055,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
nqp::getattr(nqp::atpos($positions,$a),Pair,'$!value'))
}) if $fired > 1;

my int $skip = $skip-empty;
my $pair;
my int $from;
my int $pos;
Expand All @@ -1065,7 +1066,8 @@ my class Str does Stringy { # declared in BOOTSTRAP
$from = nqp::getattr($pair,Pair,'$!key');
if nqp::isge_i($from,$pos) { # not hidden by other needle
my int $needle-index = nqp::getattr($pair,Pair,'$!value');
nqp::push($result,nqp::substr($str,$pos,$from - $pos));
nqp::push($result,nqp::substr($str,$pos,$from - $pos))
unless $skip && nqp::iseq_i($from,$pos);
nqp::push($result,$needle-index);
$pos = $from + nqp::atpos($needle-chars,$needle-index);
}
Expand All @@ -1077,7 +1079,8 @@ my class Str does Stringy { # declared in BOOTSTRAP
$from = nqp::getattr($pair,Pair,'$!key');
if nqp::isge_i($from,$pos) { # not hidden by other needle
my int $needle-index = nqp::getattr($pair,Pair,'$!value');
nqp::push($result,nqp::substr($str,$pos,$from - $pos));
nqp::push($result,nqp::substr($str,$pos,$from - $pos))
unless $skip && nqp::iseq_i($from,$pos);
nqp::push($result,nqp::atpos($needles,$needle-index));
$pos = $from + nqp::atpos($needle-chars,$needle-index);
}
Expand All @@ -1088,7 +1091,8 @@ my class Str does Stringy { # declared in BOOTSTRAP
$pair := nqp::atpos($positions,nqp::shift($sorted));
$from = nqp::getattr($pair,Pair,'$!key');
if nqp::isge_i($from,$pos) { # not hidden by other needle
nqp::push($result,nqp::substr($str,$pos,$from - $pos));
nqp::push($result,nqp::substr($str,$pos,$from - $pos))
unless $skip && nqp::iseq_i($from,$pos);
$pos = $from + nqp::atpos(
$needle-chars,nqp::getattr($pair,Pair,'$!value'));
}
Expand Down

0 comments on commit d7a817a

Please sign in to comment.