From b3d667765e9c961e09ac05d4d7578edfc9a93fb9 Mon Sep 17 00:00:00 2001 From: Jakob Cornell Date: Sun, 1 Oct 2023 13:43:27 -0500 Subject: [PATCH] Fix digit grouping bug in Rust number parsing typo detection --- sharedmodel/src/update_parse.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sharedmodel/src/update_parse.rs b/sharedmodel/src/update_parse.rs index 5e3f0c9..ed05cea 100644 --- a/sharedmodel/src/update_parse.rs +++ b/sharedmodel/src/update_parse.rs @@ -199,6 +199,14 @@ fn parse_from_lines(lines: &[impl Borrow], curr_count: Option, bot_u let goal_string = count_val.abs().to_string(); let goal_parts: Vec<&[u8]> = goal_string.as_bytes().rchunks(3).rev().collect(); let (&last, front) = goal_parts.split_last().unwrap(); + + // TODO try refactoring so 'partials' owns the character data; might be + // cleaner + let last_part_missing_second_last_char = [ + last.get(..last.len() - 2).unwrap(), + slice::from_ref(&last[last.len() - 1]) + ].concat(); + let partials: Vec> = vec![ // missing last digit front.iter().cloned().chain([last.get(..last.len() - 1).unwrap()]).collect(), @@ -207,10 +215,7 @@ fn parse_from_lines(lines: &[impl Borrow], curr_count: Option, bot_u front.iter().cloned().chain([last.get(..last.len() - 2).unwrap()]).collect(), // missing second-last digit - front.iter().cloned().chain([ - last.get(..last.len() - 2).unwrap(), - slice::from_ref(&last[last.len() - 1]), - ]).collect(), + front.iter().cloned().chain([&last_part_missing_second_last_char[..]]).collect(), ]; // missing any of last two digits or double paste -- 2.30.2