( chars: &mut T, buf: &mut [u8; 4], )
| 189 | } |
| 190 | |
| 191 | fn read_four_hex_digits<'a, T: CharProvider<'a>>( |
| 192 | chars: &mut T, |
| 193 | buf: &mut [u8; 4], |
| 194 | ) -> Result<u32, ParseStringErrorKind> { |
| 195 | for slot in buf.iter_mut() { |
| 196 | match chars.move_next_char() { |
| 197 | Some(c) if c.is_ascii_hexdigit() => *slot = c as u8, |
| 198 | _ => return Err(ParseStringErrorKind::ExpectedFourHexDigits), |
| 199 | } |
| 200 | } |
| 201 | // safety: buf contains only ASCII hex digits |
| 202 | let hex_str = std::str::from_utf8(buf).unwrap(); |
| 203 | u32::from_str_radix(hex_str, 16).map_err(|_| ParseStringErrorKind::InvalidUnicodeEscapeSequence(hex_str.to_string())) |
| 204 | } |
| 205 | |
| 206 | fn hex_buf_to_str(buf: &[u8; 4]) -> String { |
| 207 | std::str::from_utf8(buf).unwrap().to_string() |
no test coverage detected
searching dependent graphs…