From 25ec4983b0ceb017650ffd5f8275b19fd8fdef66 Mon Sep 17 00:00:00 2001 From: Daniel Drodt Date: Mon, 15 Jan 2024 12:08:08 +0100 Subject: [PATCH 1/9] Fix CSL attribute name (#8) --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6710b6d..166fa91 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -992,7 +992,7 @@ pub struct Citation { )] pub disambiguate_add_givenname: bool, /// When to expand names that are ambiguous in short form. - #[serde(rename = "@disambiguate-add-givenname-rule", default)] + #[serde(rename = "@givenname-disambiguation-rule", default)] pub givenname_disambiguation_rule: DisambiguationRule, /// Disambiguate by adding more names that would otherwise be hidden by et al. /// From a4ed7ae6b000cb6986dbe46436868ce61b5b94bd Mon Sep 17 00:00:00 2001 From: Kian-Meng Ang Date: Tue, 20 Feb 2024 17:06:46 +0800 Subject: [PATCH 2/9] Fix typos (#9) --- src/json.rs | 2 +- src/lib.rs | 10 +++++----- src/taxonomy.rs | 2 +- tests/independent/chicago-fullnote-bibliography.csl | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/json.rs b/src/json.rs index 4ee67ce..12aed14 100644 --- a/src/json.rs +++ b/src/json.rs @@ -382,7 +382,7 @@ pub struct CitationItem { pub locator: Option, /// What kind of locator to use (e.g. `"page"`). pub label: Option, - /// Whether to supress the author for this item. + /// Whether to suppress the author for this item. #[serde(default)] pub suppress_author: bool, /// Something to print before this item. diff --git a/src/lib.rs b/src/lib.rs index 166fa91..6771ef3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -622,7 +622,7 @@ pub enum StyleClass { pub enum PageRangeFormat { /// “321–28” /// Aliases: `chicago` until CSL 1.1 - // Rename needed because the number is not used as word boundry by heck. + // Rename needed because the number is not used as word boundary by heck. #[serde(alias = "chicago")] #[serde(rename = "chicago-15")] Chicago15, @@ -1217,7 +1217,7 @@ pub enum SubsequentAuthorSubstituteRule { CompleteAll, /// When all names match, replace each name. CompleteEach, - /// Each maching name is replaced. + /// Each matching name is replaced. PartialEach, /// Only the first matching name is replaced. PartialFirst, @@ -2122,7 +2122,7 @@ impl Names { } /// Convert a [`Names`] within a substitute to a name using the parent element. - pub fn from_names_substitue(&self, child: &Self) -> Names { + pub fn from_names_substitute(&self, child: &Self) -> Names { if child.name().is_some() || child.et_al().is_some() || child.substitute().is_some() @@ -2453,7 +2453,7 @@ impl NameOptions<'_> { return false; } - // If this is a subsequnt citation of the same item, use other CSL options + // If this is a subsequent citation of the same item, use other CSL options let (et_al_min, et_al_use_first) = if is_subsequent { (self.et_al_subsequent_min, self.et_al_subsequent_use_first) } else { @@ -2485,7 +2485,7 @@ pub enum DelimiterBehavior { /// (`-precedes-last`) names. #[default] Contextual, - /// Only use if the preceeding name is inverted (per `name-as-sort-order`). + /// Only use if the preceding name is inverted (per `name-as-sort-order`). AfterInvertedName, /// Always use the delimiter for this condition. Always, diff --git a/src/taxonomy.rs b/src/taxonomy.rs index 87d0762..1cfcf24 100644 --- a/src/taxonomy.rs +++ b/src/taxonomy.rs @@ -70,7 +70,7 @@ pub enum StandardVariable { CallNumber, /// Identifier of the item in the input data file (analogous to BibTeX /// entrykey); Use this variable to facilitate conversion between - /// word-processor and plain-text writing systems; For an identifer intended + /// word-processor and plain-text writing systems; For an identifier intended /// as formatted output label for a citation (e.g. “Ferr78”), use /// citation-label instead. CitationKey, diff --git a/tests/independent/chicago-fullnote-bibliography.csl b/tests/independent/chicago-fullnote-bibliography.csl index 23e94cd..1e9fe18 100644 --- a/tests/independent/chicago-fullnote-bibliography.csl +++ b/tests/independent/chicago-fullnote-bibliography.csl @@ -105,7 +105,7 @@ - + From be28dd4241ca6d7204f0cf5cddb34e6abe31f9a4 Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Tue, 20 Feb 2024 10:33:47 +0100 Subject: [PATCH 3/9] Add alias for `PrintingNumber` citation-style-language/locales@v0.0.12 introduces the non-standard printing variable. We assume it's an alias for `printing-number` --- src/lib.rs | 2 +- src/taxonomy.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6771ef3..c8485cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3571,7 +3571,7 @@ mod test { } /// Be sure to check out the CSL - /// [styles](https://github.com/citation-style-language/locales) repository + /// [styles](https://github.com/citation-style-language/styles) repository /// into a sibling folder to run this test. #[test] fn roundtrip_cbor_all() { diff --git a/src/taxonomy.rs b/src/taxonomy.rs index 1cfcf24..f25431f 100644 --- a/src/taxonomy.rs +++ b/src/taxonomy.rs @@ -296,6 +296,7 @@ pub enum NumberVariable { /// journal article); Use part-title for the title of the part, if any. PartNumber, /// Printing number of the item or container holding the item. + #[serde(alias = "printing")] PrintingNumber, /// Section of the item or container holding the item (e.g. “§2.0.1” for a /// law; “politics” for a newspaper article). From 1d3ae07cb604c7025fa51094bd6eb9ceef3f801c Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Wed, 28 Feb 2024 10:05:02 +0100 Subject: [PATCH 4/9] Saturate the power and do it in i64 Fixes typst/typst#3208 --- src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c8485cf..0d1fb2f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -712,18 +712,18 @@ fn expand(a: i32, b: i32) -> i32 { } fn changed_part(a: i32, b: i32, min: u32) -> i32 { - let mut base = (a.max(b) as f32).log10().floor() as u32; + let mut base = (a.max(b) as f64).log10().floor() as u32; // Check whether the digit at the given base is the same while { - let a_digit = a / 10_i32.pow(base); - let b_digit = b / 10_i32.pow(base); + let a_digit = a as i64 / 10_i64.saturating_pow(base); + let b_digit = b as i64 / 10_i64.saturating_pow(base); a_digit == b_digit && base > min } { base -= 1; } - b % 10_i32.pow(base + 1) + (b as i64 % 10_i64.saturating_pow(base + 1)) as i32 } /// How to treat the non-dropping name particle when printing names. @@ -3683,6 +3683,7 @@ mod test { // https://docs.citationstyles.org/en/stable/specification.html#appendix-v-page-range-formats + assert_eq!("1–8", run(c16, 1, 8)); assert_eq!("3–10", run(c15, 3, 10)); assert_eq!("71–72", run(c15, 71, 72)); assert_eq!("100–104", run(c15, 100, 4)); From eabda5e059ff23c20f2c9914aa279f36ac3c0697 Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Wed, 6 Mar 2024 15:39:57 +0100 Subject: [PATCH 5/9] Version bump --- Cargo.toml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index da45320..5b4e8d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "citationberg" -version = "0.1.1" +version = "0.2.0" authors = ["Martin Haug "] license = "MIT OR Apache-2.0" description = "A parser for CSL files" diff --git a/README.md b/README.md index f4131a2..532f580 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ A library for parsing CSL styles. ```toml [dependencies] -citationberg = "0.1" +citationberg = "0.2" ``` Citationberg deserializes CSL styles from XML into Rust structs. It supports From 42b7214f8ea68aeab78ca6e1f6503f49324944df Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Wed, 6 Mar 2024 16:32:41 +0100 Subject: [PATCH 6/9] Bump `quick-xml` --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5b4e8d4..7da3998 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ default = [] json = ["unscanny"] # adds support for CSL-json parsing [dependencies] -quick-xml = { version = "0.28", features = ["serialize", "overlapped-lists"] } +quick-xml = { version = "0.31", features = ["serialize", "overlapped-lists"] } serde = { version = "1.0", features = ["derive"] } unscanny = { version = "0.1.0", optional = true } From 778a5da601c615960e2dbe2153a33cd2c09ab1a8 Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Wed, 6 Mar 2024 16:35:48 +0100 Subject: [PATCH 7/9] Version bump --- Cargo.toml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7da3998..b2c5b86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "citationberg" -version = "0.2.0" +version = "0.3.0" authors = ["Martin Haug "] license = "MIT OR Apache-2.0" description = "A parser for CSL files" diff --git a/README.md b/README.md index 532f580..3f100db 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ A library for parsing CSL styles. ```toml [dependencies] -citationberg = "0.2" +citationberg = "0.3" ``` Citationberg deserializes CSL styles from XML into Rust structs. It supports From 89485c45a3229daed23efb3d26c42e7d7acd8bfd Mon Sep 17 00:00:00 2001 From: Astrick <33888523+AstrickHarren@users.noreply.github.com> Date: Mon, 8 Apr 2024 04:09:44 -0400 Subject: [PATCH 8/9] Fix fallback on subsequent name options not set (#11) --- src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0d1fb2f..1d35e0e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2453,9 +2453,12 @@ impl NameOptions<'_> { return false; } - // If this is a subsequent citation of the same item, use other CSL options + // If this is a subsequent citation of the same item, use other CSL options, if they exist let (et_al_min, et_al_use_first) = if is_subsequent { - (self.et_al_subsequent_min, self.et_al_subsequent_use_first) + ( + self.et_al_subsequent_min.or(self.et_al_min), + self.et_al_subsequent_use_first.or(self.et_al_use_first), + ) } else { (self.et_al_min, self.et_al_use_first) }; From 858782ed7c958354d9eb2f3a99f203ba383eb5ae Mon Sep 17 00:00:00 2001 From: Daniel Drodt Date: Mon, 8 Apr 2024 10:26:59 +0200 Subject: [PATCH 9/9] PageRangeFormat: Switch to InclusiveRange (#12) --- src/lib.rs | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1d35e0e..111c078 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -642,43 +642,44 @@ impl PageRangeFormat { /// Use a page range format to format a range of pages. pub fn format( self, - range: std::ops::Range, + range: std::ops::RangeInclusive, buf: &mut impl fmt::Write, separator: Option<&str>, ) -> Result<(), fmt::Error> { let separator = separator.unwrap_or("–"); - - write!(buf, "{}{}", range.start, separator)?; - let end = if range.end >= range.start { - range.end + let start = *range.start(); + if start == *range.end() { + return write!(buf, "{start}"); + } + write!(buf, "{}{}", start, separator)?; + let end = if *range.end() >= start { + *range.end() } else { - expand(range.start, range.end) + expand(start, *range.end()) }; match self { - _ if range.start < 0 || range.end < 0 => write!(buf, "{}", end), + _ if start < 0 || *range.end() < 0 => write!(buf, "{}", end), PageRangeFormat::Expanded => write!(buf, "{}", end), PageRangeFormat::Chicago15 | PageRangeFormat::Chicago16 - if range.start < 100 || range.start % 100 == 0 => + if start < 100 || start % 100 == 0 => { write!(buf, "{}", end) } PageRangeFormat::Minimal => { - write!(buf, "{}", changed_part(range.start, end, 0)) + write!(buf, "{}", changed_part(start, end, 0)) } PageRangeFormat::MinimalTwo if end < 10 => { - write!(buf, "{}", changed_part(range.start, end, 1)) + write!(buf, "{}", changed_part(start, end, 1)) } PageRangeFormat::Chicago15 - if range.start > 100 && (1..10).contains(&(range.start % 100)) => + if start > 100 && (1..10).contains(&(start % 100)) => { - write!(buf, "{}", changed_part(range.start, end, 0)) + write!(buf, "{}", changed_part(start, end, 0)) } - PageRangeFormat::Chicago15 - if closest_smaller_power_of_10(range.start) == 1000 => - { - let changed = changed_part(range.start, end, 1); + PageRangeFormat::Chicago15 if closest_smaller_power_of_10(start) == 1000 => { + let changed = changed_part(start, end, 1); if closest_smaller_power_of_10(changed) == 100 { write!(buf, "{end}") } else { @@ -688,7 +689,7 @@ impl PageRangeFormat { PageRangeFormat::Chicago15 | PageRangeFormat::Chicago16 | PageRangeFormat::MinimalTwo => { - write!(buf, "{}", changed_part(range.start, end, 1)) + write!(buf, "{}", changed_part(start, end, 1)) } } } @@ -3674,7 +3675,7 @@ mod test { fn page_range() { fn run(format: PageRangeFormat, start: i32, end: i32) -> String { let mut buf = String::new(); - format.format(start..end, &mut buf, None).unwrap(); + format.format(start..=end, &mut buf, None).unwrap(); buf }