MCPcopy Index your code
hub / github.com/RustPython/RustPython / split

Method split

crates/vm/src/stdlib/_sre.rs:362–396  ·  view source on GitHub ↗
(
            zelf: PyRef<Self>,
            split_args: SplitArgs,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

360
361 #[pymethod]
362 fn split(
363 zelf: PyRef<Self>,
364 split_args: SplitArgs,
365 vm: &VirtualMachine,
366 ) -> PyResult<Vec<PyObjectRef>> {
367 with_sre_str!(zelf, &split_args.string, vm, |s| {
368 let req = s.create_request(&zelf, 0, usize::MAX);
369 let state = State::default();
370 let mut split_list: Vec<PyObjectRef> = Vec::new();
371 let mut iter = SearchIter { req, state };
372 let mut n = 0;
373 let mut last = 0;
374
375 while (split_args.maxsplit == 0 || n < split_args.maxsplit) && iter.next().is_some()
376 {
377 /* get segment before this match */
378 split_list.push(s.slice(last, iter.state.start, vm));
379
380 let m = Match::new(&mut iter.state, zelf.clone(), split_args.string.clone());
381
382 // add groups (if any)
383 for i in 1..=zelf.groups {
384 split_list.push(m.get_slice(i, s, vm).unwrap_or_else(|| vm.ctx.none()));
385 }
386
387 n += 1;
388 last = iter.state.cursor.position;
389 }
390
391 // get segment following last match (even if empty)
392 split_list.push(req.string.slice(last, s.count(), vm));
393
394 Ok(split_list)
395 })
396 }
397
398 #[pygetset]
399 const fn flags(&self) -> u16 {

Callers 3

get_single_attrMethod · 0.45
listdrivesFunction · 0.45
get_statementMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected