mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibWeb: Port Element::get_attribute_value from ByteString
This commit is contained in:
parent
2751f32a18
commit
462f97b28a
Notes:
sideshowbarker
2024-07-16 22:14:49 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/462f97b28a Pull-request: https://github.com/SerenityOS/serenity/pull/22452
3 changed files with 9 additions and 8 deletions
|
@ -75,6 +75,7 @@
|
|||
#include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/UnsetStyleValue.h>
|
||||
#include <LibWeb/Dump.h>
|
||||
#include <LibWeb/Infra/CharacterTypes.h>
|
||||
#include <LibWeb/Infra/Strings.h>
|
||||
|
||||
static void log_parse_error(SourceLocation const& location = SourceLocation::current())
|
||||
|
@ -6976,11 +6977,11 @@ bool Parser::substitute_attr_function(DOM::Element& element, StringView property
|
|||
// with leading and trailing ASCII whitespace stripped. (No CSS parsing of the value is performed.)
|
||||
// If the attribute value, after trimming, is the empty string, there is instead no substitution value.
|
||||
// If the <custom-ident>’s value is a CSS-wide keyword or `default`, there is instead no substitution value.
|
||||
auto substitution_value = attribute_value.trim_whitespace();
|
||||
auto substitution_value = MUST(attribute_value.trim(Infra::ASCII_WHITESPACE));
|
||||
if (!substitution_value.is_empty()
|
||||
&& !substitution_value.equals_ignoring_ascii_case("default"sv)
|
||||
&& !is_css_wide_keyword(substitution_value)) {
|
||||
dest.empend(Token::create_ident(MUST(FlyString::from_deprecated_fly_string(substitution_value))));
|
||||
dest.empend(Token::create_ident(substitution_value));
|
||||
return true;
|
||||
}
|
||||
} else if (attribute_type.equals_ignoring_ascii_case("length"_fly_string)) {
|
||||
|
@ -7016,7 +7017,7 @@ bool Parser::substitute_attr_function(DOM::Element& element, StringView property
|
|||
// The substitution value is a CSS string, whose value is the literal value of the attribute.
|
||||
// (No CSS parsing or "cleanup" of the value is performed.)
|
||||
// No value triggers fallback.
|
||||
dest.empend(Token::create_string(MUST(FlyString::from_deprecated_fly_string(attribute_value))));
|
||||
dest.empend(Token::create_string(attribute_value));
|
||||
return true;
|
||||
} else if (attribute_type.equals_ignoring_ascii_case("time"_fly_string)) {
|
||||
// Parse a component value from the attribute’s value.
|
||||
|
@ -7033,7 +7034,7 @@ bool Parser::substitute_attr_function(DOM::Element& element, StringView property
|
|||
// The substitution value is a CSS <url> value, whose url is the literal value of the attribute.
|
||||
// (No CSS parsing or "cleanup" of the value is performed.)
|
||||
// No value triggers fallback.
|
||||
dest.empend(Token::create_url(MUST(FlyString::from_deprecated_fly_string(attribute_value))));
|
||||
dest.empend(Token::create_url(attribute_value));
|
||||
return true;
|
||||
} else {
|
||||
// Dimension units
|
||||
|
|
|
@ -130,17 +130,17 @@ ByteString Element::deprecated_get_attribute(StringView name) const
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-element-attributes-get-value
|
||||
ByteString Element::get_attribute_value(FlyString const& local_name, Optional<FlyString> const& namespace_) const
|
||||
String Element::get_attribute_value(FlyString const& local_name, Optional<FlyString> const& namespace_) const
|
||||
{
|
||||
// 1. Let attr be the result of getting an attribute given namespace, localName, and element.
|
||||
auto const* attribute = m_attributes->get_attribute_ns(namespace_, local_name);
|
||||
|
||||
// 2. If attr is null, then return the empty string.
|
||||
if (!attribute)
|
||||
return ByteString::empty();
|
||||
return String {};
|
||||
|
||||
// 3. Return attr’s value.
|
||||
return attribute->value().to_byte_string();
|
||||
return attribute->value();
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-getattributenode
|
||||
|
|
|
@ -103,7 +103,7 @@ public:
|
|||
// FIXME: This should be taking a 'FlyString const&' / 'Optional<FlyString> const&'
|
||||
Optional<String> get_attribute(StringView name) const;
|
||||
ByteString deprecated_get_attribute(StringView name) const;
|
||||
ByteString get_attribute_value(FlyString const& local_name, Optional<FlyString> const& namespace_ = {}) const;
|
||||
String get_attribute_value(FlyString const& local_name, Optional<FlyString> const& namespace_ = {}) const;
|
||||
|
||||
WebIDL::ExceptionOr<void> set_attribute(FlyString const& name, String const& value);
|
||||
|
||||
|
|
Loading…
Reference in a new issue