mirror of https://github.com/adamdruppe/arsd.git
Merge pull request #353 from GrimMaple/master
Add `in` support to `AttributeSet`. Add documentation
This commit is contained in:
commit
22a9ddffca
15
dom.d
15
dom.d
|
@ -4152,13 +4152,26 @@ struct AttributeSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Element _element;
|
private Element _element;
|
||||||
///
|
/// Sets a `value` for `attribute`. If doens't exists, creates it
|
||||||
string set(string name, string value) {
|
string set(string name, string value) {
|
||||||
_element.setAttribute(name, value);
|
_element.setAttribute(name, value);
|
||||||
return 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 {
|
string get(string name) const {
|
||||||
return _element.getAttribute(name);
|
return _element.getAttribute(name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue