Add `in` support to `AttributeSet`. Add documentation

This commit is contained in:
Grim Maple 2022-12-16 18:53:49 +03:00
parent 90ab8167fe
commit a58e589414
1 changed files with 285 additions and 272 deletions

15
dom.d
View File

@ -4152,13 +4152,26 @@ struct AttributeSet {
}
private Element _element;
///
/// Sets a `value` for `attribute`. If doens't exists, creates it
string set(string name, string value) {
_element.setAttribute(name, value);
return value;
}
/// Provides support for testing with `in`
auto opBinaryRight(string op : "in")(string name) const
{
return name in _element.attributes;
}
///
unittest
{
auto doc = new XmlDocument(`<test attr="test"/>`);
assert("attr" in doc.root.attrs);
assert("test" !in doc.root.attrs);
}
/// Returns attribute `name`, or `null` if doesn't exist
string get(string name) const {
return _element.getAttribute(name);
}