Subject: Re: [Boost-bugs] [Boost C++ Libraries] #1976: Inverse function for complete
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-08-22 00:56:15
#1976: Inverse function for complete
--------------------------------------+-------------------------------------
Reporter: me22.ca+boost_at_[hidden] | Owner: bemandawes
Type: Feature Requests | Status: new
Milestone: Boost 1.36.0 | Component: filesystem
Version: Boost 1.35.0 | Severity: Problem
Resolution: | Keywords:
--------------------------------------+-------------------------------------
Comment(by anonymous):
Here's a naive implementation (that doesn't handle symlinks and isn't well
tested):
{{{
#include <boost/filesystem.hpp>
boost::filesystem::path
naive_uncomplete(boost::filesystem::path const path,
boost::filesystem::path const base) {
if (path.has_root_path()){
if (path.root_path() != base.root_path()) {
return path;
} else {
return naive_uncomplete(path.relative_path(),
base.relative_path());
}
} else {
if (base.has_root_path()) {
throw "cannot uncomplete a path relative path from a rooted
base";
} else {
typedef boost::filesystem::path::const_iterator path_iterator;
path_iterator path_it = path.begin();
path_iterator base_it = base.begin();
while ( path_it != path.end() && base_it != base.end() ) {
if (*path_it != *base_it) break;
++path_it; ++base_it;
}
boost::filesystem::path result;
for (; base_it != base.end(); ++base_it) {
result /= "..";
}
for (; path_it != path.end(); ++path_it) {
result /= *path_it;
}
return result;
}
}
}
}}}
-- Ticket URL: <http://svn.boost.org/trac/boost/ticket/1976#comment:2> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:58 UTC