util/MimeType: add ParseMimeTypeParameters()

This commit is contained in:
Max Kellermann
2016-06-10 22:31:26 +02:00
parent bc63810ebd
commit 287ef181ba
3 changed files with 53 additions and 0 deletions
+22
View File
@@ -18,6 +18,7 @@
*/
#include "MimeType.hxx"
#include "SplitString.hxx"
#include <string.h>
@@ -29,3 +30,24 @@ GetMimeTypeBase(const char *s)
? std::string(s, semicolon)
: std::string(s);
}
std::map<std::string, std::string>
ParseMimeTypeParameters(const char *s)
{
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(std::string(&i.front(), eq),
std::string(&i[eq + 1])));
}
return result;
}