mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:14:58 +00:00
LibCore: Replace MIME type description lookup with a more generic method
Rather than adding a bunch of `get_*_from_mime_type` functions, add just one to get the Core::MimeType instance. We will need multiple fields at once in Browser.
This commit is contained in:
parent
6760d236e4
commit
1f44c9468a
3 changed files with 8 additions and 8 deletions
|
@ -168,14 +168,14 @@ Optional<StringView> guess_mime_type_based_on_sniffed_bytes(ReadonlyBytes bytes)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<StringView> get_description_from_mime_type(StringView mime_name)
|
Optional<MimeType const&> get_mime_type_data(StringView mime_name)
|
||||||
{
|
{
|
||||||
for (auto const& mime_type : s_registered_mime_type) {
|
for (auto const& mime_type : s_registered_mime_type) {
|
||||||
if (mime_name == mime_type.name)
|
if (mime_name == mime_type.name)
|
||||||
return mime_type.description;
|
return mime_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
return OptionalNone {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<StringView> guess_mime_type_based_on_sniffed_bytes(Core::File& file)
|
Optional<StringView> guess_mime_type_based_on_sniffed_bytes(Core::File& file)
|
||||||
|
|
|
@ -61,6 +61,6 @@ struct MimeType {
|
||||||
u64 offset { 0 };
|
u64 offset { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
Optional<StringView> get_description_from_mime_type(StringView);
|
Optional<MimeType const&> get_mime_type_data(StringView);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,17 +168,17 @@ static constexpr Array s_pattern_with_specialized_functions {
|
||||||
|
|
||||||
static ErrorOr<Optional<String>> get_description_from_mime_type(StringView mime, StringView path)
|
static ErrorOr<Optional<String>> get_description_from_mime_type(StringView mime, StringView path)
|
||||||
{
|
{
|
||||||
auto const description = Core::get_description_from_mime_type(mime);
|
auto const mime_type = Core::get_mime_type_data(mime);
|
||||||
|
|
||||||
if (!description.has_value())
|
if (!mime_type.has_value())
|
||||||
return OptionalNone {};
|
return OptionalNone {};
|
||||||
|
|
||||||
for (auto const& pattern : s_pattern_with_specialized_functions) {
|
for (auto const& pattern : s_pattern_with_specialized_functions) {
|
||||||
if (mime.matches(pattern.matching_pattern))
|
if (mime.matches(pattern.matching_pattern))
|
||||||
return pattern.details(*description, path);
|
return pattern.details(mime_type->description, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return description_only(*description, path);
|
return description_only(mime_type->description, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue