From 3999fca9e671e262cdd0ec104e9f6f6cfb623dd4 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Thu, 15 Sep 2022 11:50:53 +1200 Subject: [PATCH] Fix parsing of ingredients with addendum but no unit Where an ingredient has no unit (for example, 2 eggs), the parser was interpreting `{eggs, 2, large}` as "2, large of eggs", instead of as "2 eggs (large)". --- src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b7db9df..e961f1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -102,6 +102,11 @@ fn capture(chars: &[char]) -> Option<(Ingredient, usize)> { unit = Some(String::new()); break; } + Some(&',') => { + i += 1; + addendum = Some(String::new()); + break; + } Some(&'}') => { i += 1; break; @@ -115,6 +120,7 @@ fn capture(chars: &[char]) -> Option<(Ingredient, usize)> { } // Unit + if let Some(ref mut unit) = unit { loop { match chars.get(i) {