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

Method py_split

crates/vm/src/anystr.rs:161–192  ·  view source on GitHub ↗
(
        &self,
        args: SplitArgs<T>,
        vm: &VirtualMachine,
        full_obj: impl FnOnce() -> PyObjectRef,
        split: SP,
        splitn: SN,
        split_whitespace: SW,
    )

Source from the content-addressed store, hash-verified

159 }
160
161 fn py_split<T, SP, SN, SW>(
162 &self,
163 args: SplitArgs<T>,
164 vm: &VirtualMachine,
165 full_obj: impl FnOnce() -> PyObjectRef,
166 split: SP,
167 splitn: SN,
168 split_whitespace: SW,
169 ) -> PyResult<Vec<PyObjectRef>>
170 where
171 T: TryFromObject + AnyStrWrapper<Self>,
172 SP: Fn(&Self, &Self, &VirtualMachine) -> Vec<PyObjectRef>,
173 SN: Fn(&Self, &Self, usize, &VirtualMachine) -> Vec<PyObjectRef>,
174 SW: Fn(&Self, isize, &VirtualMachine) -> Vec<PyObjectRef>,
175 {
176 if args.sep.as_ref().is_some_and(|sep| sep.is_empty()) {
177 return Err(vm.new_value_error("empty separator"));
178 }
179 let splits = if let Some(pattern) = args.sep {
180 let Some(pattern) = pattern.as_ref() else {
181 return Ok(vec![full_obj()]);
182 };
183 if args.maxsplit < 0 {
184 split(self, pattern, vm)
185 } else {
186 splitn(self, pattern, (args.maxsplit + 1) as usize, vm)
187 }
188 } else {
189 split_whitespace(self, args.maxsplit, vm)
190 };
191 Ok(splits)
192 }
193 fn py_split_whitespace<F>(&self, maxsplit: isize, convert: F) -> Vec<PyObjectRef>
194 where
195 F: Fn(&Self) -> PyObjectRef;

Callers 4

splitMethod · 0.80
rsplitMethod · 0.80
splitMethod · 0.80
rsplitMethod · 0.80

Implementers 2

bytes_inner.rscrates/vm/src/bytes_inner.rs
str.rscrates/vm/src/builtins/str.rs

Calls 4

ErrClass · 0.50
splitFunction · 0.50
as_refMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected