(&self, args: anystr::SplitLinesArgs, vm: &VirtualMachine)
| 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( |
nothing calls this directly
no test coverage detected