function for inverse relative path?

Timothee Cour thelastmammoth at gmail.com
Thu Dec 7 04:39:25 UTC 2017


how about:
```
string inverseRelativePath(string root, string rel){
while(true){
if(rel.empty || rel==".") {
return root;
}
auto a1=root.baseName;
auto a2=rel.baseName;
enforce(a1==a2, text(root, " ", rel));
root=root.dirName;
rel=rel.dirName;
}
}

unittest{
import std.exception;
auto a="/a/b/c.d";
auto b="b/c.d";
assert(inverseRelativePath(a, b) == "/a");
assertThrown(inverseRelativePath(a, "c2.d"));
}
```


On Wed, Dec 6, 2017 at 5:36 PM, Timothee Cour <thelastmammoth at gmail.com> wrote:
> what would be a robust way to do this `inverseRelativePath`, and
> should that be in std.path?
>
> ```
> auto a="/a/b/c.d";
> auto b="b/c.d";
> assert(inverseRelativePath(a, b) == "/a");
> assertThrown(inverseRelativePath(a, "c2.d"));
> ```


More information about the Digitalmars-d mailing list