Skip to content

Commit

Permalink
Fix String.each to actually work as it should, also have it respect $/.
Browse files Browse the repository at this point in the history
Fixes #17.
  • Loading branch information
treed committed Aug 7, 2009
1 parent 7f9db1a commit 34e0fdb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
26 changes: 22 additions & 4 deletions src/classes/String.pir
Expand Up @@ -156,11 +156,29 @@ Returns the characters in C<self> in reverse order. Destructive update.
.end

.sub 'each' :method :multi('CardinalString',_)
.param pmc delim
.param pmc delim :optional
.param int delim_flag :opt_flag
.param pmc block :named('!BLOCK')
.local pmc list
list = self.'split'(delim)
list.'each'(block)
.local pmc str, iterator
if delim_flag goto have_delim
delim = get_hll_global '$/'
have_delim:
iterator = iter self
str = new 'CardinalString'
main_loop:
unless iterator goto loop_end
$P0 = shift iterator
str.'concat'($P0)
unless $P0 == delim goto main_loop
block(str)
str = new 'CardinalString'
goto main_loop
loop_end:
$P0 = str.'empty?'()
if $P0 goto done
block(str)
done:
.return (self)
.end

.sub 'empty?' :method
Expand Down
2 changes: 0 additions & 2 deletions t/string/block.t
Expand Up @@ -24,11 +24,9 @@ parrot = 'parrot'
i = 0
parrot.each('r') do |split|
if i == 0
todo "Fix String.each(char)", "17"
is split, 'par', '.each(char) for String'
end
if i == 1
todo "Fix String.each(char)", "17"
is split, 'r', '.each(char) for String'
end
if i == 2
Expand Down

0 comments on commit 34e0fdb

Please sign in to comment.