util/MimeType: use IterableSplitString() in ParseMimeTypeParameters()
This commit is contained in:
parent
51e5b56b3a
commit
afbcac9fb1
@ -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<std::string, std::string>
|
||||
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<std::string, std::string> 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;
|
||||
|
@ -42,6 +42,6 @@ GetMimeTypeBase(std::string_view s) noexcept;
|
||||
* "foo/bar; param1=value1; param2=value2"
|
||||
*/
|
||||
std::map<std::string, std::string>
|
||||
ParseMimeTypeParameters(const char *s) noexcept;
|
||||
ParseMimeTypeParameters(std::string_view mime_type) noexcept;
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user