Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make chop/.chop first class citizens
  • Loading branch information
lizmat committed Apr 23, 2015
1 parent b0e7a59 commit 0c0eb13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/core/Cool.pm
Expand Up @@ -120,8 +120,8 @@ my class Cool { # declared in BOOTSTRAP
self.Str.chomp;
}

method chop() {
self.Str.chop
method chop(Int() $n = 1) {
self.Str.chop($n)
}

method ord(--> Int) {
Expand Down Expand Up @@ -301,7 +301,7 @@ my class Cool { # declared in BOOTSTRAP
}
Metamodel::ClassHOW.exclude_parent(Cool);

sub chop(Cool $s) returns Str { $s.chop }
sub chop(Cool $s, Int() $n = 1) returns Str { $s.chop($n) }
sub chomp(Cool $s) returns Str { $s.chomp }
sub flip(Cool $s) returns Str { $s.flip }
sub index(Cool $s,$needle,$pos=0) { $s.index($needle,$pos) }
Expand Down
7 changes: 4 additions & 3 deletions src/core/Str.pm
Expand Up @@ -97,9 +97,10 @@ my class Str does Stringy { # declared in BOOTSTRAP
}
}

method chop(Str:D: $chars = 1) {
my str $sself = nqp::unbox_s(self);
nqp::p6box_s(nqp::substr($sself, 0, nqp::chars($sself) - $chars))
method chop(Str:D: Int() $chopping = 1) {
my str $str = nqp::unbox_s(self);
my int $chars = nqp::chars($str) - $chopping;
$chars > 0 ?? nqp::p6box_s(nqp::substr($str,0,$chars)) !! '';
}

# chars used to handle ranges for pred/succ
Expand Down

0 comments on commit 0c0eb13

Please sign in to comment.