Merge pull request #353 from GrimMaple/master

Add `in` support to `AttributeSet`. Add documentation
This commit is contained in:
Adam D. Ruppe 2022-12-16 11:15:57 -05:00 committed by GitHub
commit 22a9ddffca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);
}