(
format: &FormatString,
arguments: &FuncArgs,
vm: &VirtualMachine,
)
| 178 | } |
| 179 | |
| 180 | pub(crate) fn format( |
| 181 | format: &FormatString, |
| 182 | arguments: &FuncArgs, |
| 183 | vm: &VirtualMachine, |
| 184 | ) -> PyResult<Wtf8Buf> { |
| 185 | let mut auto_argument_index: usize = 0; |
| 186 | let mut seen_index = false; |
| 187 | format_internal(vm, format, &mut |field_type| match field_type { |
| 188 | FieldType::Auto => { |
| 189 | if seen_index { |
| 190 | return Err(vm.new_value_error( |
| 191 | "cannot switch from manual field specification to automatic field numbering", |
| 192 | )); |
| 193 | } |
| 194 | auto_argument_index += 1; |
| 195 | arguments |
| 196 | .args |
| 197 | .get(auto_argument_index - 1) |
| 198 | .cloned() |
| 199 | .ok_or_else(|| vm.new_index_error("tuple index out of range")) |
| 200 | } |
| 201 | FieldType::Index(index) => { |
| 202 | if auto_argument_index != 0 { |
| 203 | return Err(vm.new_value_error( |
| 204 | "cannot switch from automatic field numbering to manual field specification", |
| 205 | )); |
| 206 | } |
| 207 | seen_index = true; |
| 208 | arguments |
| 209 | .args |
| 210 | .get(index) |
| 211 | .cloned() |
| 212 | .ok_or_else(|| vm.new_index_error("tuple index out of range")) |
| 213 | } |
| 214 | FieldType::Keyword(keyword) => keyword |
| 215 | .as_str() |
| 216 | .ok() |
| 217 | .and_then(|keyword| arguments.get_optional_kwarg(keyword)) |
| 218 | .ok_or_else(|| vm.new_key_error(vm.ctx.new_str(keyword).into())), |
| 219 | }) |
| 220 | } |
| 221 | |
| 222 | pub(crate) fn format_map( |
| 223 | format: &FormatString, |
no test coverage detected