{decoder,archive,playlist}/plugin: pass std::string_view to SupportsMimeType()
This commit is contained in:
parent
53396c0e50
commit
19dd1a25d7
@ -55,10 +55,8 @@ static bool archive_plugins_enabled[std::max(n_archive_plugins, std::size_t(1))]
|
|||||||
if (archive_plugins_enabled[archive_plugin_iterator - archive_plugins])
|
if (archive_plugins_enabled[archive_plugin_iterator - archive_plugins])
|
||||||
|
|
||||||
const ArchivePlugin *
|
const ArchivePlugin *
|
||||||
archive_plugin_from_suffix(const char *suffix) noexcept
|
archive_plugin_from_suffix(std::string_view suffix) noexcept
|
||||||
{
|
{
|
||||||
assert(suffix != nullptr);
|
|
||||||
|
|
||||||
archive_plugins_for_each_enabled(plugin)
|
archive_plugins_for_each_enabled(plugin)
|
||||||
if (plugin->suffixes != nullptr &&
|
if (plugin->suffixes != nullptr &&
|
||||||
StringArrayContainsCase(plugin->suffixes, suffix))
|
StringArrayContainsCase(plugin->suffixes, suffix))
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
#ifndef MPD_ARCHIVE_LIST_HXX
|
#ifndef MPD_ARCHIVE_LIST_HXX
|
||||||
#define MPD_ARCHIVE_LIST_HXX
|
#define MPD_ARCHIVE_LIST_HXX
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
struct ArchivePlugin;
|
struct ArchivePlugin;
|
||||||
|
|
||||||
extern const ArchivePlugin *const archive_plugins[];
|
extern const ArchivePlugin *const archive_plugins[];
|
||||||
@ -33,7 +35,7 @@ extern const ArchivePlugin *const archive_plugins[];
|
|||||||
/* interface for using plugins */
|
/* interface for using plugins */
|
||||||
|
|
||||||
const ArchivePlugin *
|
const ArchivePlugin *
|
||||||
archive_plugin_from_suffix(const char *suffix) noexcept;
|
archive_plugin_from_suffix(std::string_view suffix) noexcept;
|
||||||
|
|
||||||
const ArchivePlugin *
|
const ArchivePlugin *
|
||||||
archive_plugin_from_name(const char *name) noexcept;
|
archive_plugin_from_name(const char *name) noexcept;
|
||||||
|
@ -124,7 +124,7 @@ decoder_check_plugin_mime(const DecoderPlugin &plugin,
|
|||||||
|
|
||||||
const char *mime_type = is.GetMimeType();
|
const char *mime_type = is.GetMimeType();
|
||||||
return mime_type != nullptr &&
|
return mime_type != nullptr &&
|
||||||
plugin.SupportsMimeType(GetMimeTypeBase(mime_type).c_str());
|
plugin.SupportsMimeType(GetMimeTypeBase(mime_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
|
@ -175,7 +175,7 @@ decoder_plugin_deinit_all() noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
decoder_plugins_supports_suffix(const char *suffix) noexcept
|
decoder_plugins_supports_suffix(std::string_view suffix) noexcept
|
||||||
{
|
{
|
||||||
return decoder_plugins_try([suffix](const DecoderPlugin &plugin){
|
return decoder_plugins_try([suffix](const DecoderPlugin &plugin){
|
||||||
return plugin.SupportsSuffix(suffix);
|
return plugin.SupportsSuffix(suffix);
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include "util/Compiler.h"
|
#include "util/Compiler.h"
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
struct ConfigData;
|
struct ConfigData;
|
||||||
struct DecoderPlugin;
|
struct DecoderPlugin;
|
||||||
|
|
||||||
@ -98,6 +100,6 @@ decoder_plugins_for_each_enabled(F f)
|
|||||||
*/
|
*/
|
||||||
gcc_pure gcc_nonnull_all
|
gcc_pure gcc_nonnull_all
|
||||||
bool
|
bool
|
||||||
decoder_plugins_supports_suffix(const char *suffix) noexcept;
|
decoder_plugins_supports_suffix(std::string_view suffix) noexcept;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -37,25 +37,15 @@ DecoderPlugin::SupportsUri(const char *uri) const noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
DecoderPlugin::SupportsSuffix(const char *suffix) const noexcept
|
DecoderPlugin::SupportsSuffix(std::string_view suffix) const noexcept
|
||||||
{
|
{
|
||||||
#if !CLANG_CHECK_VERSION(3,6)
|
|
||||||
/* disabled on clang due to -Wtautological-pointer-compare */
|
|
||||||
assert(suffix != nullptr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return suffixes != nullptr &&
|
return suffixes != nullptr &&
|
||||||
StringArrayContainsCase(suffixes, suffix);
|
StringArrayContainsCase(suffixes, suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
DecoderPlugin::SupportsMimeType(const char *mime_type) const noexcept
|
DecoderPlugin::SupportsMimeType(std::string_view mime_type) const noexcept
|
||||||
{
|
{
|
||||||
#if !CLANG_CHECK_VERSION(3,6)
|
|
||||||
/* disabled on clang due to -Wtautological-pointer-compare */
|
|
||||||
assert(mime_type != nullptr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return mime_types != nullptr &&
|
return mime_types != nullptr &&
|
||||||
StringArrayContainsCase(mime_types, mime_type);
|
StringArrayContainsCase(mime_types, mime_type);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <forward_list> // IWYU pragma: export
|
#include <forward_list> // IWYU pragma: export
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
struct ConfigBlock;
|
struct ConfigBlock;
|
||||||
class InputStream;
|
class InputStream;
|
||||||
@ -252,15 +253,15 @@ struct DecoderPlugin {
|
|||||||
* Does the plugin announce the specified file name suffix?
|
* Does the plugin announce the specified file name suffix?
|
||||||
*/
|
*/
|
||||||
gcc_pure gcc_nonnull_all
|
gcc_pure gcc_nonnull_all
|
||||||
bool SupportsSuffix(const char *suffix) const noexcept;
|
bool SupportsSuffix(std::string_view suffix) const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does the plugin announce the specified MIME type?
|
* Does the plugin announce the specified MIME type?
|
||||||
*/
|
*/
|
||||||
gcc_pure gcc_nonnull_all
|
gcc_pure gcc_nonnull_all
|
||||||
bool SupportsMimeType(const char *mime_type) const noexcept;
|
bool SupportsMimeType(std::string_view mime_type) const noexcept;
|
||||||
|
|
||||||
bool SupportsContainerSuffix(const char *suffix) const noexcept {
|
bool SupportsContainerSuffix(std::string_view suffix) const noexcept {
|
||||||
return container_scan != nullptr && SupportsSuffix(suffix);
|
return container_scan != nullptr && SupportsSuffix(suffix);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -172,7 +172,7 @@ decoder_check_plugin_mime(const DecoderPlugin &plugin,
|
|||||||
|
|
||||||
const char *mime_type = is.GetMimeType();
|
const char *mime_type = is.GetMimeType();
|
||||||
return mime_type != nullptr &&
|
return mime_type != nullptr &&
|
||||||
plugin.SupportsMimeType(GetMimeTypeBase(mime_type).c_str());
|
plugin.SupportsMimeType(GetMimeTypeBase(mime_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
|
@ -29,7 +29,7 @@ PlaylistPlugin::SupportsScheme(StringView scheme) const noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PlaylistPlugin::SupportsSuffix(const char *suffix) const noexcept
|
PlaylistPlugin::SupportsSuffix(StringView suffix) const noexcept
|
||||||
{
|
{
|
||||||
return suffixes != nullptr &&
|
return suffixes != nullptr &&
|
||||||
StringArrayContainsCase(suffixes, suffix);
|
StringArrayContainsCase(suffixes, suffix);
|
||||||
|
@ -126,7 +126,7 @@ struct PlaylistPlugin {
|
|||||||
* Does the plugin announce the specified file name suffix?
|
* Does the plugin announce the specified file name suffix?
|
||||||
*/
|
*/
|
||||||
gcc_pure gcc_nonnull_all
|
gcc_pure gcc_nonnull_all
|
||||||
bool SupportsSuffix(const char *suffix) const noexcept;
|
bool SupportsSuffix(StringView suffix) const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does the plugin announce the specified MIME type?
|
* Does the plugin announce the specified MIME type?
|
||||||
|
@ -238,10 +238,8 @@ playlist_list_open_stream_mime(InputStreamPtr &&is, const char *full_mime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<SongEnumerator>
|
std::unique_ptr<SongEnumerator>
|
||||||
playlist_list_open_stream_suffix(InputStreamPtr &&is, const char *suffix)
|
playlist_list_open_stream_suffix(InputStreamPtr &&is, std::string_view suffix)
|
||||||
{
|
{
|
||||||
assert(suffix != nullptr);
|
|
||||||
|
|
||||||
playlist_plugins_for_each_enabled(plugin) {
|
playlist_plugins_for_each_enabled(plugin) {
|
||||||
if (plugin->open_stream != nullptr &&
|
if (plugin->open_stream != nullptr &&
|
||||||
plugin->SupportsSuffix(suffix)) {
|
plugin->SupportsSuffix(suffix)) {
|
||||||
@ -289,10 +287,8 @@ playlist_list_open_stream(InputStreamPtr &&is, const char *uri)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const PlaylistPlugin *
|
const PlaylistPlugin *
|
||||||
FindPlaylistPluginBySuffix(const char *suffix) noexcept
|
FindPlaylistPluginBySuffix(std::string_view suffix) noexcept
|
||||||
{
|
{
|
||||||
assert(suffix != nullptr);
|
|
||||||
|
|
||||||
playlist_plugins_for_each_enabled(plugin) {
|
playlist_plugins_for_each_enabled(plugin) {
|
||||||
if (plugin->SupportsSuffix(suffix))
|
if (plugin->SupportsSuffix(suffix))
|
||||||
return plugin;
|
return plugin;
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#include "thread/Mutex.hxx"
|
#include "thread/Mutex.hxx"
|
||||||
#include "util/Compiler.h"
|
#include "util/Compiler.h"
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
struct ConfigData;
|
struct ConfigData;
|
||||||
struct PlaylistPlugin;
|
struct PlaylistPlugin;
|
||||||
class SongEnumerator;
|
class SongEnumerator;
|
||||||
@ -74,7 +76,7 @@ std::unique_ptr<SongEnumerator>
|
|||||||
playlist_list_open_uri(const char *uri, Mutex &mutex);
|
playlist_list_open_uri(const char *uri, Mutex &mutex);
|
||||||
|
|
||||||
std::unique_ptr<SongEnumerator>
|
std::unique_ptr<SongEnumerator>
|
||||||
playlist_list_open_stream_suffix(InputStreamPtr &&is, const char *suffix);
|
playlist_list_open_stream_suffix(InputStreamPtr &&is, std::string_view suffix);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a playlist from an input stream.
|
* Opens a playlist from an input stream.
|
||||||
@ -88,7 +90,7 @@ playlist_list_open_stream(InputStreamPtr &&is, const char *uri);
|
|||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
const PlaylistPlugin *
|
const PlaylistPlugin *
|
||||||
FindPlaylistPluginBySuffix(const char *suffix) noexcept;
|
FindPlaylistPluginBySuffix(std::string_view suffix) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if there is a playlist plugin which can handle the
|
* Determines if there is a playlist plugin which can handle the
|
||||||
@ -96,7 +98,7 @@ FindPlaylistPluginBySuffix(const char *suffix) noexcept;
|
|||||||
*/
|
*/
|
||||||
gcc_pure
|
gcc_pure
|
||||||
inline bool
|
inline bool
|
||||||
playlist_suffix_supported(const char *suffix) noexcept
|
playlist_suffix_supported(std::string_view suffix) noexcept
|
||||||
{
|
{
|
||||||
return FindPlaylistPluginBySuffix(suffix) != nullptr;
|
return FindPlaylistPluginBySuffix(suffix) != nullptr;
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "input/InputStream.hxx"
|
#include "input/InputStream.hxx"
|
||||||
#include "input/LocalOpen.hxx"
|
#include "input/LocalOpen.hxx"
|
||||||
#include "fs/Path.hxx"
|
#include "fs/Path.hxx"
|
||||||
|
#include "util/StringView.hxx"
|
||||||
#include "util/UriExtract.hxx"
|
#include "util/UriExtract.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
@ -39,12 +40,12 @@ try {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
const auto suffix_utf8 = Path::FromFS(suffix).ToUTF8Throw();
|
const auto suffix_utf8 = Path::FromFS(suffix).ToUTF8Throw();
|
||||||
if (!playlist_suffix_supported(suffix_utf8.c_str()))
|
if (!playlist_suffix_supported(suffix_utf8))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
auto is = OpenLocalInputStream(path, mutex);
|
auto is = OpenLocalInputStream(path, mutex);
|
||||||
return playlist_list_open_stream_suffix(std::move(is),
|
return playlist_list_open_stream_suffix(std::move(is),
|
||||||
suffix_utf8.c_str());
|
suffix_utf8);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
LogError(std::current_exception());
|
LogError(std::current_exception());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user