diff --git a/src/parser/util.rs b/src/parser/util.rs index 651de89a..849711a4 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -197,32 +197,6 @@ pub fn always_fail<'r, 's>(_context: Context<'r, 's>, input: &'s str) -> Res<&'s )))) } -/// Walk backwards unconsuming blank lines and line endings. -/// -/// List items are a special case where the trailing blank lines do not belong to it, unlike all other elements. Rather than write that special logic into each child parser, this just walks backwards through the consumed input to unconsume trailing blank lines and line breaks. -#[tracing::instrument(ret, level = "debug")] -pub fn regurgitate<'s>(input: &'s str, remaining: &'s str) -> &'s str { - assert!(is_slice_of(input, remaining)); - let mut offset = remaining.as_ptr() as usize - input.as_ptr() as usize; - let source = &input[..offset]; - let mut char_indices = source.char_indices().rev(); - loop { - match char_indices.next() { - Some((off, chr)) => { - if chr == '\n' { - offset = off; - } else if chr != ' ' && chr != '\t' { - return &input[offset..]; - } - } - None => { - // It was all whitespace, so return the full input string - return input; - } - }; - } -} - #[tracing::instrument(ret, level = "debug")] pub fn whitespace_eof(input: &str) -> Res<&str, &str> { recognize(tuple((multispace0, eof)))(input) @@ -256,14 +230,4 @@ mod tests { assert!(is_slice_of(input, yellow_heart)); assert_eq!(yellow_heart, "๐Ÿ’›"); } - - #[test] - fn regurgitate_unicode() { - let input = "๐Ÿงก๐Ÿ’›\n\t \t \n\n๐Ÿ’š๐Ÿ’™๐Ÿ’œ"; - let (green_heart_index, _) = input.char_indices().skip(12).next().unwrap(); - let starting_with_green_heart = &input[green_heart_index..]; - let after_yellow = regurgitate(input, starting_with_green_heart); - assert!(is_slice_of(input, after_yellow)); - assert_eq!(after_yellow, "\n\t \t \n\n๐Ÿ’š๐Ÿ’™๐Ÿ’œ"); - } }