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

Method py_rsplit_whitespace

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

Source from the content-addressed store, hash-verified

2287 }
2288
2289 fn py_rsplit_whitespace<F>(&self, maxsplit: isize, convert: F) -> Vec<PyObjectRef>
2290 where
2291 F: Fn(&Self) -> PyObjectRef,
2292 {
2293 // CPython rsplit_whitespace
2294 let mut splits = Vec::new();
2295 let mut last_offset = self.len();
2296 let mut count = maxsplit;
2297 for (offset, _) in self.rmatch_indices(|c: char| c.is_ascii_whitespace() || c == '\x0b') {
2298 if last_offset == offset + 1 {
2299 last_offset -= 1;
2300 continue;
2301 }
2302 if count == 0 {
2303 break;
2304 }
2305 splits.push(convert(&self[offset + 1..last_offset]));
2306 last_offset = offset;
2307 count -= 1;
2308 }
2309 if last_offset != 0 {
2310 splits.push(convert(&self[..last_offset]));
2311 }
2312 splits
2313 }
2314}
2315
2316impl AnyStrContainer<Wtf8> for Wtf8Buf {

Callers 1

rsplitMethod · 0.45

Calls 10

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

Tested by

no test coverage detected