Suprised by error from `is_not` on empty result
barskern opened this issue · 1 comments
barskern commented
I was suprised when using is_not
that it errored when the resulting slice is empty, despite the fact that it finds the terminating character. I would think that it should only 'care' about finding the terminating character (similarly to take_till
), and that it shouldn't enforce anything regarding the output. I assumed the following test case would hold. Is this the intended behaviour?
Prerequisites
Here are a few things you should provide to help me understand the issue:
- Rust version :
rustc 1.78.0 (9b00956e5 2024-04-29)
- nom version :
7.1.3
- nom compilation features used: default
Test case
#[test]
fn nom_bytes_is_not_assumption() {
use nom::Parser;
let input = "\n";
let mut p = nom::bytes::complete::is_not::<_, _, nom::error::VerboseError<&str>>("\r\n\t");
let (rem, v) = p.parse(input).unwrap();
assert_eq!("", v);
assert_eq!(input, rem);
}
docwilco commented
is_not
wants at least one character to match. It's basically is_not1
and not is_not0
.
Now I would suggest making two parsers, is_not0
and is_not1
. To make this distinction clear, and make it consistent with all the other foo0
and foo1
functions.