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

Function join

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

Source from the content-addressed store, hash-verified

277}
278
279fn join<'gc>(
280 mc: &'gc Mutation<'gc>,
281 receiver: Value<'gc>,
282 args: Vec<Value<'gc>>,
283) -> Result<Value<'gc>, VmError> {
284 let receiver = receiver.as_string_value()?;
285 let separator = receiver.as_str();
286
287 if args.len() != 1 {
288 return Err(VmError::RuntimeError(
289 "join: expected exactly one array argument".into(),
290 ));
291 }
292
293 // Get the array from args[0]
294 let vec = match &args[0] {
295 Value::List(list) => &list.borrow().data,
296 _ => {
297 return Err(VmError::RuntimeError(
298 "join: argument must be an array".into(),
299 ));
300 }
301 };
302
303 let mut result = String::new();
304 for (i, value) in vec.iter().enumerate() {
305 if i > 0 {
306 result.push_str(separator);
307 }
308 match value {
309 Value::String(s) => result.push_str(s.to_str().unwrap()),
310 Value::IoString(s) => result.push_str(s),
311 _ => {
312 return Err(VmError::RuntimeError(format!(
313 "join: array element {} must be a string",
314 i
315 )));
316 }
317 }
318 }
319
320 Ok(Value::IoString(Gc::new(mc, result)))
321}
322
323// Regex operations
324fn regex_match<'gc>(

Callers

nothing calls this directly

Calls 6

RuntimeErrorClass · 0.85
as_string_valueMethod · 0.80
lenMethod · 0.80
to_strMethod · 0.80
as_strMethod · 0.45
borrowMethod · 0.45

Tested by

no test coverage detected