LibHTML: Basic element attribute parsing.

This commit is contained in:
Andreas Kling
2019-06-15 21:08:36 +02:00
parent 581d6b00c8
commit f8a86b5164
5 changed files with 194 additions and 17 deletions

View File

@@ -10,3 +10,40 @@ Element::~Element()
{
}
Attribute* Element::find_attribute(const String& name)
{
for (auto& attribute : m_attributes) {
if (attribute.name() == name)
return &attribute;
}
return nullptr;
}
const Attribute* Element::find_attribute(const String& name) const
{
for (auto& attribute : m_attributes) {
if (attribute.name() == name)
return &attribute;
}
return nullptr;
}
String Element::attribute(const String& name) const
{
if (auto* attribute = find_attribute(name))
return attribute->value();
return { };
}
void Element::set_attribute(const String& name, const String& value)
{
if (auto* attribute = find_attribute(name))
attribute->set_value(value);
else
m_attributes.append({ name, value });
}
void Element::set_attributes(Vector<Attribute>&& attributes)
{
m_attributes = move(attributes);
}