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

Method expandtabs

crates/vm/src/bytes_inner.rs:711–741  ·  view source on GitHub ↗
(&self, options: anystr::ExpandTabsArgs)

Source from the content-addressed store, hash-verified

709 }
710
711 pub fn expandtabs(&self, options: anystr::ExpandTabsArgs) -> Vec<u8> {
712 let tabsize = options.tabsize();
713 let mut counter: usize = 0;
714 let mut res = vec![];
715
716 if tabsize == 0 {
717 return self
718 .elements
719 .iter()
720 .copied()
721 .filter(|x| *x != b'\t')
722 .collect();
723 }
724
725 for i in &self.elements {
726 if *i == b'\t' {
727 let len = tabsize - counter % tabsize;
728 res.extend_from_slice(&vec![b' '; len]);
729 counter += len;
730 } else {
731 res.push(*i);
732 if *i == b'\r' || *i == b'\n' {
733 counter = 0;
734 } else {
735 counter += 1;
736 }
737 }
738 }
739
740 res
741 }
742
743 pub fn splitlines<FW, W>(&self, options: anystr::SplitLinesArgs, into_wrapper: FW) -> Vec<W>
744 where

Callers 3

builtin_str.pyFile · 0.45
builtin_bytes.pyFile · 0.45

Calls 5

tabsizeMethod · 0.80
collectMethod · 0.80
filterMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected