aboutsummaryrefslogtreecommitdiff
path: root/src/attr.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2023-08-31 05:18:49 +0200
committerMartin Fischer <martin@push-f.com>2023-09-03 23:00:05 +0200
commitd45e09a3157c71e3c95bf618a2b181f322c87a5d (patch)
tree0093a5b86f9234e7a92ba64e2112823159dc1f29 /src/attr.rs
parent42a18751eeaaa1637a5446bc5e4965815aa959c0 (diff)
fix!: wrong attribute value spans for char refs
Diffstat (limited to 'src/attr.rs')
-rw-r--r--src/attr.rs23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/attr.rs b/src/attr.rs
index f7161cf..72dfcd9 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -32,10 +32,10 @@ pub(crate) struct AttrInternal<O> {
pub value: String,
/// 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 `O::default()`.
- /// We intentionally don't use `Option<O>` here to spare us a byte (and padding) per attribute.
- pub value_offset: O,
+ /// The span of the attribute value.
+ /// For the empty attribute syntax this is just `O::default()..O::default()`.
+ /// We intentionally don't use `Option<Range<O>>` here to spare us a byte (and padding) per attribute.
+ pub value_span: Range<O>,
pub value_syntax: Option<AttrValueSyntax>,
}
@@ -67,9 +67,9 @@ pub struct AttributeOwned<O> {
pub value: String,
/// The start offset of the attribute name.
pub name_offset: O,
- /// The start offset of the attribute value.
+ /// The span of the attribute value.
/// `None` in case of the empty attribute syntax (e.g. `disabled` in `<input disabled>`).
- pub value_offset: Option<O>,
+ pub value_span: Option<Range<O>>,
/// The syntax of the attribute value.
/// `None` indicates the empty attribute syntax (e.g. `disabled` in `<input disabled>`).
pub value_syntax: Option<AttrValueSyntax>,
@@ -104,14 +104,14 @@ impl<'a, O: Offset> Attribute<'a, O> {
self.map_val.name_offset..self.map_val.name_offset + self.name.len()
}
- /// For explicitly defined values calculates the span of the attribute value and returns it.
+ /// For explicitly defined values returns the span of the attribute value.
///
/// 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())
+ Some(self.map_val.value_span.clone())
}
/// Returns the attribute value syntax in case the value is explicitly defined.
@@ -158,10 +158,7 @@ impl<O> Iterator for AttrIntoIter<O> {
name,
value: map_val.value,
name_offset: map_val.name_offset,
- value_offset: map_val
- .value_syntax
- .is_some()
- .then_some(map_val.value_offset),
+ value_span: map_val.value_syntax.is_some().then_some(map_val.value_span),
value_syntax: map_val.value_syntax,
})
}
@@ -200,7 +197,7 @@ impl<O: Default> FromIterator<(String, String)> for AttributeMap<O> {
AttrInternal {
value,
name_offset: O::default(),
- value_offset: O::default(),
+ value_span: O::default()..O::default(),
value_syntax: Some(AttrValueSyntax::DoubleQuoted),
},
)