I have implemented the limit parameter on both Str.split(String,
Integer) and Str.split(Regex, Integer). In doing so I had to change
the method signature of Str.split(String) to ".sub 'split' :method
:multi(_, _)" from ".sub 'split' :method :multi('String')". The former
method signature is the correct one anyway as the latter just
restricts the invoker to being a 'String' and doesn't say anything
about the argument type.All the tests except for one in split.p6 "pass" (verify by just looking at the output). The one that doesn't pass is: say 102030405.split(0).perl; which produces: ["1.", "2", "3e+", "8"] Note that this bug is not introduced by the patch, it was only discovered because now we can do Int.split(Int).
Index: src/builtins/any-str.pir
===================================================================
--- src/builtins/any-str.pir (revision 31332)
+++ src/builtins/any-str.pir (working copy)
@@ -197,8 +197,10 @@
.end
.namespace['Any']
-.sub 'split' :method :multi('String')
+.sub 'split' :method :multi(_, _)
.param string delim
+ .param int count :optional
+ .param int has_count :opt_flag
.local string objst
.local pmc pieces
.local pmc tmps
@@ -214,6 +216,10 @@
len = pieces
i = 0
loop:
+ unless has_count goto skip_count
+ dec count
+ if count < 0 goto done
+ skip_count:
if i == len goto done
tmps = new 'Perl6Str'
@@ -229,6 +235,8 @@
.sub 'split' :method :multi(_, 'Sub')
.param pmc regex
+ .param int count :optional
+ .param int has_count :opt_flag
.local pmc match
.local pmc retv
.local int start_pos
@@ -244,6 +252,10 @@
goto done
loop:
+ unless has_count goto skip_count
+ dec count
+ if count < 0 goto done
+ skip_count:
match = regex($S0, 'continue' => start_pos)
end_pos = match.'from'()
end_pos -= start_pos
split.p6
Description: Binary data
