MCPcopy Create free account
hub / github.com/dprint/jsonc-parser / read_four_hex_digits

Function read_four_hex_digits

src/string.rs:191–204  ·  view source on GitHub ↗
(
  chars: &mut T,
  buf: &mut [u8; 4],
)

Source from the content-addressed store, hash-verified

189}
190
191fn 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
206fn hex_buf_to_str(buf: &[u8; 4]) -> String {
207 std::str::from_utf8(buf).unwrap().to_string()

Callers 1

parse_hex_charFunction · 0.85

Calls 1

move_next_charMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…