Skip to content

Commit

Permalink
Merge pull request #2324 from MartinNowak/fix13098
Browse files Browse the repository at this point in the history
[REG2.066a] Issue 13098 - std.path functions no longer works with DirEntry
  • Loading branch information
9rnsr committed Jul 15, 2014
1 parent 02c8b31 commit ec44674
Showing 1 changed file with 46 additions and 17 deletions.
63 changes: 46 additions & 17 deletions std/path.d
Expand Up @@ -390,13 +390,8 @@ unittest
static assert (baseName("dir/file.ext") == "file.ext");
static assert (baseName("dir/file.ext", ".ext") == "file");

struct DirEntry
{
alias name this;
@property string name() { return ""; }
}
DirEntry de;
auto a = de.baseName;
static struct DirEntry { string s; alias s this; }
assert(baseName(DirEntry("dir/file.ext")) == "file.ext");
}


Expand Down Expand Up @@ -690,8 +685,6 @@ private ptrdiff_t extSeparatorPos(R)(const R path)
}




/** Returns the _extension part of a file name, including the dot.
If there is no _extension, $(D null) is returned.
Expand Down Expand Up @@ -722,6 +715,12 @@ auto extension(R)(R path)
}


inout(C)[] extension(C)(inout(C)[] path)
{
return extension!(inout(C)[])(path);
}


unittest
{
assert (extension("file").empty);
Expand Down Expand Up @@ -764,6 +763,9 @@ unittest
foreach (i, c; `.ext2`)
assert(s[i] == c);
}

static struct DirEntry { string s; alias s this; }
assert (extension(DirEntry("file")).empty);
}


Expand Down Expand Up @@ -1851,6 +1853,13 @@ bool isRooted(R)(const R path)
}


bool isRooted(C)(const(C)[] path)
if (isSomeChar!C)
{
return isRooted!(const(C)[])(path);
}


unittest
{
assert (isRooted("/"));
Expand All @@ -1870,6 +1879,9 @@ unittest

static assert (isRooted("/foo"));
static assert (!isRooted("foo"));

static struct DirEntry { string s; alias s this; }
assert (!isRooted(DirEntry("foo")));
}


Expand Down Expand Up @@ -1906,17 +1918,31 @@ unittest
}
---
*/
version (StdDdoc) bool isAbsolute(C)(in C[] path) @safe pure nothrow @nogc
if (isSomeChar!C);

else version (Windows) bool isAbsolute(R)(const R path)
if (isRandomAccessRange!R && isSomeChar!(ElementType!R) ||
isSomeString!R)
version (StdDdoc)
{
return isDriveRoot(path) || isUNC(path);
bool isAbsolute(R)(const R path) @safe pure nothrow @nogc
if (isRandomAccessRange!R && isSomeChar!(ElementType!R) ||
isSomeString!R);
}
else version (Windows)
{
bool isAbsolute(R)(const R path) @safe pure nothrow @nogc
if (isRandomAccessRange!R && isSomeChar!(ElementType!R) ||
isSomeString!R)
{
return isDriveRoot(path) || isUNC(path);
}

else version (Posix) alias isAbsolute = isRooted;
bool isAbsolute(C)(const(C)[] path) @safe pure nothrow @nogc
if (isSomeChar!C)
{
return isAbsolute!(const(C)[])(path);
}
}
else version (Posix)
{
alias isAbsolute = isRooted;
}


unittest
Expand Down Expand Up @@ -1948,6 +1974,9 @@ unittest
auto r = MockRange!(immutable(char))(`../foo`);
assert(!r.isAbsolute());
}

static struct DirEntry { string s; alias s this; }
assert(!isAbsolute(DirEntry("foo")));
}


Expand Down

0 comments on commit ec44674

Please sign in to comment.