Add implementations to calculate the new fields for heading.

This commit is contained in:
Tom Alexander 2023-10-31 23:46:53 -04:00
parent 03754be71e
commit 425bc12353
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 31 additions and 3 deletions

View File

@ -94,11 +94,39 @@ impl<'s> StandardProperties<'s> for Heading<'s> {
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
let first_child = self.children.first();
let last_child = self.children.last();
match (first_child, last_child) {
(None, None) => None,
(None, Some(_)) | (Some(_), None) => unreachable!(),
(Some(first_child), Some(last_child)) => {
let first_child_offset = first_child.get_source().as_ptr() as usize;
let last_child_offset = {
let last_child_source = last_child.get_source();
last_child_source.as_ptr() as usize + last_child_source.len()
};
let source_offset = self.source.as_ptr() as usize;
debug_assert!(super::lesser_element::is_slice_of(
self.source,
first_child.get_source()
));
debug_assert!(super::lesser_element::is_slice_of(
self.source,
last_child.get_source()
));
Some(
&self.source[(first_child_offset - source_offset)
..(last_child_offset - first_child_offset)],
)
}
}
}
fn get_post_blank(&self) -> PostBlank {
todo!()
self.children
.last()
.map(|child| child.get_post_blank())
.unwrap_or(0)
}
}

View File

@ -610,7 +610,7 @@ fn content_line<'s>(input: &'s str) -> Res<&'s str, (Option<&'s str>, &'s str)>
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
/// Check if the child string slice is a slice of the parent string slice.
fn is_slice_of(parent: &str, child: &str) -> bool {
pub(crate) fn is_slice_of(parent: &str, child: &str) -> bool {
let parent_start = parent.as_ptr() as usize;
let parent_end = parent_start + parent.len();
let child_start = child.as_ptr() as usize;