Skip to content

Commit

Permalink
Minimal fix for IEEE bibliography ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
laurmaedje committed Mar 27, 2023
1 parent 67fefb5 commit d42d30f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/style/ieee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,6 @@ impl<'a> BibliographyStyle<'a> for Ieee {
}

fn ordering(&self) -> BibliographyOrdering {
BibliographyOrdering::ByPrefix
BibliographyOrdering::ByNumericPrefix
}
}
17 changes: 15 additions & 2 deletions src/style/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ impl Brackets {
pub enum BibliographyOrdering {
/// Order items by the alphanumerical order of their prefixes.
ByPrefix,
/// Order items by the numeric order of their prefixes.
ByNumericPrefix,
/// Order items by their authors, then titles, and finally dates.
ByAuthor,
/// Do not reorder. Bibliography will be in insertion order of the database.
Expand Down Expand Up @@ -915,10 +917,21 @@ fn sorted_bibliography(
) -> Vec<DisplayReference> {
match ordering {
BibliographyOrdering::ByPrefix => {
items.sort_unstable_by(|(a, _), (b, _)| a.prefix.cmp(&b.prefix));
items.sort_by(|(a, _), (b, _)| a.prefix.cmp(&b.prefix));
}
BibliographyOrdering::ByNumericPrefix => items.sort_by_key(|(reference, _)| {
reference.prefix.as_ref().and_then(|prefix| {
prefix
.value
.chars()
.filter(|c| c.is_numeric())
.collect::<String>()
.parse::<i64>()
.ok()
})
}),
BibliographyOrdering::ByAuthor => {
items.sort_unstable_by(|(a_ref, a_auths), (b_ref, b_auths)| {
items.sort_by(|(a_ref, a_auths), (b_ref, b_auths)| {
author_title_ord_custom(
a_ref.entry,
b_ref.entry,
Expand Down

0 comments on commit d42d30f

Please sign in to comment.