2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
// author: Max Kellermann <max.kellermann@gmail.com>
|
2016-06-10 22:24:13 +02:00
|
|
|
|
|
|
|
#include "MimeType.hxx"
|
2020-11-04 21:24:53 +01:00
|
|
|
#include "IterableSplitString.hxx"
|
2022-07-01 11:06:37 +02:00
|
|
|
#include "util/StringSplit.hxx"
|
|
|
|
#include "util/StringStrip.hxx"
|
2016-06-10 22:24:13 +02:00
|
|
|
|
2020-11-04 20:27:28 +01:00
|
|
|
std::string_view
|
|
|
|
GetMimeTypeBase(std::string_view s) noexcept
|
2016-06-10 22:24:13 +02:00
|
|
|
{
|
2022-07-01 11:06:37 +02:00
|
|
|
return Split(s, ';').first;
|
2016-06-10 22:24:13 +02:00
|
|
|
}
|
2016-06-10 22:31:26 +02:00
|
|
|
|
2023-03-12 09:11:45 +01:00
|
|
|
std::map<std::string, std::string, std::less<>>
|
2020-11-04 21:24:53 +01:00
|
|
|
ParseMimeTypeParameters(std::string_view mime_type) noexcept
|
2016-06-10 22:31:26 +02:00
|
|
|
{
|
2020-11-04 21:24:53 +01:00
|
|
|
/* discard the first segment (the base MIME type) */
|
2022-07-01 11:06:37 +02:00
|
|
|
const auto params = Split(mime_type, ';').second;
|
2016-06-10 22:31:26 +02:00
|
|
|
|
2023-03-12 09:11:45 +01:00
|
|
|
std::map<std::string, std::string, std::less<>> result;
|
2022-07-01 11:06:37 +02:00
|
|
|
for (const std::string_view i : IterableSplitString(params, ';')) {
|
|
|
|
const auto s = Split(Strip(i), '=');
|
|
|
|
if (!s.first.empty() && s.second.data() != nullptr)
|
2020-11-04 21:24:53 +01:00
|
|
|
result.emplace(s);
|
2016-06-10 22:31:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|