MCPcopy Index your code
hub / github.com/RustPython/RustPython / decode_unicode

Function decode_unicode

crates/stdlib/src/json/machinery.rs:258–271  ·  view source on GitHub ↗
(it: &mut I, pos: usize)

Source from the content-addressed store, hash-verified

256
257#[inline]
258fn decode_unicode<I>(it: &mut I, pos: usize) -> Result<CodePoint, DecodeError>
259where
260 I: Iterator<Item = (usize, (usize, CodePoint))>,
261{
262 flame_guard!("machinery::decode_unicode");
263 let err = || DecodeError::new("Invalid \\uXXXX escape", pos);
264 let mut uni = 0u16;
265 for _ in 0..4 {
266 let (_, (_, c)) = it.next().ok_or_else(err)?;
267 let d = c.to_char().and_then(|c| c.to_digit(16)).ok_or_else(err)? as u16;
268 uni = (uni << 4) | d;
269 }
270 Ok(uni.into())
271}

Callers 1

scanstringFunction · 0.85

Calls 4

newFunction · 0.85
ok_or_elseMethod · 0.80
nextMethod · 0.45
to_charMethod · 0.45

Tested by

no test coverage detected