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
332f480e
Commit
332f480e
authored
Mar 13, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/UriExtract: uri_get_path() returns std::string_view
parent
9a164668
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
32 deletions
+41
-32
CurlStorage.cxx
src/storage/plugins/CurlStorage.cxx
+8
-8
UriExtract.cxx
src/util/UriExtract.cxx
+27
-18
UriExtract.hxx
src/util/UriExtract.hxx
+3
-3
UriRelative.cxx
src/util/UriRelative.cxx
+3
-3
No files found.
src/storage/plugins/CurlStorage.cxx
View file @
332f480e
...
@@ -456,11 +456,11 @@ CurlStorage::GetInfo(const char *uri_utf8, gcc_unused bool follow)
...
@@ -456,11 +456,11 @@ CurlStorage::GetInfo(const char *uri_utf8, gcc_unused bool follow)
}
}
gcc_pure
gcc_pure
static
const
char
*
static
std
::
string_view
UriPathOrSlash
(
const
char
*
uri
)
noexcept
UriPathOrSlash
(
const
char
*
uri
)
noexcept
{
{
const
char
*
path
=
uri_get_path
(
uri
);
auto
path
=
uri_get_path
(
uri
);
if
(
path
==
nullptr
)
if
(
path
.
data
()
==
nullptr
)
path
=
"/"
;
path
=
"/"
;
return
path
;
return
path
;
}
}
...
@@ -495,7 +495,7 @@ private:
...
@@ -495,7 +495,7 @@ private:
*/
*/
gcc_pure
gcc_pure
StringView
HrefToEscapedName
(
const
char
*
href
)
const
noexcept
{
StringView
HrefToEscapedName
(
const
char
*
href
)
const
noexcept
{
const
char
*
path
=
uri_get_path
(
href
);
StringView
path
=
uri_get_path
(
href
);
if
(
path
==
nullptr
)
if
(
path
==
nullptr
)
return
nullptr
;
return
nullptr
;
...
@@ -504,16 +504,16 @@ private:
...
@@ -504,16 +504,16 @@ private:
case in hex digits in escaped characters; TODO:
case in hex digits in escaped characters; TODO:
implement properly */
implement properly */
path
=
StringAfterPrefixIgnoreCase
(
path
,
base_path
.
c_str
());
path
=
StringAfterPrefixIgnoreCase
(
path
,
base_path
.
c_str
());
if
(
path
==
nullptr
||
*
path
==
0
)
if
(
path
==
nullptr
||
path
.
empty
()
)
return
nullptr
;
return
nullptr
;
const
char
*
slash
=
strchr
(
path
,
'/'
);
const
char
*
slash
=
path
.
Find
(
'/'
);
if
(
slash
==
nullptr
)
if
(
slash
==
nullptr
)
/* regular file */
/* regular file */
return
path
;
return
path
;
else
if
(
slash
[
1
]
==
0
)
else
if
(
slash
==
&
path
.
back
()
)
/* trailing slash: collection; strip the slash */
/* trailing slash: collection; strip the slash */
return
{
path
,
slash
};
return
{
path
.
data
,
slash
};
else
else
/* strange, better ignore it */
/* strange, better ignore it */
return
nullptr
;
return
nullptr
;
...
...
src/util/UriExtract.cxx
View file @
332f480e
...
@@ -48,12 +48,12 @@ IsValidSchemeChar(char ch)
...
@@ -48,12 +48,12 @@ IsValidSchemeChar(char ch)
gcc_pure
gcc_pure
static
bool
static
bool
IsValidScheme
(
StringV
iew
p
)
noexcept
IsValidScheme
(
std
::
string_v
iew
p
)
noexcept
{
{
if
(
p
.
empty
()
||
!
IsValidSchemeStart
(
p
.
front
()))
if
(
p
.
empty
()
||
!
IsValidSchemeStart
(
p
.
front
()))
return
false
;
return
false
;
for
(
size_t
i
=
1
;
i
<
p
.
size
;
++
i
)
for
(
size_t
i
=
1
;
i
<
p
.
size
()
;
++
i
)
if
(
!
IsValidSchemeChar
(
p
[
i
]))
if
(
!
IsValidSchemeChar
(
p
[
i
]))
return
false
;
return
false
;
...
@@ -65,18 +65,23 @@ IsValidScheme(StringView p) noexcept
...
@@ -65,18 +65,23 @@ IsValidScheme(StringView p) noexcept
* double slash).
* double slash).
*/
*/
gcc_pure
gcc_pure
static
const
char
*
static
std
::
string_view
uri_after_scheme
(
const
char
*
uri
)
noexcept
uri_after_scheme
(
std
::
string_view
uri
)
noexcept
{
{
if
(
uri
[
0
]
==
'/'
&&
uri
[
1
]
==
'/'
&&
uri
[
2
]
!=
'/'
)
if
(
uri
.
length
()
>
2
&&
return
uri
+
2
;
uri
[
0
]
==
'/'
&&
uri
[
1
]
==
'/'
&&
uri
[
2
]
!=
'/'
)
return
uri
.
substr
(
2
);
const
char
*
colon
=
strchr
(
uri
,
':'
);
return
colon
!=
nullptr
&&
auto
colon
=
uri
.
find
(
':'
);
IsValidScheme
({
uri
,
colon
})
&&
if
(
colon
==
std
::
string_view
::
npos
||
colon
[
1
]
==
'/'
&&
colon
[
2
]
==
'/'
!
IsValidScheme
(
uri
.
substr
(
0
,
colon
)))
?
colon
+
3
return
{};
:
nullptr
;
uri
=
uri
.
substr
(
colon
+
1
);
if
(
uri
[
0
]
!=
'/'
||
uri
[
1
]
!=
'/'
)
return
{};
return
uri
.
substr
(
2
);
}
}
bool
bool
...
@@ -101,12 +106,16 @@ uri_is_relative_path(const char *uri) noexcept
...
@@ -101,12 +106,16 @@ uri_is_relative_path(const char *uri) noexcept
return
!
uri_has_scheme
(
uri
)
&&
*
uri
!=
'/'
;
return
!
uri_has_scheme
(
uri
)
&&
*
uri
!=
'/'
;
}
}
const
char
*
std
::
string_view
uri_get_path
(
const
char
*
uri
)
noexcept
uri_get_path
(
std
::
string_view
uri
)
noexcept
{
{
const
char
*
ap
=
uri_after_scheme
(
uri
);
auto
ap
=
uri_after_scheme
(
uri
);
if
(
ap
!=
nullptr
)
if
(
ap
.
data
()
!=
nullptr
)
{
return
strchr
(
ap
,
'/'
);
auto
slash
=
ap
.
find
(
'/'
);
if
(
slash
==
std
::
string_view
::
npos
)
return
{};
return
ap
.
substr
(
slash
);
}
return
uri
;
return
uri
;
}
}
...
...
src/util/UriExtract.hxx
View file @
332f480e
...
@@ -57,9 +57,9 @@ uri_is_relative_path(const char *uri) noexcept;
...
@@ -57,9 +57,9 @@ uri_is_relative_path(const char *uri) noexcept;
* Returns the URI path (including the query string) or nullptr if the
* Returns the URI path (including the query string) or nullptr if the
* given URI has no path.
* given URI has no path.
*/
*/
gcc_pure
gcc_nonnull_all
gcc_pure
const
char
*
std
::
string_view
uri_get_path
(
const
char
*
uri
)
noexcept
;
uri_get_path
(
std
::
string_view
uri
)
noexcept
;
gcc_pure
gcc_pure
const
char
*
const
char
*
...
...
src/util/UriRelative.cxx
View file @
332f480e
...
@@ -163,8 +163,8 @@ uri_apply_relative(const std::string &relative_uri,
...
@@ -163,8 +163,8 @@ uri_apply_relative(const std::string &relative_uri,
return
base_uri
.
substr
(
0
,
i
)
+
relative_uri
;
return
base_uri
.
substr
(
0
,
i
)
+
relative_uri
;
}
}
const
char
*
_base_path
=
uri_get_path
(
base_uri
.
c_str
()
);
const
auto
_base_path
=
uri_get_path
(
base_uri
);
if
(
_base_path
==
nullptr
)
{
if
(
_base_path
.
data
()
==
nullptr
)
{
std
::
string
result
(
base_uri
);
std
::
string
result
(
base_uri
);
if
(
relative_uri
.
front
()
!=
'/'
)
if
(
relative_uri
.
front
()
!=
'/'
)
result
.
push_back
(
'/'
);
result
.
push_back
(
'/'
);
...
@@ -183,7 +183,7 @@ uri_apply_relative(const std::string &relative_uri,
...
@@ -183,7 +183,7 @@ uri_apply_relative(const std::string &relative_uri,
if
(
!
ConsumeSpecial
(
relative_path
,
base_path
))
if
(
!
ConsumeSpecial
(
relative_path
,
base_path
))
return
{};
return
{};
std
::
string
result
(
base_uri
.
c_str
(),
_base_path
);
std
::
string
result
(
base_uri
.
data
(),
_base_path
.
data
()
);
result
.
append
(
base_path
.
data
,
base_path
.
size
);
result
.
append
(
base_path
.
data
,
base_path
.
size
);
result
.
append
(
relative_path
);
result
.
append
(
relative_path
);
return
result
;
return
result
;
...
...
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