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

Method py_bytes_splitlines

crates/vm/src/anystr.rs:370–395  ·  view source on GitHub ↗

TODO: remove this function from anystr. See https://github.com/RustPython/RustPython/pull/4709/files#r1141013993

(&self, options: SplitLinesArgs, into_wrapper: FW)

Source from the content-addressed store, hash-verified

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

Callers 1

splitlinesMethod · 0.80

Implementers 2

bytes_inner.rscrates/vm/src/bytes_inner.rs
str.rscrates/vm/src/builtins/str.rs

Calls 7

newFunction · 0.85
iterMethod · 0.45
as_bytesMethod · 0.45
nextMethod · 0.45
pushMethod · 0.45
get_bytesMethod · 0.45
bytes_lenMethod · 0.45

Tested by

no test coverage detected