Commit 7de6e4db authored by Max Kellermann's avatar Max Kellermann

playlist/Registry: eliminate MIME type copy

parent 15dbb808
...@@ -201,22 +201,29 @@ playlist_list_open_stream_mime2(InputStreamPtr &&is, StringView mime) ...@@ -201,22 +201,29 @@ playlist_list_open_stream_mime2(InputStreamPtr &&is, StringView mime)
return nullptr; return nullptr;
} }
/**
* Extract the "main" part of a MIME type string, i.e. the portion
* before the semicolon (if one exists).
*/
gcc_pure
static StringView
ExtractMimeTypeMainPart(StringView s) noexcept
{
const auto separator = s.Find(';');
if (separator != nullptr)
s.SetEnd(separator);
return s;
}
static std::unique_ptr<SongEnumerator> static std::unique_ptr<SongEnumerator>
playlist_list_open_stream_mime(InputStreamPtr &&is, const char *full_mime) playlist_list_open_stream_mime(InputStreamPtr &&is, const char *full_mime)
{ {
assert(full_mime != nullptr); assert(full_mime != nullptr);
const char *semicolon = strchr(full_mime, ';');
if (semicolon == nullptr)
return playlist_list_open_stream_mime2(std::move(is),
full_mime);
if (semicolon == full_mime)
return nullptr;
/* probe only the portion before the semicolon*/ /* probe only the portion before the semicolon*/
const std::string mime(full_mime, semicolon); return playlist_list_open_stream_mime2(std::move(is),
return playlist_list_open_stream_mime2(std::move(is), mime.c_str()); ExtractMimeTypeMainPart(full_mime));
} }
std::unique_ptr<SongEnumerator> std::unique_ptr<SongEnumerator>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment