New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some fixes to split methods #336
Comments
From cdavaz@gmail.comI have implemented the limit parameter on both Str.split(String, All the tests except for one in split.p6 "pass" (verify by just say 102030405.split(0).perl; which produces: ["1.", "2", "3e+", "8"] Note that this bug is not introduced by the patch, it was only |
From cdavaz@gmail.comsplit.diffIndex: 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
|
From cdavaz@gmail.com |
From @moritzOn Sun Sep 21 23:47:04 2008, cdavaz@gmail.com wrote:
Applied as r31333, thank you very much.
For the mid-term and long term goals it would be much better if you
Aye. I think we have no spec (yet?) on how to stringify integers, and I don't It's likely that we either won't have exact standards (and therefore But that's not the topic of this ticket, so closing it now. |
The RT System itself - Status changed from 'new' to 'open' |
@moritz - Status changed from 'open' to 'resolved' |
From @pmichaud
I see this as being a Rakudo/Parrot bug, not a specification bug. As to _why_ the above involves floating points at all -- currently the When RT #59006 is fixed, this issue will also likely be fixed. However, Thanks! Pm |
cdavaz@gmail.com - Status changed from 'resolved' to 'open' |
From cdavaz@gmail.comI have made the following fixes to split: A negative or zero limit returns all split elements (before returned the If limit is less than the total number of possible elements that the |
From cdavaz@gmail.comsplit.diffIndex: src/builtins/any-str.pir
===================================================================
--- src/builtins/any-str.pir (revision 31355)
+++ src/builtins/any-str.pir (working copy)
@@ -203,32 +203,44 @@
.param int has_count :opt_flag
.local string objst
.local pmc pieces
- .local pmc tmps
.local pmc retv
.local int len
+ .local int pos
.local int i
retv = new 'List'
+ # per Perl 5's negative LIMIT behavior
+ if has_count goto handle_count
+ handle_count:
+ unless count < 1 goto positive_count
+ has_count = 0
+
+ positive_count:
objst = self
+ length $I0, delim
split pieces, delim, objst
-
len = pieces
+ pos = 0
i = 0
+
loop:
unless has_count goto skip_count
dec count
- if count < 0 goto done
+ unless count < 1 goto skip_count
+ $S0 = substr objst, pos
+ retv.'push'($S0)
+ goto done
skip_count:
if i == len goto done
-
- tmps = new 'Perl6Str'
- tmps = pieces[i]
-
- retv.'push'(tmps)
-
+ $S0 = pieces[i]
+ retv.'push'($S0)
+ length $I1, $S0
+ pos += $I0
+ pos += $I1
inc i
goto loop
+
done:
.return(retv)
.end
@@ -246,6 +258,13 @@
retv = new 'List'
start_pos = 0
+ # per Perl 5's negative LIMIT behavior
+ if has_count goto handle_count
+ handle_count:
+ unless count < 1 goto positive_count
+ has_count = 0
+
+ positive_count:
match = regex($S0)
if match goto loop
retv.'push'($S0)
@@ -254,7 +273,10 @@
loop:
unless has_count goto skip_count
dec count
- if count < 0 goto done
+ unless count < 1 goto skip_count
+ $S1 = substr $S0, start_pos
+ retv.'push'($S1)
+ goto done
skip_count:
match = regex($S0, 'continue' => start_pos)
end_pos = match.'from'()
|
From cdavaz@gmail.comSorry I made a small mistake in the last patch, this one gives it: Changed if has_count goto handle_count To unless has_count goto positive_count |
From cdavaz@gmail.comsplit.diffIndex: src/builtins/any-str.pir
===================================================================
--- src/builtins/any-str.pir (revision 31355)
+++ src/builtins/any-str.pir (working copy)
@@ -203,32 +203,44 @@
.param int has_count :opt_flag
.local string objst
.local pmc pieces
- .local pmc tmps
.local pmc retv
.local int len
+ .local int pos
.local int i
retv = new 'List'
+ # per Perl 5's negative LIMIT behavior
+ unless has_count goto positive_count
+ handle_count:
+ unless count < 1 goto positive_count
+ has_count = 0
+
+ positive_count:
objst = self
+ length $I0, delim
split pieces, delim, objst
-
len = pieces
+ pos = 0
i = 0
+
loop:
unless has_count goto skip_count
dec count
- if count < 0 goto done
+ unless count < 1 goto skip_count
+ $S0 = substr objst, pos
+ retv.'push'($S0)
+ goto done
skip_count:
if i == len goto done
-
- tmps = new 'Perl6Str'
- tmps = pieces[i]
-
- retv.'push'(tmps)
-
+ $S0 = pieces[i]
+ retv.'push'($S0)
+ length $I1, $S0
+ pos += $I0
+ pos += $I1
inc i
goto loop
+
done:
.return(retv)
.end
@@ -246,6 +258,13 @@
retv = new 'List'
start_pos = 0
+ # per Perl 5's negative LIMIT behavior
+ unless has_count goto positive_count
+ handle_count:
+ unless count < 1 goto positive_count
+ has_count = 0
+
+ positive_count:
match = regex($S0)
if match goto loop
retv.'push'($S0)
@@ -254,7 +273,10 @@
loop:
unless has_count goto skip_count
dec count
- if count < 0 goto done
+ unless count < 1 goto skip_count
+ $S1 = substr $S0, start_pos
+ retv.'push'($S1)
+ goto done
skip_count:
match = regex($S0, 'continue' => start_pos)
end_pos = match.'from'()
|
From cdavaz@gmail.comGrr.. wrong again sorry!! Forgot to remove the handle_count label. |
From cdavaz@gmail.comsplit.diffIndex: src/builtins/any-str.pir
===================================================================
--- src/builtins/any-str.pir (revision 31355)
+++ src/builtins/any-str.pir (working copy)
@@ -203,32 +203,43 @@
.param int has_count :opt_flag
.local string objst
.local pmc pieces
- .local pmc tmps
.local pmc retv
.local int len
+ .local int pos
.local int i
retv = new 'List'
+ # per Perl 5's negative LIMIT behavior
+ unless has_count goto positive_count
+ unless count < 1 goto positive_count
+ has_count = 0
+
+ positive_count:
objst = self
+ length $I0, delim
split pieces, delim, objst
-
len = pieces
+ pos = 0
i = 0
+
loop:
unless has_count goto skip_count
dec count
- if count < 0 goto done
+ unless count < 1 goto skip_count
+ $S0 = substr objst, pos
+ retv.'push'($S0)
+ goto done
skip_count:
if i == len goto done
-
- tmps = new 'Perl6Str'
- tmps = pieces[i]
-
- retv.'push'(tmps)
-
+ $S0 = pieces[i]
+ retv.'push'($S0)
+ length $I1, $S0
+ pos += $I0
+ pos += $I1
inc i
goto loop
+
done:
.return(retv)
.end
@@ -246,6 +257,12 @@
retv = new 'List'
start_pos = 0
+ # per Perl 5's negative LIMIT behavior
+ unless has_count goto positive_count
+ unless count < 1 goto positive_count
+ has_count = 0
+
+ positive_count:
match = regex($S0)
if match goto loop
retv.'push'($S0)
@@ -254,7 +271,10 @@
loop:
unless has_count goto skip_count
dec count
- if count < 0 goto done
+ unless count < 1 goto skip_count
+ $S1 = substr $S0, start_pos
+ retv.'push'($S1)
+ goto done
skip_count:
match = regex($S0, 'continue' => start_pos)
end_pos = match.'from'()
|
From @moritzOn Mon Sep 22 22:55:29 2008, cdavaz wrote:
Sorry, I've lost track of your patches (probably due to our parallel |
From cdavaz@gmail.comNope, that last one was it. Still waiting on a decision for how edge On Thu, Sep 25, 2008 at 10:49 PM, Moritz Lenz via RT
|
From @masak<ron_> rakudo: say 102030405.split(0).perl; |
@masak - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#59184 (status was 'resolved')
Searchable as RT59184$
The text was updated successfully, but these errors were encountered: