Function split_at_first_char_lossy

Source
pub fn split_at_first_char_lossy(buf: &[u8]) -> (&str, &[u8])
Expand description

Split buffer after the first valid utf8 character.

If buf doesn’t start with a valid utf8 character, returns the unicode replacement character and the buffer after skipping invalid bytes.

Panics if buf is empty.

assert_eq!(split_at_first_char_lossy(
  &['1' as u8, '2' as u8, '3' as u8][..]),
  ("1", &['2' as u8, '3' as u8][..]));
assert_eq!(split_at_first_char_lossy(
  &[0x80, 0x80, '2' as u8, '3' as u8][..]),
  ("�", &['2' as u8, '3' as u8][..]));