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

Function scanstring

crates/stdlib/src/json.rs:697–727  ·  view source on GitHub ↗
(
        s: PyStrRef,
        end: usize,
        strict: OptionalArg<bool>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

695
696 #[pyfunction]
697 fn scanstring(
698 s: PyStrRef,
699 end: usize,
700 strict: OptionalArg<bool>,
701 vm: &VirtualMachine,
702 ) -> PyResult<(Wtf8Buf, usize)> {
703 flame_guard!("_json::scanstring");
704 let wtf8 = s.as_wtf8();
705
706 // Convert char index `end` to byte index
707 let byte_idx = if end == 0 {
708 0
709 } else {
710 wtf8.code_point_indices()
711 .nth(end)
712 .map(|(i, _)| i)
713 .ok_or_else(|| {
714 py_decode_error(
715 machinery::DecodeError::new("Unterminated string starting at", end - 1),
716 s.clone(),
717 vm,
718 )
719 })?
720 };
721
722 let (result, chars_consumed, _bytes_consumed) =
723 machinery::scanstring(&wtf8[byte_idx..], end, strict.unwrap_or(true))
724 .map_err(|e| py_decode_error(e, s, vm))?;
725
726 Ok((result, end + chars_consumed))
727 }
728}

Callers 3

parseMethod · 0.70
parse_objectMethod · 0.70
call_scan_onceMethod · 0.70

Calls 7

py_decode_errorFunction · 0.85
newFunction · 0.85
ok_or_elseMethod · 0.80
code_point_indicesMethod · 0.80
as_wtf8Method · 0.45
mapMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected