# New Ticket Created by "Chris Davaz" # Please include the string: [perl #59016] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=59016 >
Sorry forgot to put the method in alphabetical order, here you go. On Fri, Sep 19, 2008 at 12:36 AM, Chris Davaz <[EMAIL PROTECTED]> wrote: > Got rid of "tempstr" and now returns the entire string on a non-match. >
Index: src/builtins/any-str.pir =================================================================== --- src/builtins/any-str.pir (revision 31220) +++ src/builtins/any-str.pir (working copy) @@ -71,7 +71,6 @@ .return(retv) .end - =item index() =cut @@ -173,6 +172,42 @@ .return ($P0) .end +=item split(/PATTERN/) + +Splits something on a regular expresion + +=cut + +.sub 'split' :method :multi(_, 'Sub') + .param pmc regex + .local pmc match + .local pmc retv + .local int start_pos + .local int end_pos + + $S0 = self + retv = new 'List' + start_pos = 0 + + match = regex($S0) + if match goto loop + retv.'push'($S0) + goto done + + loop: + match = regex($S0, 'continue' => start_pos) + end_pos = match.'from'() + end_pos -= start_pos + $S1 = substr $S0, start_pos, end_pos + retv.'push'($S1) + unless match goto done + start_pos = match.'to'() + goto loop + + done: + .return(retv) +.end + =item substr() =cut