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

Function formatter_parser

crates/vm/src/stdlib/_string.rs:38–72  ·  view source on GitHub ↗
(text: PyStrRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

36
37 #[pyfunction]
38 fn formatter_parser(text: PyStrRef, vm: &VirtualMachine) -> PyResult<PyList> {
39 let format_string =
40 FormatString::from_str(text.as_wtf8()).map_err(|e| e.to_pyexception(vm))?;
41
42 let mut result: Vec<PyObjectRef> = Vec::new();
43 let mut literal = Wtf8Buf::new();
44 for part in format_string.format_parts {
45 match part {
46 FormatPart::Field {
47 field_name,
48 conversion_spec,
49 format_spec,
50 } => {
51 result.push(create_format_part(
52 mem::take(&mut literal),
53 Some(field_name),
54 Some(format_spec),
55 conversion_spec,
56 vm,
57 ));
58 }
59 FormatPart::Literal(text) => literal.push_wtf8(&text),
60 }
61 }
62 if !literal.is_empty() {
63 result.push(create_format_part(
64 mem::take(&mut literal),
65 None,
66 None,
67 None,
68 vm,
69 ));
70 }
71 Ok(result.into())
72 }
73
74 #[pyfunction]
75 fn formatter_field_name_split(

Callers

nothing calls this directly

Calls 9

newFunction · 0.85
create_format_partFunction · 0.85
takeFunction · 0.85
push_wtf8Method · 0.80
SomeClass · 0.50
as_wtf8Method · 0.45
to_pyexceptionMethod · 0.45
pushMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected