Skip to content

Commit

Permalink
Fix regression introduced in #155
Browse files Browse the repository at this point in the history
  • Loading branch information
reknih committed Oct 1, 2024
1 parent 10ce27b commit 2f8a083
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/types/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl PageRanges {

/// Get the first page of the first range.
pub fn first(&self) -> Option<&Numeric> {
self.ranges.first().and_then(PageRangesPart::start)
self.ranges.iter().find_map(PageRangesPart::start)
}

/// Order the values according to CSL rules.
Expand Down Expand Up @@ -59,7 +59,20 @@ impl PageRanges {

/// Whether to pluralize the `pages` term, when used with this page range.
pub fn is_plural(&self) -> bool {
self.ranges.len() != 1
let mut count = 0;
for range in &self.ranges {
match range {
PageRangesPart::SinglePage(_) => count += 1,
PageRangesPart::Range(s, e) | PageRangesPart::EscapedRange(s, e) => {
if s != e {
return true;
}
count += 1
}
_ => {}
}
}
count > 1
}
}

Expand Down Expand Up @@ -104,7 +117,7 @@ pub enum PageRangesPart {
}

impl PageRangesPart {
/// The start of a range if any.
/// The start of a range, if any.
pub fn start(&self) -> Option<&Numeric> {
match self {
Self::EscapedRange(s, _) => Some(s),
Expand All @@ -114,6 +127,16 @@ impl PageRangesPart {
}
}

/// The end of a range, if any.
pub fn end(&self) -> Option<&Numeric> {
match self {
Self::EscapedRange(_, e) => Some(e),
Self::Range(_, e) => Some(e),
Self::SinglePage(_) => None,
_ => None,
}
}

/// Order the values according to CSL rules.
pub(crate) fn csl_cmp(&self, other: &Self) -> std::cmp::Ordering {
match (self, other) {
Expand Down

0 comments on commit 2f8a083

Please sign in to comment.