std.path review: update

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Thu Jul 21 02:38:15 PDT 2011


On Thu, 21 Jul 2011 03:36:37 -0400, Jussi Jumppanen wrote:

> Lars T. Kyllingstad Wrote:
> 
>> On Wed, 20 Jul 2011 14:16:04 -0400, Steven Schveighoffer wrote:
>>
>> Any .NET programmers out there?  Can you please tell me what the
>> following functions return?
>> 
>>   System.IO.Path.GetDirectoryName("\\foo\bar")
>>   System.IO.Path.GetPathRoot("\\foo\bar\baz")
> 
> This code:
>   using System;
>   
>   namespace Test
>   {
>      static class Program
>      {
>         [STAThread]
>         static void Main()
>         {
>            string test;
>   
>            test = @"\\foo\bar\";
>            Console.WriteLine("System.IO.Path.GetDirectoryName(" + test +
>            ")");
>            Console.WriteLine(System.IO.Path.GetDirectoryName(test));
>   
>            test = @"\\foo\bar";
>            Console.WriteLine("System.IO.Path.GetDirectoryName(" + test +
>            ")");
>            Console.WriteLine(System.IO.Path.GetDirectoryName(test));
>   
>            test = @"\\foo\bar\baz";
>            Console.WriteLine("System.IO.Path.GetDirectoryName(" + test +
>            ")"); Console.WriteLine(System.IO.Path.GetPathRoot(test));
>         }
>      }
>   }
> 
> produced this output:
> 
>   C:\temp>test.exe
>   System.IO.Path.GetDirectoryName(\\foo\bar\) \\foo\bar
>   System.IO.Path.GetDirectoryName(\\foo\bar)
>   
>   System.IO.Path.GetDirectoryName(\\foo\bar\baz) \\foo\bar
> 
> Cheers Jussi

Thanks, this is very helpful.  Now we know that MS's APIs treat \\foo\bar 
as a root directory, so we should do the same.  This means that, once I 
get around to implementing it, the following asserts will pass on Windows:

    assert (baseName(`\\foo\bar`) == `\\foo\bar`);
    assert (dirName(`\\foo\bar`) == `\\foo\bar`);
    assert (pathSplitter(`\\foo\bar\baz`).front == `\\foo\bar`);

This is analogous to the following on POSIX (where the behaviour mimics 
that of the basename and dirname shell utilities):

    assert (baseName("/") == "/");
    assert (dirName("/") == "/");
    assert (pathSplitter("/").front == "/");

-Lars


More information about the Digitalmars-d mailing list