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

Function find

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

Single match in the requested mode. */

(pattern: &str, text: &str, mode: Mode)

Source from the content-addressed store, hash-verified

46
47/* Single match in the requested mode. */
48pub fn find(pattern: &str, text: &str, mode: Mode) -> Result<Option<Found>, ReError> {
49 let re = Regex::compile(pattern)?;
50 let chars: Vec<char> = text.chars().collect();
51 let m = Matcher::new(&chars, re.prog.flags);
52 let caps = match mode {
53 Mode::Search => m.search(&re.prog.root, re.prog.group_count),
54 Mode::Match => m.match_at(&re.prog.root, re.prog.group_count, false),
55 Mode::Full => m.match_at(&re.prog.root, re.prog.group_count, true),
56 };
57 match caps {
58 Some(c) => Ok(Some(build(&chars, &c, re.prog.group_count))),
59 None if m.exceeded() => Err(too_complex()),
60 None => Ok(None),
61 }
62}
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> {

Callers 5

searchFunction · 0.50
fullmatchFunction · 0.50
groupsFunction · 0.50
spanFunction · 0.50
r#matchFunction · 0.50

Calls 6

buildFunction · 0.85
too_complexFunction · 0.85
collectMethod · 0.80
searchMethod · 0.80
match_atMethod · 0.80
exceededMethod · 0.80

Tested by

no test coverage detected