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

Method splitlines

crates/vm/src/builtins/str.rs:1123–1152  ·  view source on GitHub ↗
(&self, args: anystr::SplitLinesArgs, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1121
1122 #[pymethod]
1123 fn splitlines(&self, args: anystr::SplitLinesArgs, vm: &VirtualMachine) -> Vec<PyObjectRef> {
1124 let into_wrapper = |s: &Wtf8| self.new_substr(s.to_owned()).to_pyobject(vm);
1125 let mut elements = Vec::new();
1126 let mut last_i = 0;
1127 let self_str = self.as_wtf8();
1128 let mut enumerated = self_str.code_point_indices().peekable();
1129 while let Some((i, ch)) = enumerated.next() {
1130 let end_len = match ch.to_char_lossy() {
1131 '\n' => 1,
1132 '\r' => {
1133 let is_rn = enumerated.next_if(|(_, ch)| *ch == '\n').is_some();
1134 if is_rn { 2 } else { 1 }
1135 }
1136 '\x0b' | '\x0c' | '\x1c' | '\x1d' | '\x1e' | '\u{0085}' | '\u{2028}'
1137 | '\u{2029}' => ch.len_wtf8(),
1138 _ => continue,
1139 };
1140 let range = if args.keepends {
1141 last_i..i + end_len
1142 } else {
1143 last_i..i
1144 };
1145 last_i = i + end_len;
1146 elements.push(into_wrapper(&self_str[range]));
1147 }
1148 if last_i != self_str.len() {
1149 elements.push(into_wrapper(&self_str[last_i..]));
1150 }
1151 elements
1152 }
1153
1154 #[pymethod]
1155 fn join(

Callers

nothing calls this directly

Calls 11

newFunction · 0.85
new_substrMethod · 0.80
code_point_indicesMethod · 0.80
len_wtf8Method · 0.80
to_pyobjectMethod · 0.45
to_ownedMethod · 0.45
as_wtf8Method · 0.45
nextMethod · 0.45
to_char_lossyMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected