Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make substr handle *-1 style third arg.
  • Loading branch information
jnthn committed Nov 18, 2011
1 parent c732039 commit cf8c0e1
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/core/Str.pm
Expand Up @@ -55,6 +55,7 @@ my class Str does Stringy {
method substr(Str:D: $start, $length? is copy) {
fail "Negative start argument ($start) to .substr" if $start < 0;
fail "Start of substr ($start) beyond end of string" if $start > self.chars;
$length = $length(self.chars - $start) if $length ~~ Callable;
$length = $length.defined ?? $length.Int !! self.chars - $start.Int;
fail "Negative length argument ($length) to .substr" if $length < 0;

Expand Down

0 comments on commit cf8c0e1

Please sign in to comment.