Skip to content

Commit

Permalink
Print bibliography
Browse files Browse the repository at this point in the history
  • Loading branch information
reknih committed Oct 18, 2023
1 parent 9d1135e commit 66d4146
Show file tree
Hide file tree
Showing 3 changed files with 371 additions and 38 deletions.
33 changes: 33 additions & 0 deletions src/csl/elem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,31 @@ impl ElemChildren {
None
}

/// Remove the first child with a matching meta by DFS.
pub(super) fn remove_meta(&mut self, meta: ElemMeta) -> bool {
for i in 0..self.0.len() {
if let ElemChild::Elem(e) = &mut self.0[i] {
if e.meta == Some(meta) {
self.0.remove(i);
return true;
}

if e.children.remove_meta(meta) {
return true;
}
}
}

false
}

pub(super) fn last_text_mut(&mut self) -> Option<&mut String> {
self.0.last_mut().and_then(|c| match c {
ElemChild::Text(t) => Some(&mut t.text),
ElemChild::Elem(e) => e.children.last_text_mut(),
})
}

/// Write the children to the given buffer.
pub fn write_buf(
&self,
Expand Down Expand Up @@ -469,6 +494,14 @@ impl<T> NonEmptyStack<T> {
}
}

pub fn get_mut(&mut self, idx: usize) -> Option<&mut T> {
if idx == self.head.len() {
Some(&mut self.last)
} else {
self.head.get_mut(idx)
}
}

/// Drains all elements including and after the given index.
pub fn drain(&mut self, idx: NonZeroUsize) -> impl Iterator<Item = T> + '_ {
let idx = idx.get();
Expand Down
Loading

0 comments on commit 66d4146

Please sign in to comment.