| 183 | } |
| 184 | |
| 185 | fn do_findall(vm: &VirtualMachine, pattern: &PyPattern, search_text: PyStrRef) -> PyResult { |
| 186 | let out = pattern |
| 187 | .regex |
| 188 | .captures_iter(search_text.as_bytes()) |
| 189 | .map(|captures| match captures.len() { |
| 190 | 1 => { |
| 191 | let full = captures.get(0).unwrap().as_bytes(); |
| 192 | let full = String::from_utf8_lossy(full).into_owned(); |
| 193 | vm.ctx.new_str(full).into() |
| 194 | } |
| 195 | 2 => { |
| 196 | let capture = captures.get(1).unwrap().as_bytes(); |
| 197 | let capture = String::from_utf8_lossy(capture).into_owned(); |
| 198 | vm.ctx.new_str(capture).into() |
| 199 | } |
| 200 | _ => { |
| 201 | let out = captures |
| 202 | .iter() |
| 203 | .skip(1) |
| 204 | .map(|m| { |
| 205 | let s = m |
| 206 | .map(|m| String::from_utf8_lossy(m.as_bytes()).into_owned()) |
| 207 | .unwrap_or_default(); |
| 208 | vm.ctx.new_str(s).into() |
| 209 | }) |
| 210 | .collect(); |
| 211 | vm.ctx.new_tuple(out).into() |
| 212 | } |
| 213 | }) |
| 214 | .collect(); |
| 215 | Ok(vm.ctx.new_list(out).into()) |
| 216 | } |
| 217 | |
| 218 | fn do_split( |
| 219 | vm: &VirtualMachine, |