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
bb07fd42
Commit
bb07fd42
authored
Nov 04, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/MimeType: migrate GetMimeTypeBase() to std::string_view
parent
bab626c3
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
23 deletions
+21
-23
TagStream.cxx
src/TagStream.cxx
+9
-9
PlaylistRegistry.cxx
src/playlist/PlaylistRegistry.cxx
+2
-4
MimeType.cxx
src/util/MimeType.cxx
+4
-8
MimeType.hxx
src/util/MimeType.hxx
+6
-2
No files found.
src/TagStream.cxx
View file @
bb07fd42
...
...
@@ -36,9 +36,9 @@
gcc_pure
static
bool
CheckDecoderPlugin
(
const
DecoderPlugin
&
plugin
,
std
::
string_view
suffix
,
const
char
*
mime
)
noexcept
std
::
string_view
suffix
,
std
::
string_view
mime
)
noexcept
{
return
(
mime
!=
nullptr
&&
plugin
.
SupportsMimeType
(
mime
))
||
return
(
!
mime
.
empty
()
&&
plugin
.
SupportsMimeType
(
mime
))
||
(
!
suffix
.
empty
()
&&
plugin
.
SupportsSuffix
(
suffix
));
}
...
...
@@ -48,23 +48,23 @@ tag_stream_scan(InputStream &is, TagHandler &handler)
assert
(
is
.
IsReady
());
const
auto
suffix
=
uri_get_suffix
(
is
.
GetURI
());
const
char
*
mime
=
is
.
GetMimeType
();
const
char
*
full_
mime
=
is
.
GetMimeType
();
if
(
suffix
.
empty
()
&&
mime
==
nullptr
)
if
(
suffix
.
empty
()
&&
full_
mime
==
nullptr
)
return
false
;
std
::
string
mime_base
;
if
(
mime
!=
nullptr
)
mime
=
(
mime_base
=
GetMimeTypeBase
(
mime
)).
c_str
(
);
std
::
string
_view
mime_base
{}
;
if
(
full_
mime
!=
nullptr
)
mime
_base
=
GetMimeTypeBase
(
full_mime
);
return
decoder_plugins_try
([
suffix
,
mime
,
&
is
,
return
decoder_plugins_try
([
suffix
,
mime
_base
,
&
is
,
&
handler
](
const
DecoderPlugin
&
plugin
){
try
{
is
.
LockRewind
();
}
catch
(...)
{
}
return
CheckDecoderPlugin
(
plugin
,
suffix
,
mime
)
&&
return
CheckDecoderPlugin
(
plugin
,
suffix
,
mime
_base
)
&&
plugin
.
ScanStream
(
is
,
handler
);
});
}
...
...
src/playlist/PlaylistRegistry.cxx
View file @
bb07fd42
...
...
@@ -227,10 +227,8 @@ ExtractMimeTypeMainPart(StringView s) noexcept
}
static
std
::
unique_ptr
<
SongEnumerator
>
playlist_list_open_stream_mime
(
InputStreamPtr
&&
is
,
const
char
*
full_mime
)
playlist_list_open_stream_mime
(
InputStreamPtr
&&
is
,
std
::
string_view
full_mime
)
{
assert
(
full_mime
!=
nullptr
);
/* probe only the portion before the semicolon*/
return
playlist_list_open_stream_mime2
(
std
::
move
(
is
),
ExtractMimeTypeMainPart
(
full_mime
));
...
...
@@ -266,7 +264,7 @@ playlist_list_open_stream(InputStreamPtr &&is, const char *uri)
const
char
*
const
mime
=
is
->
GetMimeType
();
if
(
mime
!=
nullptr
)
{
auto
playlist
=
playlist_list_open_stream_mime
(
std
::
move
(
is
),
GetMimeTypeBase
(
mime
)
.
c_str
()
);
GetMimeTypeBase
(
mime
));
if
(
playlist
!=
nullptr
)
return
playlist
;
}
...
...
src/util/MimeType.cxx
View file @
bb07fd42
...
...
@@ -19,16 +19,12 @@
#include "MimeType.hxx"
#include "SplitString.hxx"
#include "StringView.hxx"
#include <cstring>
std
::
string
GetMimeTypeBase
(
const
char
*
s
)
noexcept
std
::
string_view
GetMimeTypeBase
(
std
::
string_view
s
)
noexcept
{
const
char
*
semicolon
=
std
::
strchr
(
s
,
';'
);
return
semicolon
!=
nullptr
?
std
::
string
(
s
,
semicolon
)
:
std
::
string
(
s
);
return
StringView
(
s
).
Split
(
';'
).
first
;
}
std
::
map
<
std
::
string
,
std
::
string
>
...
...
src/util/MimeType.hxx
View file @
bb07fd42
...
...
@@ -20,7 +20,10 @@
#ifndef MPD_MIME_TYPE_HXX
#define MPD_MIME_TYPE_HXX
#include "util/Compiler.h"
#include <string>
#include <string_view>
#include <map>
/**
...
...
@@ -28,8 +31,9 @@
* part before the semicolon. If there is no semicolon, it returns
* the string as-is.
*/
std
::
string
GetMimeTypeBase
(
const
char
*
s
)
noexcept
;
gcc_pure
std
::
string_view
GetMimeTypeBase
(
std
::
string_view
s
)
noexcept
;
/**
* Parse the parameters from a MIME type string. Parameters are
...
...
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