MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / find_all

Function find_all

std/re/src/main/mod.rs:65–85  ·  view source on GitHub ↗

All non overlapping matches, plus the group count for output shaping. */

(pattern: &str, text: &str)

Source from the content-addressed store, hash-verified

63
64/* All non overlapping matches, plus the group count for output shaping. */
65pub fn find_all(pattern: &str, text: &str) -> Result<(Vec<Found>, usize), ReError> {
66 let re = Regex::compile(pattern)?;
67 let chars: Vec<char> = text.chars().collect();
68 let m = Matcher::new(&chars, re.prog.flags);
69 let mut out = Vec::new();
70 let mut start = 0;
71 while start <= chars.len() {
72 match m.search_from(&re.prog.root, re.prog.group_count, start) {
73 Some(c) => {
74 let (s, e) = c[0].unwrap();
75 out.push(build(&chars, &c, re.prog.group_count));
76 start = if e > s { e } else { e + 1 }; // step past an empty match
77 }
78 None => {
79 if m.exceeded() { return Err(too_complex()); }
80 break;
81 }
82 }
83 }
84 Ok((out, re.prog.group_count))
85}
86
87/* Replace every match, expanding backreferences in the template. */
88pub fn sub(pattern: &str, repl: &str, text: &str) -> Result<String, ReError> {

Callers 1

findallFunction · 0.85

Calls 7

buildFunction · 0.85
too_complexFunction · 0.85
collectMethod · 0.80
search_fromMethod · 0.80
pushMethod · 0.80
exceededMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected