Fix digit grouping bug in Rust number parsing typo detection
authorJakob Cornell <jakob+gpg@jcornell.net>
Sun, 1 Oct 2023 18:43:27 +0000 (13:43 -0500)
committerJakob Cornell <jakob+gpg@jcornell.net>
Sun, 1 Oct 2023 18:43:27 +0000 (13:43 -0500)
sharedmodel/src/update_parse.rs

index 5e3f0c9ef5d98798995cdf03e2e236e82cfcf23b..ed05cea08b099a2d5999ce324fff44c1ecb70c46 100644 (file)
@@ -199,6 +199,14 @@ fn parse_from_lines(lines: &[impl Borrow<str>], curr_count: Option<Count>, 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<&[u8]>> = 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<str>], curr_count: Option<Count>, 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