Skip to content

Commit

Permalink
fix the the char index in ChineseToNumberError
Browse files Browse the repository at this point in the history
  • Loading branch information
magiclen committed Dec 11, 2023
1 parent b54c306 commit dd6c6bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chinese-number"
version = "0.7.5"
version = "0.7.6"
authors = ["Magic Len <[email protected]>"]
edition = "2021"
rust-version = "1.58"
Expand Down
21 changes: 14 additions & 7 deletions src/chinese_to_number/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down

0 comments on commit dd6c6bb

Please sign in to comment.