From 08c751d130afe63e75054d52fd02fd339d224d53 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Wed, 25 Sep 2019 11:55:04 +0300 Subject: [PATCH] LibHTML: Add StyleProperties::string_or_fallback() This is an utility to go with the existing length_or_fallback(). --- Libraries/LibHTML/CSS/StyleProperties.cpp | 8 ++++++++ Libraries/LibHTML/CSS/StyleProperties.h | 1 + 2 files changed, 9 insertions(+) diff --git a/Libraries/LibHTML/CSS/StyleProperties.cpp b/Libraries/LibHTML/CSS/StyleProperties.cpp index 9cdf4af97c..8bf9108911 100644 --- a/Libraries/LibHTML/CSS/StyleProperties.cpp +++ b/Libraries/LibHTML/CSS/StyleProperties.cpp @@ -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(); +} diff --git a/Libraries/LibHTML/CSS/StyleProperties.h b/Libraries/LibHTML/CSS/StyleProperties.h index d449363de5..4deca177b1 100644 --- a/Libraries/LibHTML/CSS/StyleProperties.h +++ b/Libraries/LibHTML/CSS/StyleProperties.h @@ -17,6 +17,7 @@ public: Optional> 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> m_property_values;