| 107 | /* findall: list of matches, group shaped like CPython for zero or one group. */ |
| 108 | #[plugin_fn] |
| 109 | fn findall(pattern: String, string: String) -> Result<Handle> { |
| 110 | let (founds, ngroups) = rx(main::find_all(&pattern, &string))?; |
| 111 | if ngroups <= 1 { |
| 112 | let items: Vec<String> = founds.iter().map(|f| pick(f, ngroups)).collect(); |
| 113 | return str_list(&items); |
| 114 | } |
| 115 | let list = Handle::new_list()?; |
| 116 | for f in &founds { |
| 117 | let groups: Vec<String> = f.groups.iter().map(|g| g.clone().unwrap_or_default()).collect(); |
| 118 | let sub = str_list(&groups)?; |
| 119 | list.call("append", &[sub.raw()])?; |
| 120 | } |
| 121 | Ok(list) |
| 122 | } |
| 123 | |
| 124 | /* groups: capture groups of the first match, or None. */ |
| 125 | #[plugin_fn] |