# New Ticket Created by Vasily Chekalkin # Please include the string: [perl #54766] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=54766 >
Hello. Implementation for Str.substr method with correct handling of negative length. -- Bacek.
Index: src/classes/Str.pir =================================================================== --- src/classes/Str.pir (revision 27780) +++ src/classes/Str.pir (working copy) @@ -229,6 +229,33 @@ .return ($S0) .end +=item substr() + + +=cut + +.sub 'substr' :method + .param int start + .param int len :optional + .param int has_len :opt_flag + .local pmc s + + if has_len goto check_len + len = self.'chars'() + + check_len: + if len > 0 goto end + $I0 = self.'chars'() + len = $I0 + len + len = len - start + + end: + $S0 = substr self, start, len + s = new 'Perl6Str' + s = $S0 + .return (s) +.end + =back =head1 Functions @@ -414,17 +441,11 @@ .param string x .param int start .param int len :optional - .param int has_len :opt_flag .local pmc s - if has_len goto end s = new 'Perl6Str' s = x - len = s.'chars'() - - end: - $S0 = substr x, start, len - .return ($S0) + .return s.'substr'(start, len) .end =item chop