MIME: add lookup function for file name extension for MIME type

This commit is contained in:
Moritz Bunkus 2017-04-15 18:20:54 +02:00
parent a1a394ce4b
commit a3e5a9b222
2 changed files with 8 additions and 0 deletions

View File

@ -2636,6 +2636,13 @@ guess_mime_type_by_ext(std::string ext) {
return "";
}
std::string
primary_file_extension_for_mime_type(std::string const &mime_type) {
auto itr = brng::find_if(mime_types, [&mime_type](auto const &m) { return m.name == mime_type; });
return (itr != mime_types.end()) && !itr->extensions.empty() ? itr->extensions[0] : std::string{};
}
#if HAVE_MAGIC_H
static std::string
guess_mime_type_by_content(magic_t &m,

View File

@ -37,6 +37,7 @@ extern std::vector<std::string> const g_popular_country_codes;
extern std::vector<mime_type_t> const mime_types;
std::string guess_mime_type(std::string ext, bool is_file);
std::string primary_file_extension_for_mime_type(std::string const &mime_type);
boost::optional<std::string> map_to_cctld(std::string const &s);
#endif // MTX_COMMON_EXTERN_DATA_H