diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-01-28 16:00:16 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-01-28 16:00:16 +0000 |
| commit | 15137597824b263c875bd427f7d121eae28d45a6 (patch) | |
| tree | cb6dc61e13822c103ece293f875e85dab24823c0 /src/util.cc | |
| parent | 4126980a15f4f6bb981d0793bd37483456c5bc79 (diff) | |
Various fixes.
Diffstat (limited to 'src/util.cc')
| -rw-r--r-- | src/util.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc index e26e66be..4be026d2 100644 --- a/src/util.cc +++ b/src/util.cc @@ -384,3 +384,26 @@ dcp::fopen_boost (boost::filesystem::path p, string t) return fopen (p.c_str(), t.c_str ()); #endif } + +boost::optional<boost::filesystem::path> +dcp::relative_to_root (boost::filesystem::path root, boost::filesystem::path file) +{ + boost::filesystem::path::const_iterator i = root.begin (); + boost::filesystem::path::const_iterator j = file.begin (); + + while (i != root.end() && j != file.end() && *i == *j) { + ++i; + ++j; + } + + if (i != root.end ()) { + return boost::optional<boost::filesystem::path> (); + } + + boost::filesystem::path rel; + while (j != file.end ()) { + rel /= *j++; + } + + return rel; +} |
