Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add MAKE-EXTENSION, fix MAKE-BASENAME
  • Loading branch information
lizmat committed Nov 1, 2014
1 parent 685ee66 commit 86af5ee
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/core/IO.pm
Expand Up @@ -3,6 +3,7 @@ my role IO {
method umask { state $ = :8( qx/umask/.chomp ) }
}

#===============================================================================
# Primitives that may live in a role someday, if we figure out how to do that
# in a sensible and performant way. Until then, these global subs with slightly
# obfuscated names, will have to do. They should also provide excellent
Expand All @@ -29,10 +30,19 @@ sub MAKE-ABSOLUTE-PATH($path,$abspath) {
}

sub MAKE-BASENAME($abspath) {
my int $index = nqp::rindex(nqp::unbox_s($abspath),'/');
my str $abspath_s = nqp::unbox_s($abspath);
my int $index = nqp::rindex($abspath_s,'/');
nqp::p6bool($index == -1)
?? $abspath
!! $abspath.substr( nqp::box_i($index + 1,Int) );
!! nqp::box_s(nqp::substr($abspath_s,$index + 1),Str);
}

sub MAKE-EXTENSION($basename) {
my str $basename_s = nqp::unbox_s($basename);
my int $index = nqp::rindex($basename_s,'.');
nqp::p6bool($index == -1)
?? ''
!! nqp::box_s(nqp::substr($basename_s,$index + 1),Str);
}

sub FILETEST-E($abspath) {
Expand Down

0 comments on commit 86af5ee

Please sign in to comment.