From 8c035fbb2c1c1a0edd0dce04ed0a8ff496ef0401 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sun, 25 Oct 2026 03:51:09 +0000 Subject: [PATCH] Fields: \* ArabicDash formats any number field It is a general format switch, so NUMPAGES, PAGEREF, SEQ and formulas read it as PAGE does (#4226). --- crates/engine/src/cmd/table_formula.rs | 2 +- crates/layout/src/fields.rs | 23 ++++++----------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/crates/engine/src/cmd/table_formula.rs b/crates/engine/src/cmd/table_formula.rs index 0ee50057d..5707ff4b4 100644 --- a/crates/engine/src/cmd/table_formula.rs +++ b/crates/engine/src/cmd/table_formula.rs @@ -1027,7 +1027,7 @@ mod tests { assert_eq!(shown("=B2 \\* Hex"), shown("=B2")); assert_eq!(shown("=A2/4 \\* Hex"), shown("=A2/4"), "a fraction keeps its digits"); assert_eq!(shown("=A2*2200 \\* DollarText"), shown("=A2*2200"), "a number past DollarText keeps its digits"); - assert_eq!(shown("=A2 \\* ArabicDash"), "458", "ArabicDash is for page numbers only"); + assert_eq!(shown("=A2 \\* ArabicDash"), "- 458 -"); } #[test] diff --git a/crates/layout/src/fields.rs b/crates/layout/src/fields.rs index 88a6f03f0..5049369a1 100644 --- a/crates/layout/src/fields.rs +++ b/crates/layout/src/fields.rs @@ -126,19 +126,8 @@ pub(crate) fn reference_link(instr: &str) -> Option { } /// `\* FORMAT` switch value (Arabic, roman, ROMAN, alphabetic, ALPHABETIC, CardText, Ordinal, -/// DollarText, Hex…). +/// ArabicDash, DollarText, Hex…). `{ PAGE \* ArabicDash }` shows "- 31 -". pub fn format_switch(instr: &str) -> Option { - format_switch_of(instr, false) -} - -/// A PAGE field's `\* FORMAT` switch value: the values of [`format_switch`] and `\* ArabicDash` -/// (`{ PAGE \* ArabicDash }` shows "- 31 -"). Only PAGE reads `\* ArabicDash`; other fields, -/// PAGEREF included, skip it and read the next format switch. -pub fn page_format_switch(instr: &str) -> Option { - format_switch_of(instr, true) -} - -fn format_switch_of(instr: &str, page: bool) -> Option { let mut it = instr.split_whitespace(); while let Some(w) = it.next() { if let Some(rest) = w.strip_prefix("\\*") { @@ -153,7 +142,7 @@ fn format_switch_of(instr: &str, page: bool) -> Option { "OrdText" | "ordtext" => NumFormat::OrdinalText, "Ordinal" | "ordinal" => NumFormat::Ordinal, "Arabic" | "arabic" => NumFormat::Decimal, - "ArabicDash" | "arabicdash" | "ARABICDASH" if page => NumFormat::NumberInDash, + "ArabicDash" | "arabicdash" | "ARABICDASH" => NumFormat::NumberInDash, "DollarText" | "dollartext" | "DOLLARTEXT" => NumFormat::DollarText, "Hex" | "hex" | "HEX" => NumFormat::Hex, // Chinese numerals: counting (一百零一), legal (壹佰零壹), digit by digit (一〇一). @@ -293,7 +282,7 @@ pub fn field_text_on(instr: &str, result: &str, ctx: &FieldCtx, page: u32) -> (S let name = field_name(instr); let fmt = format_switch(instr); match name.as_str() { - "PAGE" => (field_number(instr, page_format_switch(instr).unwrap_or(ctx.page_format), page), true), + "PAGE" => (field_number(instr, format_switch(instr).unwrap_or(ctx.page_format), page), true), "NUMPAGES" => (field_number(instr, fmt.unwrap_or(NumFormat::Decimal), ctx.pages), true), "SECTIONPAGES" => (field_number(instr, fmt.unwrap_or(NumFormat::Decimal), ctx.section_pages), true), "SECTION" => (field_number(instr, fmt.unwrap_or(NumFormat::Decimal), ctx.section), true), @@ -441,7 +430,7 @@ mod tests { } /// `\* DollarText` writes lowercase cardinal text with "and 00/100", `\* Hex` uppercase - /// hexadecimal digits, and `\* ArabicDash` a page number between hyphens, on PAGE only. Words + /// hexadecimal digits, and `\* ArabicDash` the number between hyphens. Words /// stop at 999,999; a larger number keeps its digits. #[test] fn dollar_text_hex_and_arabic_dash_switches() { @@ -449,8 +438,8 @@ mod tests { let text = |instr: &str| field_text(instr, "", &ctx).0; assert_eq!(text(r"PAGE \* ArabicDash"), "- 31 -"); assert_eq!(text(r"PAGE \*arabicdash \* MERGEFORMAT"), "- 31 -"); - assert_eq!(text(r"NUMPAGES \* ArabicDash"), "458", "ArabicDash is for page numbers only"); - assert_eq!(text(r"NUMPAGES \* ArabicDash \* roman"), "cdlviii", "the next format switch counts"); + assert_eq!(text(r"NUMPAGES \* ArabicDash"), "- 458 -", "any number field reads ArabicDash"); + assert_eq!(text(r"NUMPAGES \* ArabicDash \* roman"), "- 458 -", "the first format switch counts"); assert_eq!(text(r"NUMPAGES \* Hex"), "1CA"); assert_eq!(text(r"NUMPAGES \* hex \* Lower"), "1ca"); assert_eq!(text(r"PAGE \* Hex"), "1F");