MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / scan_anchored

Function scan_anchored

codegraph-kernel/src/cfnptr.rs:559–583  ·  view source on GitHub ↗

Anchor-skeleton driver shared by INIT_RE and ARRAY_TABLE_RE: both match `(?:^|[;{}])` then a body, and resume from the end of each match. `body` returns (token, match_end) when the body matches at the position after the anchor.

(s: &[u8], mut body: F, out: &mut Vec<String>)

Source from the content-addressed store, hash-verified

557/// `(?:^|[;{}])` then a body, and resume from the end of each match. `body`
558/// returns (token, match_end) when the body matches at the position after the
559/// anchor.
560fn scan_anchored<F>(s: &[u8], mut body: F, out: &mut Vec<String>)
561where
562 F: FnMut(&[u8], usize) -> Option<(String, usize)>,
563{
564 let mut last = 0usize;
565 // The `^` branch consumes nothing and only exists at position 0.
566 if last == 0 {
567 if let Some((tok, end)) = body(s, 0) {
568 out.push(tok);
569 last = end;
570 }
571 }
572 let mut p = last;
573 while p < s.len() {
574 let ch = s[p];
575 if ch == b';' || ch == b'{' || ch == b'}' {
576 if let Some((tok, end)) = body(s, p + 1) {
577 out.push(tok);
578 p = end;
579 continue;
580 }
581 }
582 p += 1;
583 }
584}
585
586/// INIT_RE body after the anchor:

Callers 1

scan_fileFunction · 0.85

Calls 3

pushMethod · 0.80
lenMethod · 0.80
bodyFunction · 0.50

Tested by

no test coverage detected