aboutsummaryrefslogtreecommitdiff
path: root/src/attr.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2023-09-01 12:07:51 +0200
committerMartin Fischer <martin@push-f.com>2023-09-03 23:00:05 +0200
commit0581e619867bde2374376265b24169b404187529 (patch)
tree04b369238b4e13af15fed2324423d1e86d22aaf6 /src/attr.rs
parentf239037c1b960ba16c6c8b2184ac017c53c631bf (diff)
fix!: make attribute spans encoding-independent
Diffstat (limited to 'src/attr.rs')
-rw-r--r--src/attr.rs22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/attr.rs b/src/attr.rs
index 72dfcd9..096235e 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -30,8 +30,8 @@ pub struct AttributeMap<O> {
#[derive(Debug, Eq, PartialEq)]
pub(crate) struct AttrInternal<O> {
pub value: String,
- /// The start offset of the attribute name.
- pub name_offset: O,
+ /// The span of the attribute name.
+ pub name_span: Range<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.
@@ -65,8 +65,8 @@ pub struct AttributeOwned<O> {
pub name: String,
/// The attribute value. Character references have been resolved.
pub value: String,
- /// The start offset of the attribute name.
- pub name_offset: O,
+ /// The span of the attribute name.
+ pub name_span: Range<O>,
/// The span of the attribute value.
/// `None` in case of the empty attribute syntax (e.g. `disabled` in `<input disabled>`).
pub value_span: Option<Range<O>>,
@@ -99,9 +99,9 @@ impl<'a, O: Offset> Attribute<'a, O> {
&self.map_val.value
}
- /// Calculates the span of the attribute name and returns it.
+ /// Returns the span of the attribute name.
pub fn name_span(&self) -> Range<O> {
- self.map_val.name_offset..self.map_val.name_offset + self.name.len()
+ self.map_val.name_span.clone()
}
/// For explicitly defined values returns the span of the attribute value.
@@ -157,7 +157,7 @@ impl<O> Iterator for AttrIntoIter<O> {
Some(AttributeOwned {
name,
value: map_val.value,
- name_offset: map_val.name_offset,
+ name_span: map_val.name_span,
value_span: map_val.value_syntax.is_some().then_some(map_val.value_span),
value_syntax: map_val.value_syntax,
})
@@ -196,7 +196,7 @@ impl<O: Default> FromIterator<(String, String)> for AttributeMap<O> {
name,
AttrInternal {
value,
- name_offset: O::default(),
+ name_span: O::default()..O::default(),
value_span: O::default()..O::default(),
value_syntax: Some(AttrValueSyntax::DoubleQuoted),
},
@@ -206,9 +206,3 @@ 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
- }
-}