Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix several issues reported by Tux++
  • Loading branch information
lizmat committed Nov 5, 2015
1 parent 289fdc5 commit 9fad7b4
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/core/Str.pm
Expand Up @@ -1031,6 +1031,11 @@ my class Str does Stringy { # declared in BOOTSTRAP
for @needles.kv -> $index, $needle {
my str $need = nqp::unbox_s($needle.Str);
my int $chars = nqp::chars($need);

# this is probably an error
die "Cannot have an empty needle when using multiple needles"
if nqp::iseq_i($chars,0);

nqp::push($needles,$need);
nqp::push($needle-chars,$chars);

Expand All @@ -1055,7 +1060,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 int $skip = ?$skip-empty;
my $pair;
my int $from;
my int $pos;
Expand All @@ -1066,9 +1071,10 @@ 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))
unless $skip && nqp::iseq_i($from,$pos);
nqp::push($result,$needle-index);
unless $skip && nqp::iseq_i($from,$pos) {
nqp::push($result,nqp::substr($str,$pos,$from - $pos));
nqp::push($result,$needle-index);
}
$pos = $from + nqp::atpos($needle-chars,$needle-index);
}
}
Expand All @@ -1079,9 +1085,10 @@ 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))
unless $skip && nqp::iseq_i($from,$pos);
nqp::push($result,nqp::atpos($needles,$needle-index));
unless $skip && nqp::iseq_i($from,$pos) {
nqp::push($result,nqp::substr($str,$pos,$from - $pos));
nqp::push($result,nqp::atpos($needles,$needle-index));
}
$pos = $from + nqp::atpos($needle-chars,$needle-index);
}
}
Expand All @@ -1098,7 +1105,8 @@ my class Str does Stringy { # declared in BOOTSTRAP
}
}
}
nqp::push($result,nqp::substr($str,$pos));
nqp::push($result,nqp::substr($str,$pos))
unless $skip && $pos == nqp::chars($str);

$result
}
Expand Down

0 comments on commit 9fad7b4

Please sign in to comment.