diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/attr.rs | 21 | 
1 files changed, 16 insertions, 5 deletions
| diff --git a/src/attr.rs b/src/attr.rs index d062a84..48ae5b0 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -33,6 +33,8 @@ pub(crate) struct AttrInternal<O> {      /// The start offset of the attribute name.      pub name_offset: O,      /// The start offset of the attribute value. +    /// For the empty attribute syntax this is just `S::Offset::default()`. +    /// We intentionally don't use `Option<S::Offset>` here to spare us a byte per attribute.      pub value_offset: O,      pub value_syntax: Option<AttrValueSyntax>,  } @@ -65,7 +67,8 @@ pub struct AttributeOwned<O> {      /// The start offset of the attribute name.      pub name_offset: O,      /// The start offset of the attribute value. -    pub value_offset: O, // TODO: wrap this in an Option once we can recognize the empty attribute syntax +    /// `None` in case of the empty attribute syntax (e.g. `disabled` in `<input disabled>`). +    pub value_offset: Option<O>,      /// The syntax of the attribute value.      /// `None` indicates the empty attribute syntax (e.g. `disabled` in `<input disabled>`).      pub value_syntax: Option<AttrValueSyntax>, @@ -96,9 +99,14 @@ impl<'a, O: Offset> Attribute<'a, O> {          self.map_val.name_offset..self.map_val.name_offset + self.name.len()      } -    /// Calculates the span of the attribute value and returns it. -    pub fn value_span(&self) -> Range<O> { -        self.map_val.value_offset..self.map_val.value_offset + self.map_val.value.len() +    /// For explicitly defined values calculates the span of the attribute value and returns it. +    /// +    /// Returns `None` for attributes using the empty attribute syntax (e.g. `disabled` in `<input disabled>`). +    pub fn value_span(&self) -> Option<Range<O>> { +        if self.map_val.value_syntax.is_none() { +            return None; +        } +        Some(self.map_val.value_offset..self.map_val.value_offset + self.map_val.value.len())      }      /// Returns the attribute value syntax in case the value is explicitly defined. @@ -141,7 +149,10 @@ impl<O> Iterator for AttrIntoIter<O> {              name,              value: map_val.value,              name_offset: map_val.name_offset, -            value_offset: map_val.value_offset, +            value_offset: map_val +                .value_syntax +                .is_some() +                .then_some(map_val.value_offset),              value_syntax: map_val.value_syntax,          })      } | 
