From a868bc616db04b63e998fdce4158bf46d58b16bf Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Thu, 26 Nov 2026 06:59:37 +0100 Subject: [PATCH] NumberCodec::explicit_plus: the sign's digit in any script the reader reads Review (CodeRabbit): the guard after the sign asked is_ascii_digit, so "+\u{663}" (Arabic-Indic 3) failed it and fell through to the reader, which read the plus as relative: 13 for a start of 10. The guard now uses the reader's own digit class, so any supported script's digit keeps the sign the number's, and a plain field's relative reading is unchanged. --- crates/behavior/src/codec.rs | 6 +++++- crates/behavior/src/quantity.rs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/behavior/src/codec.rs b/crates/behavior/src/codec.rs index 63d0012027..0177419992 100644 --- a/crates/behavior/src/codec.rs +++ b/crates/behavior/src/codec.rs @@ -331,7 +331,7 @@ impl NumberCodec { // relative `+` nor the share of the start value. if self.plus && let Some(rest) = trimmed.strip_prefix('+') - && rest.trim_start().starts_with(|c: char| c.is_ascii_digit() || c == self.reader.decimal_separator()) + && rest.trim_start().starts_with(|c: char| crate::quantity::digit(c).is_some() || c == self.reader.decimal_separator()) { return self.parse_tagged_with(rest.trim_start(), &None, false); } @@ -480,6 +480,10 @@ mod review_tests { assert!(angle.parse("+", &Some(10.0)).is_err(), "a lone plus stays no number"); let plain = NumberCodec::new(Reader::new(), 2); assert_eq!(plain.parse("+ 2", &Some(10.0)).ok(), Some(Some(12.0)), "a plain field's plus still adds to the start"); + // The digit after the sign may be written in any script the reader reads: Arabic-Indic ٣ is 3. + assert_eq!(angle.parse("+\u{663}", &Some(10.0)).ok(), Some(Some(3.0)), "a sign before an Arabic-Indic digit is still the number's"); + assert_eq!(angle.parse("\u{663}", &Some(10.0)).ok(), Some(Some(3.0)), "and the reader reads that digit as before"); + assert_eq!(plain.parse("+\u{663}", &Some(10.0)).ok(), Some(Some(13.0)), "a plain field still adds it to the start"); } /// A share field's signed percentage is that number, not a share of the start value again. diff --git a/crates/behavior/src/quantity.rs b/crates/behavior/src/quantity.rs index 0aae495027..58009eb615 100644 --- a/crates/behavior/src/quantity.rs +++ b/crates/behavior/src/quantity.rs @@ -7,7 +7,7 @@ use crate::codec::NotAValue; const DIGIT_BLOCKS: [u32; 5] = [0x30, 0x660, 0x6F0, 0x966, 0xFF10]; /// The value of a decimal digit of any supported script. -fn digit(c: char) -> Option { +pub(crate) fn digit(c: char) -> Option { DIGIT_BLOCKS.iter().find_map(|&zero| (zero..zero + 10).contains(&(c as u32)).then(|| c as u32 - zero)) }