[phobos] std.path proof of concept

Lars Tandle Kyllingstad lars at kyllingen.net
Wed Apr 28 01:43:55 PDT 2010


Sorry, sent this to Andrei's private address again...

On 04/27/2010 09:51 PM, Andrei Alexandrescu wrote:
> 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.

Good point.


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

I completely agree with you.

It's not a case of *adding* support, however.  getExt() and defaultExt() 
are already in the current std.path, so what you're suggesting is 
*removing* support.

I don't mind, but I'm sure it won't sit well with everyone.  Like it or 
not -- and I sure don't -- extensions are still the primary way of 
conveying file type information.


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

Good idea.  I just realised it's kinda pointless to have both filename() 
and basename() as well.


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

The same as the current std.path.fncharmatch():  On POSIX 
fncharmatch('a','A') is false but on Windows it's true.

I'm not convinced any of these last three are generally useful, but 
again, I am wary of *removing* functionality.

-Lars


More information about the phobos mailing list