Skip to content

Commit

Permalink
work around Rakudo bugs to get Str.split working
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Feb 23, 2009
1 parent 215ad17 commit 1fe71b8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/setting/Any.pm
@@ -1,5 +1,5 @@
class Any is also {
method split($delimiter, Int $limit = *) {
method split($delimiter, $limit = *) {
if $limit ~~ Whatever {
return (~self).split($delimiter);
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/setting/Str.pm
Expand Up @@ -19,13 +19,15 @@ class Str is also {
self.split($delimiter).[0..$limit];
}

# TODO: substitute with $delimiter as Str once coercion is implemented
# TODO: substitute with '$delimiter as Str' once coercion is implemented
our List multi method split($delimiter is copy) {
my Int $prev = 0;
$delimiter = ~$delimiter;
return gather {
my $pos;
while defined ($pos = self.index($delimiter, $prev)) {
# work around a rakudo bug: "102030405".index(0, 10).defined is True
while $prev <= self.chars
&& defined ($pos = self.index($delimiter, $prev)) {
take self.substr($prev, $pos - $prev);
$prev = $pos + $delimiter.chars;
}
Expand Down

0 comments on commit 1fe71b8

Please sign in to comment.