MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / split

Function split

aiscript-vm/src/builtins/string.rs:261–277  ·  view source on GitHub ↗

Split and join

(
    mc: &'gc Mutation<'gc>,
    receiver: Value<'gc>,
    args: Vec<Value<'gc>>,
)

Source from the content-addressed store, hash-verified

259
260// Split and join
261fn split<'gc>(
262 mc: &'gc Mutation<'gc>,
263 receiver: Value<'gc>,
264 args: Vec<Value<'gc>>,
265) -> Result<Value<'gc>, VmError> {
266 let delimiter = string_arg!(&args, 0, "split")?.to_str().unwrap();
267
268 let s = receiver.as_string_value()?;
269 let parts = s
270 .as_str()
271 .split(delimiter)
272 .map(|part| Value::IoString(Gc::new(mc, part.to_string())))
273 .collect();
274
275 // Convert to array
276 Ok(Value::array(mc, parts))
277}
278
279fn join<'gc>(
280 mc: &'gc Mutation<'gc>,

Callers

nothing calls this directly

Calls 3

to_strMethod · 0.80
as_string_valueMethod · 0.80
as_strMethod · 0.45

Tested by

no test coverage detected