Proposal for std.path replacement

Regan Heath regan at netmail.co.nz
Mon Mar 7 02:25:21 PST 2011


On Sun, 06 Mar 2011 08:37:15 -0000, Rainer Schuetze <r.sagitario at gmx.de>  
wrote:

> Looks good overall. I have a few comments and nitpicks though:
>
>  >   basename("dir/subdir/")             -->  "subdir"
>  >   directory("dir/subdir/")      -->  "dir"
>
> Is this what everybody expects? I'm not sure, but another possibility  
> would be to treat these as if "dir/subdir/." is passed. What is the  
> result of directory("/") or directory("d:/")?

?? I would expect:

   directory("dir/subdir/")      -->  "dir/subdir"

as subdir _is_ a dir, not a file, as shown by the trailing slash.  If it  
was:

   directory("dir/subdir")      -->  "dir"

as subdir is perhaps not a directory, as there is no trailing slash.

I realise this means the trailing slash becomes important, but it kinda is  
important as it does tell us when something is definitely a directory.

Alternately, we could ignore the distinction between file and directory -  
as we're essentially just parsing strings here - and have two functions:

lastComponent("dir/subdir/")  -> "subdir"
lastComponent("dir/subdir")   -> "subdir"

allButLastComponent("dir/subdir/") -> "dir/"
allButLastComponent("dir/subdir")  -> "dir/"


-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d mailing list