MCPcopy Create free account
hub / github.com/aiscriptdev/aiscript / last_index_of

Function last_index_of

aiscript-vm/src/builtins/string.rs:184–199  ·  view source on GitHub ↗
(
    _mc: &'gc Mutation<'gc>,
    receiver: Value<'gc>,
    args: Vec<Value<'gc>>,
)

Source from the content-addressed store, hash-verified

182}
183
184fn last_index_of<'gc>(
185 _mc: &'gc Mutation<'gc>,
186 receiver: Value<'gc>,
187 args: Vec<Value<'gc>>,
188) -> Result<Value<'gc>, VmError> {
189 let substr = string_arg!(&args, 0, "last_index_of")?;
190
191 let s = receiver.as_string_value()?;
192 let s = s.as_str();
193 let substr = substr.to_str().unwrap();
194
195 match s.rfind(substr) {
196 Some(pos) => Ok(Value::Number(pos as f64)),
197 None => Ok(Value::Number(-1.0)),
198 }
199}
200
201// Substring and slicing
202fn substring<'gc>(

Callers

nothing calls this directly

Calls 3

as_string_valueMethod · 0.80
to_strMethod · 0.80
as_strMethod · 0.45

Tested by

no test coverage detected