diff options
author | Max Kellermann <max@duempel.org> | 2016-06-10 22:31:26 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2016-06-10 22:52:35 +0200 |
commit | 287ef181bad16f8c8f90ee95a046f4c2a91908db (patch) | |
tree | 90ec7518bd0bd9e5b0cc2684268a06cb4085b96d /src | |
parent | bc63810ebddde08c133084c377b46616c370bbaa (diff) |
util/MimeType: add ParseMimeTypeParameters()
Diffstat (limited to 'src')
-rw-r--r-- | src/util/MimeType.cxx | 22 | ||||
-rw-r--r-- | src/util/MimeType.hxx | 10 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/util/MimeType.cxx b/src/util/MimeType.cxx index 64822555b..1287895fc 100644 --- a/src/util/MimeType.cxx +++ b/src/util/MimeType.cxx @@ -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; +} diff --git a/src/util/MimeType.hxx b/src/util/MimeType.hxx index fe8f385b2..679697d7a 100644 --- a/src/util/MimeType.hxx +++ b/src/util/MimeType.hxx @@ -21,6 +21,7 @@ #define MPD_MIME_TYPE_HXX #include <string> +#include <map> /** * Extract the part of the MIME type before the parameters, i.e. the @@ -30,4 +31,13 @@ std::string GetMimeTypeBase(const char *s); +/** + * Parse the parameters from a MIME type string. Parameters are + * separated by semicolon. Example: + * + * "foo/bar; param1=value1; param2=value2" + */ +std::map<std::string, std::string> +ParseMimeTypeParameters(const char *s); + #endif |