Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
d744c997
Commit
d744c997
authored
Feb 07, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/Traits: add function Relative()
Move code from Path::RelativeFS() and make it generic.
parent
6b421cc3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
23 deletions
+61
-23
Path.cxx
src/fs/Path.cxx
+0
-22
Path.hxx
src/fs/Path.hxx
+3
-1
Traits.cxx
src/fs/Traits.cxx
+40
-0
Traits.hxx
src/fs/Traits.hxx
+18
-0
No files found.
src/fs/Path.cxx
View file @
d744c997
...
...
@@ -26,25 +26,3 @@ Path::ToUTF8() const
{
return
::
PathToUTF8
(
c_str
());
}
const
char
*
Path
::
RelativeFS
(
const
char
*
other_fs
)
const
{
const
size_t
l
=
length
();
if
(
memcmp
(
data
(),
other_fs
,
l
)
!=
0
)
return
nullptr
;
other_fs
+=
l
;
if
(
*
other_fs
!=
0
)
{
if
(
!
PathTraitsFS
::
IsSeparator
(
*
other_fs
))
/* mismatch */
return
nullptr
;
/* skip remaining path separators */
do
{
++
other_fs
;
}
while
(
PathTraitsFS
::
IsSeparator
(
*
other_fs
));
}
return
other_fs
;
}
src/fs/Path.hxx
View file @
d744c997
...
...
@@ -135,7 +135,9 @@ public:
* nullptr on mismatch.
*/
gcc_pure
const
char
*
RelativeFS
(
const
char
*
other_fs
)
const
;
const
char
*
RelativeFS
(
const
char
*
other_fs
)
const
{
return
PathTraitsFS
::
Relative
(
value
,
other_fs
);
}
gcc_pure
bool
IsAbsolute
()
{
...
...
src/fs/Traits.cxx
View file @
d744c997
...
...
@@ -78,6 +78,34 @@ GetParentPathImpl(typename Traits::const_pointer p)
return
typename
Traits
::
string
(
p
,
sep
);
}
template
<
typename
Traits
>
typename
Traits
::
const_pointer
RelativePathImpl
(
typename
Traits
::
const_pointer
base
,
typename
Traits
::
const_pointer
other
)
{
assert
(
base
!=
nullptr
);
assert
(
other
!=
nullptr
);
const
auto
base_length
=
Traits
::
GetLength
(
base
);
if
(
memcmp
(
base
,
other
,
base_length
*
sizeof
(
*
base
))
!=
0
)
/* mismatch */
return
nullptr
;
other
+=
base_length
;
if
(
other
!=
0
)
{
if
(
!
Traits
::
IsSeparator
(
*
other
))
/* mismatch */
return
nullptr
;
/* skip remaining path separators */
do
{
++
other
;
}
while
(
Traits
::
IsSeparator
(
*
other
));
}
return
other
;
}
PathTraitsFS
::
string
PathTraitsFS
::
Build
(
PathTraitsFS
::
const_pointer
a
,
size_t
a_size
,
PathTraitsFS
::
const_pointer
b
,
size_t
b_size
)
...
...
@@ -97,6 +125,12 @@ PathTraitsFS::GetParent(PathTraitsFS::const_pointer p)
return
GetParentPathImpl
<
PathTraitsFS
>
(
p
);
}
PathTraitsFS
::
const_pointer
PathTraitsFS
::
Relative
(
const_pointer
base
,
const_pointer
other
)
{
return
RelativePathImpl
<
PathTraitsFS
>
(
base
,
other
);
}
PathTraitsUTF8
::
string
PathTraitsUTF8
::
Build
(
PathTraitsUTF8
::
const_pointer
a
,
size_t
a_size
,
PathTraitsUTF8
::
const_pointer
b
,
size_t
b_size
)
...
...
@@ -115,3 +149,9 @@ PathTraitsUTF8::GetParent(PathTraitsUTF8::const_pointer p)
{
return
GetParentPathImpl
<
PathTraitsUTF8
>
(
p
);
}
PathTraitsUTF8
::
const_pointer
PathTraitsUTF8
::
Relative
(
const_pointer
base
,
const_pointer
other
)
{
return
RelativePathImpl
<
PathTraitsUTF8
>
(
base
,
other
);
}
src/fs/Traits.hxx
View file @
d744c997
...
...
@@ -106,6 +106,15 @@ struct PathTraitsFS {
static
string
GetParent
(
const_pointer
p
);
/**
* Determine the relative part of the given path to this
* object, not including the directory separator. Returns an
* empty string if the given path equals this object or
* nullptr on mismatch.
*/
gcc_pure
gcc_nonnull_all
static
const_pointer
Relative
(
const_pointer
base
,
const_pointer
other
);
/**
* Constructs the path from the given components.
* If either of the components is empty string,
* remaining component is returned unchanged.
...
...
@@ -180,6 +189,15 @@ struct PathTraitsUTF8 {
static
string
GetParent
(
const_pointer
p
);
/**
* Determine the relative part of the given path to this
* object, not including the directory separator. Returns an
* empty string if the given path equals this object or
* nullptr on mismatch.
*/
gcc_pure
gcc_nonnull_all
static
const_pointer
Relative
(
const_pointer
base
,
const_pointer
other
);
/**
* Constructs the path from the given components.
* If either of the components is empty string,
* remaining component is returned unchanged.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment