From 6fb3586baacc590ef009ae4a2bd55e105be5e37c Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 3 Sep 2023 15:25:25 +1200 Subject: [PATCH] LibWeb: Add Optional version of Element::attribute As a non-deprecated alternative to DeprecatedString Element::attribute. --- Userland/Libraries/LibWeb/DOM/Element.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 0bf936d0ae..208d940926 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -92,6 +92,14 @@ public: bool has_attributes() const; DeprecatedString deprecated_attribute(DeprecatedFlyString const& name) const { return get_attribute(name); } + Optional attribute(DeprecatedFlyString const& name) const + { + auto ret = deprecated_attribute(name); + if (ret.is_null()) + return {}; + return String::from_deprecated_string(ret).release_value(); + } + DeprecatedString get_attribute(DeprecatedFlyString const& name) const; DeprecatedString get_attribute_value(DeprecatedFlyString const& local_name, DeprecatedFlyString const& namespace_ = {}) const;