Add relative path method and normalize parent references
I added a method which computes the relative path which goes between two paths. I added this downstream to yonaskolb/XcodeGen#524, but since it seems generally useful I figured I'd try to add it back to PathKit. This is similar to Pathname#relative_path_from in the ruby stdlib and PurePath.relative_to in python. Let me know if this is something you'd be interested in adding, and if there's anything I can do to help!
Declaration
/// Returns the relative path necessary to go from `base` to `self`.
///
/// Both paths must be absolute or relative paths.
/// - throws: Throws an error when the path types do not match, or when `base` has so many parent path components
/// that it refers to an unknown parent directory.
public func relativePath(from base: Path) throws -> Path
Examples
Path("a/b").relativePath(from: Path("a/c")) == Path("../b")
Path("/a/b/c/d").relativePath(from: Path("/a/b")) == Path("c/d")
Path("/a/../../b").relativePath(from: Path("/b")) == Path(".")
Changes to normalize()
One would expect that a path like "a/../../b" could normalize to "b". Foundation's standardizingPath method only removes redundant parent directory references if the path is absolute, so "/a/../../b" normalizes to "/b" but the former case doesn't normalize at all. I realized that PathKit already has logic to remove redundant ".."s in its + operator, so I added a case to normalize() that adds up all the path components if the path is relative.