Skip to content

Commit 334de3b

Browse files
committed
Port split_words to NQP.
1 parent 597cb7e commit 334de3b

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

src/HLL/Grammar.pm

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -461,27 +461,16 @@ position C<pos>.
461461
}
462462

463463
our method split_words(str $words) {
464-
Q:PIR {
465-
.include 'src/Regex/constants.pir'
466-
.local string words
467-
words = find_lex '$words'
468-
.local int pos, eos
469-
.local pmc result
470-
pos = 0
471-
eos = length words
472-
result = new ['ResizablePMCArray']
473-
split_loop:
474-
pos = find_not_cclass .CCLASS_WHITESPACE, words, pos, eos
475-
unless pos < eos goto split_done
476-
$I0 = find_cclass .CCLASS_WHITESPACE, words, pos, eos
477-
$I1 = $I0 - pos
478-
$S0 = substr words, pos, $I1
479-
push result, $S0
480-
pos = $I0
481-
goto split_loop
482-
split_done:
483-
.return (result)
484-
};
464+
my @result;
465+
my int $pos := 0;
466+
my int $eos := nqp::chars($words);
467+
my int $ws;
468+
while ($pos := nqp::findnotcclass(pir::const::CCLASS_WHITESPACE, $words, $pos, $eos)) < $eos {
469+
$ws := nqp::findcclass(pir::const::CCLASS_WHITESPACE, $words, $pos, $eos);
470+
nqp::push(@result, nqp::substr($words, $pos, $ws - $pos));
471+
$pos := $ws;
472+
}
473+
@result
485474
}
486475

487476
=begin

0 commit comments

Comments
 (0)