From dd6c6bb9995f0016d018a851435aafb6f494cf2f Mon Sep 17 00:00:00 2001 From: Magic Len Date: Mon, 11 Dec 2023 16:44:29 +0800 Subject: [PATCH] fix the the char index in ChineseToNumberError --- Cargo.toml | 2 +- src/chinese_to_number/functions.rs | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bedb38d..3891b39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chinese-number" -version = "0.7.5" +version = "0.7.6" authors = ["Magic Len "] edition = "2021" rust-version = "1.58" diff --git a/src/chinese_to_number/functions.rs b/src/chinese_to_number/functions.rs index 098b08a..5352fa4 100644 --- a/src/chinese_to_number/functions.rs +++ b/src/chinese_to_number/functions.rs @@ -238,13 +238,20 @@ pub(crate) fn chinese_to_unsigned_integer( Some(exp) if exp >= ChineseExponent::百 => { let high = chinese_to_unsigned_integer(method, &chars[..pointer])?; - let low = chinese_to_unsigned_integer_unit( - method, - &chars[pointer..], - 0, - exp, - )? - .0 / 10; + let low = + chinese_to_unsigned_integer_unit(method, &chars[pointer..], 0, exp) + .map_err(|mut err| { + if let ChineseToNumberError::ChineseNumberIncorrect { + char_index, + } = &mut err + { + *char_index = pointer; + } + + err + })? + .0 + / 10; return high.checked_add(low).ok_or(ChineseToNumberError::Overflow); },