Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Simox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Leander Singer
Simox
Commits
676f7275
Commit
676f7275
authored
2 years ago
by
Rainer Kartmann
Browse files
Options
Downloads
Patches
Plain Diff
Format
parent
b6bf9f15
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SimoxUtility/filesystem/make_relative.h
+9
-4
9 additions, 4 deletions
SimoxUtility/filesystem/make_relative.h
with
9 additions
and
4 deletions
SimoxUtility/filesystem/make_relative.h
+
9
−
4
View file @
676f7275
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment