(
s: PyStrRef,
end: usize,
strict: OptionalArg<bool>,
vm: &VirtualMachine,
)
| 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 | } |
no test coverage detected