Format function that implements Python-like string formatting
(
state: &mut State<'gc>,
args: Vec<Value<'gc>>,
)
| 4 | |
| 5 | /// Format function that implements Python-like string formatting |
| 6 | pub(super) fn format<'gc>( |
| 7 | state: &mut State<'gc>, |
| 8 | args: Vec<Value<'gc>>, |
| 9 | ) -> Result<Value<'gc>, VmError> { |
| 10 | if args.is_empty() { |
| 11 | return Err(VmError::RuntimeError( |
| 12 | "format() missing required argument.".into(), |
| 13 | )); |
| 14 | } |
| 15 | |
| 16 | let template = args[0].as_string()?.to_str().unwrap(); |
| 17 | let format_args = &args[1..]; |
| 18 | |
| 19 | let result = format_string(template, format_args)?; |
| 20 | Ok(Value::IoString(Gc::new(state, result))) |
| 21 | } |
| 22 | |
| 23 | #[derive(Debug, Default)] |
| 24 | struct FormatSpec { |
nothing calls this directly
no test coverage detected