summaryrefslogtreecommitdiff
path: root/src/boost-utils.cc
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2013-03-12 05:14:58 (GMT)
committerMarius Kintel <marius@kintel.net>2013-03-12 05:14:58 (GMT)
commitdccc039211eebe3f69c935557bd56abae323c26f (patch)
treefb39b939619db2bb258de78cf38012919762fbbc /src/boost-utils.cc
parent6b8a5e266ca1725e35e76aef0caa639fe77fdc48 (diff)
Got rid of remaining Qt dependencies. The test framework should now be Qt-free
Diffstat (limited to 'src/boost-utils.cc')
-rw-r--r--src/boost-utils.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/boost-utils.cc b/src/boost-utils.cc
new file mode 100644
index 0000000..f81917a
--- /dev/null
+++ b/src/boost-utils.cc
@@ -0,0 +1,42 @@
+#include "boost-utils.h"
+#include <stdio.h>
+#include <iostream>
+
+fs::path relativePath(const fs::path &path, const fs::path &relative_to)
+{
+ // create absolute paths
+ fs::path p = fs::absolute(path);
+ fs::path r = fs::absolute(relative_to);
+
+ // if root paths are different, return absolute path
+ if (p.root_path() != r.root_path())
+ return p;
+
+ // initialize relative path
+ fs::path result;
+
+ // find out where the two paths diverge
+ fs::path::const_iterator itr_path = p.begin();
+ fs::path::const_iterator itr_relative_to = r.begin();
+ while (*itr_path == *itr_relative_to && itr_path != p.end() && itr_relative_to != r.end()) {
+ ++itr_path;
+ ++itr_relative_to;
+ }
+
+ // add "../" for each remaining token in relative_to
+ if (itr_relative_to != r.end()) {
+ ++itr_relative_to;
+ while (itr_relative_to != r.end()) {
+ result /= "..";
+ ++itr_relative_to;
+ }
+ }
+
+ // add remaining path
+ while (itr_path != p.end()) {
+ result /= *itr_path;
+ ++itr_path;
+ }
+
+ return result;
+}
contact: Jan Huwald // Impressum