Skip to content
Snippets Groups Projects
Commit 676f7275 authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Format

parent b6bf9f15
No related branches found
No related tags found
No related merge requests found
......@@ -5,16 +5,21 @@
namespace simox::fs
{
//! Return path when appended to a_From will resolve to same as a_To
inline std::filesystem::path make_relative(std::filesystem::path a_From, std::filesystem::path a_To)
inline std::filesystem::path
make_relative(std::filesystem::path a_From, std::filesystem::path a_To)
{
a_From = std::filesystem::canonical(a_From);
a_To = std::filesystem::canonical(a_To);
std::filesystem::path ret;
std::filesystem::path::const_iterator itrFrom(a_From.begin()), itrTo(a_To.begin());
// Find common base
for (std::filesystem::path::const_iterator toEnd(a_To.end()), fromEnd(a_From.end()); itrFrom != fromEnd && itrTo != toEnd && *itrFrom == *itrTo; ++itrFrom, ++itrTo);
for (std::filesystem::path::const_iterator toEnd(a_To.end()), fromEnd(a_From.end());
itrFrom != fromEnd && itrTo != toEnd && *itrFrom == *itrTo;
++itrFrom, ++itrTo)
;
// Navigate backwards in directory to reach previously found base
for (std::filesystem::path::const_iterator fromEnd(a_From.end()); itrFrom != fromEnd; ++itrFrom)
for (std::filesystem::path::const_iterator fromEnd(a_From.end()); itrFrom != fromEnd;
++itrFrom)
{
if ((*itrFrom) != ".")
ret /= "..";
......@@ -25,4 +30,4 @@ namespace simox::fs
ret /= *itrTo;
return ret;
}
}
} // namespace simox::fs
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment