[phobos] std.path proof of concept

Andrei Alexandrescu andrei at erdani.com
Tue Apr 27 12:51:16 PDT 2010


On 04/27/2010 03:40 AM, Lars Tandle Kyllingstad wrote:
> On 04/27/2010 12:43 AM, Andrei Alexandrescu wrote:
> Below is a listing the API I have in mind. I think it's worth breaking
> backwards compatibility for a more unified and coherent naming scheme,
> and I also think it's better to do it now than later. Walter seemed to
> oppose the idea, what do others think?
>
>
> // System-dependent constants
> string dirSeparator
> string altDirSeparator
> string pathSeparator
> string currentDir
> string parentDir

I'd change "currentDir" with e.g. "currentDirSymbol" or something. 
Otherwise people may actually thing currentDir is pwd. Same about parentDir.

> // File extensions
> string extension(path)
> string setExtension(path, ext)
> string setDefaultExtension(path, ext)
> string appendExtension(path, ext)
> string removeExtension(path, ext=null)

I'm not fond of adding support for extensions. On Unix there's no 
explicit extension. Extension comes from CP/M with 8 characters for name 
and 3 characters for extension, which is now long defunct.

> // Extracting drive/directory/filename
> string drive(path)
> string directory(path)
> string filename(path)
> string basename(path, suffix)

"dirname" will be instantly recognized by any Unix user.

> // Relative/absolute/canonical paths
> bool isAbsolute(path)
> bool isRelative(path)
> bool isCanonical(path)
> string toAbsolute(path)
> string toRelative(path)
> string toCanonical(path)
>
> // Joining/splitting paths
> string join(pathComponents...)
> SomeRange splitter(path) // cf. Ellery Newcomer's suggestion
>
> // Filename matching
> bool wildcardMatch(path, pattern)
> bool filenameMatch(path1, path2)
> bool filenameCharMatch(char1, char2)

What does the last do?


Andrei


More information about the phobos mailing list