Path as an object in std.path

John Colvin john.loughran.colvin at gmail.com
Fri Jun 7 11:33:52 PDT 2013


On Friday, 7 June 2013 at 18:26:42 UTC, Andrei Alexandrescu wrote:
> On 6/7/13 2:10 PM, monarch_dodra wrote:
>> On Friday, 7 June 2013 at 17:27:16 UTC, Andrei Alexandrescu 
>> wrote:
>>> On 6/7/13 1:04 PM, monarch_dodra wrote:
>>>> I think using string as the main form of representation for 
>>>> a path is
>>>> fine.
>>>>
>>>> However, there are times where it is convenient to be able 
>>>> to explode a
>>>> path into a structure, where each part is clearly separate 
>>>> from the
>>>> next.
>>>
>>> Tuple!(
>>> string, "drive",
>>> string[], "folders",
>>> string, "basename",
>>> string, "extension"
>>> )
>>> parsePath(string path);
>>>
>>> string buildPath(string drive, string[] folders, string 
>>> basename,
>>> string extension);
>>>
>>>
>>> Andrei
>>
>> Yeah. That's pretty much more or less what I was describing. 
>> Except
>> "buildPath" would take your (unnamed) tuple type directly.
>
> No, the version I wrote is more flexible. You get to pass 
> separate arguments to it or just pass a tuple with .expand.
>
> buildPath(parsePath("/bin/sh").expand)
>
> should rebuild "/bin/sh".
>
>> There'd be also be a "filename" member/ufcs function in there 
>> for
>> convenience.
>>
>> I think that would be a small, but useful, addition to 
>> std.path.
>
> Me 2.
>
>
> Andrei

An overload for buildPath that took the tuple directly would be 
good. Typing expand all the time would get tiresome if you were 
doing lots of this.


More information about the Digitalmars-d mailing list