Skip to main content

take_utf8_while1

Function take_utf8_while1 

Source
pub fn take_utf8_while1<F>(
    cond: F,
) -> impl Fn(&[u8]) -> IResult<&[u8], Cow<'_, str>>
where F: Fn(char) -> bool,
Expand description

Parses the input as a sequence of UTF-8 characters that satisfy the predicate cond. If invalid UTF-8 is encountered, it is replaced by char::REPLACEMENT_CHARACTER and parsing continues.

This function is zero-copy if the parsed input is valid UTF-8, otherwise a string gets allocated because of the need to insert replacement characters. This is similar to how String::from_utf8_lossy works.