util/MimeType: migrate GetMimeTypeBase() to std::string_view
This commit is contained in:
parent
bab626c325
commit
bb07fd42ce
@ -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);
|
||||
});
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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>
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user