| 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; |