[phobos] std.path cleanup

Walter Bright walter at digitalmars.com
Fri Apr 23 03:58:00 PDT 2010



Lars Tandle Kyllingstad wrote:
> I have a few suggestions for improvements to std.path, and if people 
> agree, I'll be happy to implement them:
>
>
> 1. Cross-platform path handling:
>
> Since most of std.path only deals with strings, and therefore doesn't 
> perform any OS-specific operations, there is really no reason to 
> completely hide the Windows path handling stuff from POSIX users and 
> vice versa.
>
> I therefore propose to put the Windows stuff in a WindowsPath 
> namespace and the POSIX stuff in a PosixPath namespace, implemented as 
> structs with only static members.

Aack, I think this approach just makes things more complicated.

>
> The module-level functions stay -- after all, a POSIX user will want 
> to deal with POSIX paths most of the time -- but now as aliases of 
> either PosixPath or WindowsPath member functions, depending on which 
> OS the library is compiled for.
>
>
> 2. Consistent naming:
>
>   sep       -> dirSeparator
>   pathsep   -> pathSeparator
>   isabs()   -> isAbsolute()
>   rel2abs() -> toAbsolute()
>   getExt()  -> extension()

Don't want to break existing code.

>
>
> 3. Add some useful stuff, like the toCanonical() function I have in my 
> personal library (it's like rel2abs, except it also resolves ../ and ./).

Sounds good.

>
>
> 4. Change the type of sep, altsep, etc. to immutable string.  (Or is 
> there a good reason why they're all _static_ arrays?)

Sounds good.

>
>
> 5. Get rid of the legacy stuff (specifically, the getBaseName and 
> getDirName aliases).  Now's a good a time as any.

What's wrong with them?

>
>
> 6. Fix bugs.  Some are in Bugzilla, and there are a couple which I've 
> found quite recently but haven't gotten around to reporting yet:
>
>   * join("", "foo") returns "/foo", should be "foo".

Ok.

>
>   * On POSIX, getExt("/tmp/.foo") returns "foo", should be ""
>     (it's the name of a hidden file, not an extension).

What is the pattern that separates hidden file from extension?

>
>
>
> Whatcha think?
>
> -Lars
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
>
>


More information about the phobos mailing list