1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:28:12 +00:00

LibHTML: Add StyleProperties::string_or_fallback()

This is an utility to go with the existing length_or_fallback().
This commit is contained in:
Sergey Bugaev 2019-09-25 11:55:04 +03:00 committed by Andreas Kling
parent 08d9883306
commit 08c751d130
2 changed files with 9 additions and 0 deletions

View file

@ -20,3 +20,11 @@ Length StyleProperties::length_or_fallback(const StringView& property_name, cons
return fallback;
return value.value()->to_length();
}
String StyleProperties::string_or_fallback(const StringView& property_name, const StringView& fallback) const
{
auto value = property(property_name);
if (!value.has_value())
return fallback;
return value.value()->to_string();
}

View file

@ -17,6 +17,7 @@ public:
Optional<NonnullRefPtr<StyleValue>> property(const String& name) const;
Length length_or_fallback(const StringView& property_name, const Length& fallback) const;
String string_or_fallback(const StringView& property_name, const StringView& fallback) const;
private:
HashMap<String, NonnullRefPtr<StyleValue>> m_property_values;