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
0080eee8
Commit
0080eee8
authored
Apr 03, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/Traits: add Relative() overload with std::string_view
parent
2429cc87
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
0 deletions
+49
-0
Traits.cxx
src/fs/Traits.cxx
+43
-0
Traits.hxx
src/fs/Traits.hxx
+6
-0
No files found.
src/fs/Traits.cxx
View file @
0080eee8
...
...
@@ -117,6 +117,37 @@ RelativePathImpl(typename Traits::string_view base,
return
other
;
}
template
<
typename
Traits
>
typename
Traits
::
string_view
RelativePathImpl
(
typename
Traits
::
string_view
base
,
typename
Traits
::
string_view
_other
)
noexcept
{
BasicStringView
<
typename
Traits
::
value_type
>
other
(
_other
);
if
(
!
other
.
SkipPrefix
(
base
))
/* mismatch */
return
{};
if
(
!
other
.
empty
())
{
if
(
!
Traits
::
IsSeparator
(
other
.
front
()))
{
if
(
!
base
.
empty
()
&&
Traits
::
IsSeparator
(
other
.
data
[
-
1
]))
/* "other" has no more slash, but the
matching base ended with a slash:
enough to detect a match */
return
other
;
/* mismatch */
return
{};
}
/* skip remaining path separators */
while
(
!
other
.
empty
()
&&
Traits
::
IsSeparator
(
other
.
front
()))
other
.
pop_front
();
}
return
other
;
}
PathTraitsFS
::
string
PathTraitsFS
::
Build
(
string_view
a
,
string_view
b
)
noexcept
{
...
...
@@ -141,6 +172,12 @@ PathTraitsFS::Relative(string_view base, const_pointer other) noexcept
return
RelativePathImpl
<
PathTraitsFS
>
(
base
,
other
);
}
PathTraitsFS
::
string_view
PathTraitsFS
::
Relative
(
string_view
base
,
string_view
other
)
noexcept
{
return
RelativePathImpl
<
PathTraitsFS
>
(
base
,
other
);
}
PathTraitsFS
::
string
PathTraitsFS
::
Apply
(
const_pointer
base
,
const_pointer
path
)
noexcept
{
...
...
@@ -178,3 +215,9 @@ PathTraitsUTF8::Relative(string_view base, const_pointer other) noexcept
{
return
RelativePathImpl
<
PathTraitsUTF8
>
(
base
,
other
);
}
PathTraitsUTF8
::
string_view
PathTraitsUTF8
::
Relative
(
string_view
base
,
string_view
other
)
noexcept
{
return
RelativePathImpl
<
PathTraitsUTF8
>
(
base
,
other
);
}
src/fs/Traits.hxx
View file @
0080eee8
...
...
@@ -149,6 +149,9 @@ struct PathTraitsFS {
gcc_pure
gcc_nonnull_all
static
const_pointer
Relative
(
string_view
base
,
const_pointer
other
)
noexcept
;
gcc_pure
static
string_view
Relative
(
string_view
base
,
string_view
other
)
noexcept
;
/**
* Constructs the path from the given components.
* If either of the components is empty string,
...
...
@@ -257,6 +260,9 @@ struct PathTraitsUTF8 {
gcc_pure
gcc_nonnull_all
static
const_pointer
Relative
(
string_view
base
,
const_pointer
other
)
noexcept
;
gcc_pure
static
string_view
Relative
(
string_view
base
,
string_view
other
)
noexcept
;
/**
* Constructs the path from the given components.
* If either of the components is empty string,
...
...
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