diff options
Diffstat (limited to 'src/attr.rs')
-rw-r--r-- | src/attr.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/attr.rs b/src/attr.rs index a56eb95..4c7e330 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -30,8 +30,10 @@ pub struct AttributeMap<O> { #[derive(Debug, Eq, PartialEq)] pub(crate) struct AttrInternal<O> { pub value: String, - pub name_span: Range<O>, - pub value_span: Range<O>, + /// The start offset of the attribute name. + pub name_offset: O, + /// The start offset of the attribute value. + pub value_offset: O, } /// An HTML attribute borrowed from an [`AttributeMap`]. @@ -74,14 +76,14 @@ impl<'a, O: Offset> Attribute<'a, O> { &self.map_val.value } - /// Returns the span of the attribute name. + /// Calculates the span of the attribute name and returns it. pub fn name_span(&self) -> Range<O> { - self.map_val.name_span.clone() + self.map_val.name_offset..self.map_val.name_offset + self.name.len() } - /// Returns the span of the attribute value. + /// Calculates the span of the attribute value and returns it. pub fn value_span(&self) -> Range<O> { - self.map_val.value_span.clone() + self.map_val.value_offset..self.map_val.value_offset + self.map_val.value.len() } } @@ -154,8 +156,8 @@ impl<O: Default> FromIterator<(String, String)> for AttributeMap<O> { name, AttrInternal { value, - name_span: O::default()..O::default(), - value_span: O::default()..O::default(), + name_offset: O::default(), + value_offset: O::default(), }, ) }) @@ -163,3 +165,9 @@ impl<O: Default> FromIterator<(String, String)> for AttributeMap<O> { } } } + +impl<O: Offset> AttrInternal<O> { + pub(crate) fn name_span(&self, name_len: usize) -> Range<O> { + self.name_offset..self.name_offset + name_len + } +} |