Function nom8::character::recognize_float
source · pub fn recognize_float<T, E: ParseError<T>, const STREAMING: bool>(
input: T
) -> IResult<T, <T as IntoOutput>::Output, E>where
T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>> + Clone + Offset + InputIter + InputLength + InputIsStreaming<STREAMING> + IntoOutput + InputTakeAtPosition,
<T as InputIter>::Item: AsChar,
<T as InputTakeAtPosition>::Item: AsChar,
Expand description
Recognizes floating point number in a byte string and returns the corresponding slice.
Complete version: Can parse until the end of input.
Streaming version: Will return Err(nom8::Err::Incomplete(_))
if there is not enough data.
Example
use nom8::character::recognize_float;
let parser = |s| {
recognize_float(s)
};
assert_eq!(parser("11e-1"), Ok(("", "11e-1")));
assert_eq!(parser("123E-02"), Ok(("", "123E-02")));
assert_eq!(parser("123K-01"), Ok(("K-01", "123")));
assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Char))));
use nom8::character::recognize_float;
let parser = |s| {
recognize_float(s)
};
assert_eq!(parser(Streaming("11e-1;")), Ok((Streaming(";"), "11e-1")));
assert_eq!(parser(Streaming("123E-02;")), Ok((Streaming(";"), "123E-02")));
assert_eq!(parser(Streaming("123K-01")), Ok((Streaming("K-01"), "123")));
assert_eq!(parser(Streaming("abc")), Err(Err::Error((Streaming("abc"), ErrorKind::Char))));