1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:07:35 +00:00

LibWeb: Add a non-DeprecatedString version of Element::get_attribute

Renaming the DeprecatedString version of this function to
Element::get_deprecated_attribute.

While performing this rename, port over functions where it is trivial to
do so to the Optional<String> version of this function.
This commit is contained in:
Shannon Booth 2023-10-01 17:46:26 +13:00 committed by Andreas Kling
parent ebe01b51c8
commit 50350fb79c
17 changed files with 52 additions and 56 deletions

View file

@ -133,7 +133,7 @@ void Element::visit_edges(Cell::Visitor& visitor)
}
// https://dom.spec.whatwg.org/#dom-element-getattribute
DeprecatedString Element::get_attribute(StringView name) const
Optional<String> Element::get_attribute(StringView name) const
{
// 1. Let attr be the result of getting an attribute given qualifiedName and this.
auto const* attribute = m_attributes->get_attribute(name);
@ -143,7 +143,16 @@ DeprecatedString Element::get_attribute(StringView name) const
return {};
// 3. Return attrs value.
return attribute->value().to_deprecated_string();
return attribute->value();
}
DeprecatedString Element::deprecated_get_attribute(StringView name) const
{
auto maybe_attribute = get_attribute(name);
if (!maybe_attribute.has_value())
return {};
return maybe_attribute->to_deprecated_string();
}
// https://dom.spec.whatwg.org/#concept-element-attributes-get-value