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,12 +315,17 @@ fn parse_utf8_char<I>(c: u8, iter: &mut I) -> Result<char, Error>
bytes.push(c); bytes.push(c);
loop { loop {
bytes.push(iter.next().unwrap().unwrap()); match iter.next() {
if let Ok(st) = str::from_utf8(bytes) { Some(Ok(next)) => {
return Ok(st.chars().next().unwrap()); bytes.push(next);
} if let Ok(st) = str::from_utf8(bytes) {
if bytes.len() >= 4 { return Ok(st.chars().next().unwrap());
return error; }
if bytes.len() >= 4 {
return error;
}
}
_ => return error,
} }
} }
} }