parse_utf8_char() makes the assumption that at least four bytes or one UTF-8 glyph are still to read in the input.
This commit is contained in:
IGI-111 2017-03-24 21:50:09 +01:00 committed by ticki
parent 5e336e10a1
commit fa2e86a558
1 changed files with 11 additions and 6 deletions

View File

@ -315,7 +315,9 @@ fn parse_utf8_char<I>(c: u8, iter: &mut I) -> Result<char, Error>
bytes.push(c);
loop {
bytes.push(iter.next().unwrap().unwrap());
match iter.next() {
Some(Ok(next)) => {
bytes.push(next);
if let Ok(st) = str::from_utf8(bytes) {
return Ok(st.chars().next().unwrap());
}
@ -323,6 +325,9 @@ fn parse_utf8_char<I>(c: u8, iter: &mut I) -> Result<char, Error>
return error;
}
}
_ => return error,
}
}
}
}