[phobos] std.path proof of concept

Lars Tandle Kyllingstad lars at kyllingen.net
Tue Apr 27 01:40:15 PDT 2010


On 04/27/2010 12:43 AM, Andrei Alexandrescu wrote:
> How about this: we focus on an API that allows you to use the alternate
> separator on Windows ("/") for virtually all Posix primitives. At least
> in theory, a Windows path without a drive is a Posix path.

Alright, I won't push it any further. ;)  What you're suggesting will 
cover many use cases, and like I said, it's not *that* important to me.

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

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

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

// 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)


-Lars


More information about the phobos mailing list