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

Function do_findall

crates/stdlib/src/re.rs:185–216  ·  view source on GitHub ↗
(vm: &VirtualMachine, pattern: &PyPattern, search_text: PyStrRef)

Source from the content-addressed store, hash-verified

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,

Callers 2

findallFunction · 0.85
findallMethod · 0.85

Calls 12

collectMethod · 0.80
into_ownedMethod · 0.80
new_listMethod · 0.80
mapMethod · 0.45
as_bytesMethod · 0.45
lenMethod · 0.45
unwrapMethod · 0.45
getMethod · 0.45
new_strMethod · 0.45
skipMethod · 0.45
iterMethod · 0.45
new_tupleMethod · 0.45

Tested by

no test coverage detected