| 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 | |
| 2316 | impl AnyStrContainer<Wtf8> for Wtf8Buf { |