TODO: remove this function from anystr. See https://github.com/RustPython/RustPython/pull/4709/files#r1141013993
(&self, options: SplitLinesArgs, into_wrapper: FW)
| 368 | // TODO: remove this function from anystr. |
| 369 | // See https://github.com/RustPython/RustPython/pull/4709/files#r1141013993 |
| 370 | fn py_bytes_splitlines<FW, W>(&self, options: SplitLinesArgs, into_wrapper: FW) -> Vec<W> |
| 371 | where |
| 372 | FW: Fn(&Self) -> W, |
| 373 | { |
| 374 | let keep = options.keepends as usize; |
| 375 | let mut elements = Vec::new(); |
| 376 | let mut last_i = 0; |
| 377 | let mut enumerated = self.as_bytes().iter().enumerate().peekable(); |
| 378 | while let Some((i, ch)) = enumerated.next() { |
| 379 | let (end_len, i_diff) = match *ch { |
| 380 | b'\n' => (keep, 1), |
| 381 | b'\r' => { |
| 382 | let is_rn = enumerated.next_if(|(_, ch)| **ch == b'\n').is_some(); |
| 383 | if is_rn { (keep + keep, 2) } else { (keep, 1) } |
| 384 | } |
| 385 | _ => continue, |
| 386 | }; |
| 387 | let range = last_i..i + end_len; |
| 388 | last_i = i + i_diff; |
| 389 | elements.push(into_wrapper(self.get_bytes(range))); |
| 390 | } |
| 391 | if last_i != self.bytes_len() { |
| 392 | elements.push(into_wrapper(self.get_bytes(last_i..self.bytes_len()))); |
| 393 | } |
| 394 | elements |
| 395 | } |
| 396 | |
| 397 | fn py_zfill(&self, width: isize) -> Vec<u8> { |
| 398 | let width = width.to_usize().unwrap_or(0); |