Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement Cool.ends-with, inspired by lucasb++
  • Loading branch information
lizmat committed Apr 8, 2015
1 parent 993c659 commit eb05181
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/core/Cool.pm
Expand Up @@ -154,6 +154,22 @@ my class Cool { # declared in BOOTSTRAP
);
}

proto method ends-with(Str(Cool) $suffix) { * }
multi method ends-with(Str:D: Str(Cool) $suffix) {
my str $str = nqp::unbox_s(self);
my str $needle = nqp::unbox_s($suffix);
nqp::p6bool(
nqp::eqat($str,$needle,nqp::chars($str) - nqp::chars($needle))
);
}
multi method ends-with(Cool:D: Str(Cool) $suffix) {
my str $str = nqp::unbox_s(self.Str);
my str $needle = nqp::unbox_s($suffix);
nqp::p6bool(
nqp::eqat($str,$needle,nqp::chars($str) - nqp::chars($needle))
);
}

proto method substr-eq-at(|) {*}
multi method substr-eq-at(Str:D: Str(Cool) $needle, Int(Cool) $pos) {
nqp::p6bool(
Expand Down

0 comments on commit eb05181

Please sign in to comment.