mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:27:44 +00:00
LibWeb: Parse and match basic "contains" attribute selectors (~=)
This commit is contained in:
parent
a38a5d50ab
commit
65c4e5cacf
4 changed files with 15 additions and 2 deletions
|
@ -63,6 +63,7 @@ public:
|
||||||
None,
|
None,
|
||||||
HasAttribute,
|
HasAttribute,
|
||||||
ExactValueMatch,
|
ExactValueMatch,
|
||||||
|
Contains,
|
||||||
};
|
};
|
||||||
|
|
||||||
AttributeMatchType attribute_match_type { AttributeMatchType::None };
|
AttributeMatchType attribute_match_type { AttributeMatchType::None };
|
||||||
|
|
|
@ -91,6 +91,10 @@ bool matches(const Selector::SimpleSelector& component, const Element& element)
|
||||||
if (element.attribute(component.attribute_name) != component.attribute_value)
|
if (element.attribute(component.attribute_name) != component.attribute_value)
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
|
case Selector::SimpleSelector::AttributeMatchType::Contains:
|
||||||
|
if (!element.attribute(component.attribute_name).split(' ').contains_slow(component.attribute_value))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,6 +242,9 @@ void dump_selector(const Selector& selector)
|
||||||
case Selector::SimpleSelector::AttributeMatchType::ExactValueMatch:
|
case Selector::SimpleSelector::AttributeMatchType::ExactValueMatch:
|
||||||
attribute_match_type_description = "ExactValueMatch";
|
attribute_match_type_description = "ExactValueMatch";
|
||||||
break;
|
break;
|
||||||
|
case Selector::SimpleSelector::AttributeMatchType::Contains:
|
||||||
|
attribute_match_type_description = "Contains";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbgprintf("%s:%s", type_description, simple_selector.value.characters());
|
dbgprintf("%s:%s", type_description, simple_selector.value.characters());
|
||||||
|
|
|
@ -472,8 +472,13 @@ public:
|
||||||
char expected_end_of_attribute_selector = ']';
|
char expected_end_of_attribute_selector = ']';
|
||||||
while (peek() != expected_end_of_attribute_selector) {
|
while (peek() != expected_end_of_attribute_selector) {
|
||||||
char ch = consume_one();
|
char ch = consume_one();
|
||||||
if (ch == '=') {
|
if (ch == '=' || (ch == '~' && peek() == '=')) {
|
||||||
attribute_match_type = Selector::SimpleSelector::AttributeMatchType::ExactValueMatch;
|
if (ch == '=') {
|
||||||
|
attribute_match_type = Selector::SimpleSelector::AttributeMatchType::ExactValueMatch;
|
||||||
|
} else if (ch == '~') {
|
||||||
|
consume_one();
|
||||||
|
attribute_match_type = Selector::SimpleSelector::AttributeMatchType::Contains;
|
||||||
|
}
|
||||||
attribute_name = String::copy(buffer);
|
attribute_name = String::copy(buffer);
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
in_value = true;
|
in_value = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue