diff --git a/src/archive/ArchiveList.cxx b/src/archive/ArchiveList.cxx index 25a4a72f9..c45daf15d 100644 --- a/src/archive/ArchiveList.cxx +++ b/src/archive/ArchiveList.cxx @@ -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]) 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) if (plugin->suffixes != nullptr && StringArrayContainsCase(plugin->suffixes, suffix)) diff --git a/src/archive/ArchiveList.hxx b/src/archive/ArchiveList.hxx index 5a0a7925f..198c400fc 100644 --- a/src/archive/ArchiveList.hxx +++ b/src/archive/ArchiveList.hxx @@ -20,6 +20,8 @@ #ifndef MPD_ARCHIVE_LIST_HXX #define MPD_ARCHIVE_LIST_HXX +#include + struct ArchivePlugin; extern const ArchivePlugin *const archive_plugins[]; @@ -33,7 +35,7 @@ extern const ArchivePlugin *const archive_plugins[]; /* interface for using plugins */ const ArchivePlugin * -archive_plugin_from_suffix(const char *suffix) noexcept; +archive_plugin_from_suffix(std::string_view suffix) noexcept; const ArchivePlugin * archive_plugin_from_name(const char *name) noexcept; diff --git a/src/command/FingerprintCommands.cxx b/src/command/FingerprintCommands.cxx index 5a4ef5b51..d75b9f5be 100644 --- a/src/command/FingerprintCommands.cxx +++ b/src/command/FingerprintCommands.cxx @@ -124,7 +124,7 @@ decoder_check_plugin_mime(const DecoderPlugin &plugin, const char *mime_type = is.GetMimeType(); return mime_type != nullptr && - plugin.SupportsMimeType(GetMimeTypeBase(mime_type).c_str()); + plugin.SupportsMimeType(GetMimeTypeBase(mime_type)); } gcc_pure diff --git a/src/decoder/DecoderList.cxx b/src/decoder/DecoderList.cxx index 7bca4b0d7..1d6640759 100644 --- a/src/decoder/DecoderList.cxx +++ b/src/decoder/DecoderList.cxx @@ -175,7 +175,7 @@ decoder_plugin_deinit_all() noexcept } 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 plugin.SupportsSuffix(suffix); diff --git a/src/decoder/DecoderList.hxx b/src/decoder/DecoderList.hxx index f3ec3c153..ecb453a03 100644 --- a/src/decoder/DecoderList.hxx +++ b/src/decoder/DecoderList.hxx @@ -22,6 +22,8 @@ #include "util/Compiler.h" +#include + struct ConfigData; struct DecoderPlugin; @@ -98,6 +100,6 @@ decoder_plugins_for_each_enabled(F f) */ gcc_pure gcc_nonnull_all bool -decoder_plugins_supports_suffix(const char *suffix) noexcept; +decoder_plugins_supports_suffix(std::string_view suffix) noexcept; #endif diff --git a/src/decoder/DecoderPlugin.cxx b/src/decoder/DecoderPlugin.cxx index bbb3966fc..e1ed4f513 100644 --- a/src/decoder/DecoderPlugin.cxx +++ b/src/decoder/DecoderPlugin.cxx @@ -37,25 +37,15 @@ DecoderPlugin::SupportsUri(const char *uri) const noexcept } 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 && StringArrayContainsCase(suffixes, suffix); } 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 && StringArrayContainsCase(mime_types, mime_type); } diff --git a/src/decoder/DecoderPlugin.hxx b/src/decoder/DecoderPlugin.hxx index c09aa5032..674565dd5 100644 --- a/src/decoder/DecoderPlugin.hxx +++ b/src/decoder/DecoderPlugin.hxx @@ -25,6 +25,7 @@ #include // IWYU pragma: export #include #include +#include struct ConfigBlock; class InputStream; @@ -252,15 +253,15 @@ struct DecoderPlugin { * Does the plugin announce the specified file name suffix? */ 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? */ 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); } }; diff --git a/src/decoder/Thread.cxx b/src/decoder/Thread.cxx index d4d85edb4..00113063d 100644 --- a/src/decoder/Thread.cxx +++ b/src/decoder/Thread.cxx @@ -172,7 +172,7 @@ decoder_check_plugin_mime(const DecoderPlugin &plugin, const char *mime_type = is.GetMimeType(); return mime_type != nullptr && - plugin.SupportsMimeType(GetMimeTypeBase(mime_type).c_str()); + plugin.SupportsMimeType(GetMimeTypeBase(mime_type)); } gcc_pure diff --git a/src/playlist/PlaylistPlugin.cxx b/src/playlist/PlaylistPlugin.cxx index ad01ba393..a243316b8 100644 --- a/src/playlist/PlaylistPlugin.cxx +++ b/src/playlist/PlaylistPlugin.cxx @@ -29,7 +29,7 @@ PlaylistPlugin::SupportsScheme(StringView scheme) const noexcept } bool -PlaylistPlugin::SupportsSuffix(const char *suffix) const noexcept +PlaylistPlugin::SupportsSuffix(StringView suffix) const noexcept { return suffixes != nullptr && StringArrayContainsCase(suffixes, suffix); diff --git a/src/playlist/PlaylistPlugin.hxx b/src/playlist/PlaylistPlugin.hxx index d729296e1..8740a13a7 100644 --- a/src/playlist/PlaylistPlugin.hxx +++ b/src/playlist/PlaylistPlugin.hxx @@ -126,7 +126,7 @@ struct PlaylistPlugin { * Does the plugin announce the specified file name suffix? */ 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? diff --git a/src/playlist/PlaylistRegistry.cxx b/src/playlist/PlaylistRegistry.cxx index b9f6bb7ec..54540b5e4 100644 --- a/src/playlist/PlaylistRegistry.cxx +++ b/src/playlist/PlaylistRegistry.cxx @@ -238,10 +238,8 @@ playlist_list_open_stream_mime(InputStreamPtr &&is, const char *full_mime) } std::unique_ptr -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) { if (plugin->open_stream != nullptr && plugin->SupportsSuffix(suffix)) { @@ -289,10 +287,8 @@ playlist_list_open_stream(InputStreamPtr &&is, const char *uri) } const PlaylistPlugin * -FindPlaylistPluginBySuffix(const char *suffix) noexcept +FindPlaylistPluginBySuffix(std::string_view suffix) noexcept { - assert(suffix != nullptr); - playlist_plugins_for_each_enabled(plugin) { if (plugin->SupportsSuffix(suffix)) return plugin; diff --git a/src/playlist/PlaylistRegistry.hxx b/src/playlist/PlaylistRegistry.hxx index 205fbb4b2..ea036cc5d 100644 --- a/src/playlist/PlaylistRegistry.hxx +++ b/src/playlist/PlaylistRegistry.hxx @@ -24,6 +24,8 @@ #include "thread/Mutex.hxx" #include "util/Compiler.h" +#include + struct ConfigData; struct PlaylistPlugin; class SongEnumerator; @@ -74,7 +76,7 @@ std::unique_ptr playlist_list_open_uri(const char *uri, Mutex &mutex); std::unique_ptr -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. @@ -88,7 +90,7 @@ playlist_list_open_stream(InputStreamPtr &&is, const char *uri); gcc_pure const PlaylistPlugin * -FindPlaylistPluginBySuffix(const char *suffix) noexcept; +FindPlaylistPluginBySuffix(std::string_view suffix) noexcept; /** * Determines if there is a playlist plugin which can handle the @@ -96,7 +98,7 @@ FindPlaylistPluginBySuffix(const char *suffix) noexcept; */ gcc_pure inline bool -playlist_suffix_supported(const char *suffix) noexcept +playlist_suffix_supported(std::string_view suffix) noexcept { return FindPlaylistPluginBySuffix(suffix) != nullptr; } diff --git a/src/playlist/PlaylistStream.cxx b/src/playlist/PlaylistStream.cxx index cebcc38e1..1867531d4 100644 --- a/src/playlist/PlaylistStream.cxx +++ b/src/playlist/PlaylistStream.cxx @@ -23,6 +23,7 @@ #include "input/InputStream.hxx" #include "input/LocalOpen.hxx" #include "fs/Path.hxx" +#include "util/StringView.hxx" #include "util/UriExtract.hxx" #include "Log.hxx" @@ -39,12 +40,12 @@ try { return nullptr; const auto suffix_utf8 = Path::FromFS(suffix).ToUTF8Throw(); - if (!playlist_suffix_supported(suffix_utf8.c_str())) + if (!playlist_suffix_supported(suffix_utf8)) return nullptr; auto is = OpenLocalInputStream(path, mutex); return playlist_list_open_stream_suffix(std::move(is), - suffix_utf8.c_str()); + suffix_utf8); } catch (...) { LogError(std::current_exception()); return nullptr;