Commit afbcac9f authored by Max Kellermann's avatar Max Kellermann

util/MimeType: use IterableSplitString() in ParseMimeTypeParameters()

parent 51e5b56b
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
*/ */
#include "MimeType.hxx" #include "MimeType.hxx"
#include "SplitString.hxx" #include "IterableSplitString.hxx"
#include "StringView.hxx" #include "StringView.hxx"
std::string_view std::string_view
...@@ -28,21 +28,17 @@ GetMimeTypeBase(std::string_view s) noexcept ...@@ -28,21 +28,17 @@ GetMimeTypeBase(std::string_view s) noexcept
} }
std::map<std::string, std::string> std::map<std::string, std::string>
ParseMimeTypeParameters(const char *s) noexcept ParseMimeTypeParameters(std::string_view mime_type) noexcept
{ {
std::map<std::string, std::string> result; /* discard the first segment (the base MIME type) */
const auto params = StringView(mime_type).Split(';').second;
auto l = SplitString(s, ';', true);
if (!l.empty())
l.pop_front();
for (const auto &i : l) { std::map<std::string, std::string> result;
const auto eq = i.find('='); for (auto i : IterableSplitString(params, ';')) {
if (eq == i.npos) i.Strip();
continue; auto s = i.Split('=');
if (!s.second.IsNull())
result.insert(std::make_pair(i.substr(0, eq), result.emplace(s);
i.substr(eq + 1)));
} }
return result; return result;
......
...@@ -42,6 +42,6 @@ GetMimeTypeBase(std::string_view s) noexcept; ...@@ -42,6 +42,6 @@ GetMimeTypeBase(std::string_view s) noexcept;
* "foo/bar; param1=value1; param2=value2" * "foo/bar; param1=value1; param2=value2"
*/ */
std::map<std::string, std::string> std::map<std::string, std::string>
ParseMimeTypeParameters(const char *s) noexcept; ParseMimeTypeParameters(std::string_view mime_type) noexcept;
#endif #endif
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