# New Ticket Created by "Chris Davaz" # Please include the string: [perl #58970] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=58970 >
I say "initial" because it didn't pass one of my tests. This might be due to regular expressions not being fully implemented, so if this is the case please let me know. Once I know I'll fix my code if need by and write an appropriate test case and add it to the pugs repo. my Str $test = "theXbiggestXbangXforXtheXbuck"; my List $list = $test.split(/X/); print $list.join("\n"); $test = "<test>tag</test><perl>stripping</perl>"; # Expect the print to give us "tag stripping" however it just yields some whitespace, not sure why $list = $test.split(/\<\/?.*?\>/); print $list.join(" ");
Index: src/classes/Str.pir =================================================================== --- src/classes/Str.pir (revision 31205) +++ src/classes/Str.pir (working copy) @@ -46,7 +46,7 @@ .return(retv) .end -.sub 'split' :method :multi('String') +.sub 'split' :method :multi(_, 'String') .param string delim .local string objst .local pmc pieces @@ -76,6 +76,50 @@ .return(retv) .end +# split a string on a regex +.sub 'split' :method :multi(_, 'Sub') + .param pmc regex + .local pmc match + .local pmc tmpstr + .local pmc retv + .local int start_pos + .local int end_pos + + retv = new 'List' + + match = regex.'ACCEPTS'(self) + unless match goto done + + start_pos = 0 + end_pos = match.'from'() + + loop: + tmpstr = new 'Perl6Str' + $S0 = substr self, start_pos, end_pos + tmpstr = $S0 + retv.'push'(tmpstr) + + start_pos = match.'to'() + + match.'next'() + + end_pos = match.'from'() + end_pos -= start_pos + + $S1 = match.'text'() + if $S1 == '' goto last + goto loop + + last: + tmpstr = new 'Perl6Str' + $S0 = substr self, start_pos, end_pos + tmpstr = $S0 + retv.'push'(tmpstr) + + done: + .return(retv) +.end + .sub lc :method .local string tmps .local pmc retv