]> git.tdb.fi Git - libs/core.git/blobdiff - source/utils.cpp
Add relative() to utils
[libs/core.git] / source / utils.cpp
index 08ab9586a31700ed9a1399b35187caba5472f37c..204f33bfdedcf841e6b4b4e0e090d9caa1824d67 100644 (file)
@@ -158,5 +158,20 @@ int fnmatch(const string &pat, const Path &fn)
 #endif
 }
 
+Path relative(const Path &path, const Path &base)
+{
+       Path::iterator i=path.begin();
+       Path::iterator j=base.begin();
+       for(; (i!=path.end() && j!=base.end() && *i==*j); ++i,++j);
+
+       Path result;
+       for(; j!=base.end(); ++j)
+               result/="..";
+       for(; i!=path.end(); ++i)
+               result/=*i;
+
+       return result;
+}
+
 } // namespace Path
 } // namespace Msp