From afbcac9fb1d692f4351d57dffd3604724c22f404 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 4 Nov 2020 21:24:53 +0100 Subject: [PATCH] util/MimeType: use IterableSplitString() in ParseMimeTypeParameters() --- src/util/MimeType.cxx | 24 ++++++++++-------------- src/util/MimeType.hxx | 2 +- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/util/MimeType.cxx b/src/util/MimeType.cxx index 13ad9fe8b..5b63d1d49 100644 --- a/src/util/MimeType.cxx +++ b/src/util/MimeType.cxx @@ -18,7 +18,7 @@ */ #include "MimeType.hxx" -#include "SplitString.hxx" +#include "IterableSplitString.hxx" #include "StringView.hxx" std::string_view @@ -28,21 +28,17 @@ GetMimeTypeBase(std::string_view s) noexcept } std::map -ParseMimeTypeParameters(const char *s) noexcept +ParseMimeTypeParameters(std::string_view mime_type) noexcept { + /* discard the first segment (the base MIME type) */ + const auto params = StringView(mime_type).Split(';').second; + std::map result; - - auto l = SplitString(s, ';', true); - if (!l.empty()) - l.pop_front(); - - for (const auto &i : l) { - const auto eq = i.find('='); - if (eq == i.npos) - continue; - - result.insert(std::make_pair(i.substr(0, eq), - i.substr(eq + 1))); + for (auto i : IterableSplitString(params, ';')) { + i.Strip(); + auto s = i.Split('='); + if (!s.second.IsNull()) + result.emplace(s); } return result; diff --git a/src/util/MimeType.hxx b/src/util/MimeType.hxx index 1a20c8cf2..e548df283 100644 --- a/src/util/MimeType.hxx +++ b/src/util/MimeType.hxx @@ -42,6 +42,6 @@ GetMimeTypeBase(std::string_view s) noexcept; * "foo/bar; param1=value1; param2=value2" */ std::map -ParseMimeTypeParameters(const char *s) noexcept; +ParseMimeTypeParameters(std::string_view mime_type) noexcept; #endif