add builder methods to NodeMask
This commit is contained in:
1 parent
436c6a02f7
commit
b9c2664089
7 files changed
+45
-172
No files matched your search
@@ -181,18 +181,10 @@ pub struct NodeMask {
|
||||
}
|
||||
|
||||
impl NodeMask {
|
||||
pub const NONE: Self = Self::new(AttributeMask::Static(&[]), false, false, false);
|
||||
pub const ALL: Self = Self::new(AttributeMask::All, true, true, true);
|
||||
|
||||
/// attritutes must be sorted!
|
||||
pub const fn new(attritutes: AttributeMask, tag: bool, namespace: bool, text: bool) -> Self {
|
||||
Self {
|
||||
attritutes,
|
||||
tag,
|
||||
namespace,
|
||||
text,
|
||||
}
|
||||
}
|
||||
pub const NONE: Self = Self::new();
|
||||
pub const ALL: Self = Self::new_with_attrs(AttributeMask::All)
|
||||
.with_text()
|
||||
.with_element();
|
||||
|
||||
pub fn overlaps(&self, other: &Self) -> bool {
|
||||
(self.tag && other.tag)
|
||||
@@ -209,4 +201,36 @@ impl NodeMask {
|
||||
text: self.text | other.text,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn new_with_attrs(attritutes: AttributeMask) -> Self {
|
||||
Self {
|
||||
attritutes,
|
||||
tag: false,
|
||||
namespace: false,
|
||||
text: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn new() -> Self {
|
||||
Self::new_with_attrs(AttributeMask::NONE)
|
||||
}
|
||||
|
||||
pub const fn with_tag(mut self) -> Self {
|
||||
self.tag = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub const fn with_namespace(mut self) -> Self {
|
||||
self.namespace = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub const fn with_element(self) -> Self {
|
||||
self.with_namespace().with_tag()
|
||||
}
|
||||
|
||||
pub const fn with_text(mut self) -> Self {
|
||||
self.text = true;
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -169,10 +169,7 @@ impl<S: State> RealDom<S> {
|
||||
text: new_text,
|
||||
} => {
|
||||
let target = &mut self[root as usize];
|
||||
nodes_updated.push((
|
||||
root as usize,
|
||||
NodeMask::new(AttributeMask::NONE, false, false, true),
|
||||
));
|
||||
nodes_updated.push((root as usize, NodeMask::new().with_text()));
|
||||
match &mut target.node_type {
|
||||
NodeType::Text { text } => {
|
||||
*text = new_text.to_string();
|
||||
@@ -183,7 +180,7 @@ impl<S: State> RealDom<S> {
|
||||
SetAttribute { root, field, .. } => {
|
||||
nodes_updated.push((
|
||||
root as usize,
|
||||
NodeMask::new(AttributeMask::single(field), false, false, false),
|
||||
NodeMask::new_with_attrs(AttributeMask::single(field)),
|
||||
));
|
||||
}
|
||||
RemoveAttribute {
|
||||
@@ -191,7 +188,7 @@ impl<S: State> RealDom<S> {
|
||||
} => {
|
||||
nodes_updated.push((
|
||||
root as usize,
|
||||
NodeMask::new(AttributeMask::single(field), false, false, false),
|
||||
NodeMask::new_with_attrs(AttributeMask::single(field)),
|
||||
));
|
||||
}
|
||||
PopRoot {} => {
|
||||
|
||||
Reference in new issue
Block a user