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

Method py_split_whitespace

crates/vm/src/builtins/str.rs:2263–2287  ·  view source on GitHub ↗
(&self, maxsplit: isize, convert: F)

Source from the content-addressed store, hash-verified

2261 }
2262
2263 fn py_split_whitespace<F>(&self, maxsplit: isize, convert: F) -> Vec<PyObjectRef>
2264 where
2265 F: Fn(&Self) -> PyObjectRef,
2266 {
2267 // CPython split_whitespace
2268 let mut splits = Vec::new();
2269 let mut last_offset = 0;
2270 let mut count = maxsplit;
2271 for (offset, _) in self.match_indices(|c: char| c.is_ascii_whitespace() || c == '\x0b') {
2272 if last_offset == offset {
2273 last_offset += 1;
2274 continue;
2275 }
2276 if count == 0 {
2277 break;
2278 }
2279 splits.push(convert(&self[last_offset..offset]));
2280 last_offset = offset + 1;
2281 count -= 1;
2282 }
2283 if last_offset != self.len() {
2284 splits.push(convert(&self[last_offset..]));
2285 }
2286 splits
2287 }
2288
2289 fn py_rsplit_whitespace<F>(&self, maxsplit: isize, convert: F) -> Vec<PyObjectRef>
2290 where

Callers 1

splitMethod · 0.45

Calls 9

newFunction · 0.85
code_point_indicesMethod · 0.80
is_char_andMethod · 0.80
convertFunction · 0.50
pushMethod · 0.45
lenMethod · 0.45
filterMethod · 0.45
as_bytesMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected