From: Jakob Cornell Date: Sun, 1 Oct 2023 18:43:27 +0000 (-0500) Subject: Fix digit grouping bug in Rust number parsing typo detection X-Git-Url: https://jcornell.net/gitweb/gitweb.cgi?a=commitdiff_plain;h=b3d667765e9c961e09ac05d4d7578edfc9a93fb9;p=counting.git Fix digit grouping bug in Rust number parsing typo detection --- 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