D-Programming-Language/phobos — pull request #1333 by dymk (2013-06-05 05:29:39+00:00)
Title: Add `struct Path` to std.path

This adds a struct, `struct Path`, to std.path, which exposes a much more palatable interface to path string manipulation.

## Rationale for adding:
* Adds a (more) platform independent abstraction for path strings.
* Path provides a type safe way to pass, compare, and manipulate arbitrary path strings.
* It wraps over the functions defined in std.path, so behavior of methods on Path are, in most cases, identical to their corresponding module function.

## Some examples of how Path can be used:
### Equality Testing:
```d
Path p1 = `foo/bar/baz`;
assert(p1 == `zaz/../foo/bar/baz`);
Path p2 = `foo/bar/./baz`;
assert(p1 == p2);
```

### Joining with other paths
```d
Path p1 = `foo/bar`;
Path p2 = `baz`;
string s3 = `quix`;
assert(Path.build(p1, p2, p3) == `foo/bar/baz/quix`;
assert(p1.join(p2, p3) == `foo/bar/baz/quix`);
```

### Implicit conversion to a normalized path when passed as a string argument
```d
void doSomething(string path) {
writeln(path);
}

Path p1 = `/path/../to/./some/file`;
p1.doSomething(); //Prints "path/some/file"
```

### Nice OO-style functions that make sense to have on the concept of a path
```d
Path p1 = `/abs/path`;
Path p2 = `rel/path`;

assert(p1.isAbsolute());
assert(p2.isRelative());
assert(p2.toAbsolute(`/abs/base`) == `/abs/base/rel/path`);
assert(p1.toRelative(`/abs`) == `path`);
```
----

Plus, lots of other goodies. I encourage you to take a look at the unittests to get a feel for what the wrapper can do. If I overlooked something important, please let me know! I'd love for this to make it into the standard library.