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

Function scan_anchored

codegraph-kernel/src/cfnptr.rs:549–573  ·  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

547/// `(?:^|[;{}])` then a body, and resume from the end of each match. `body`
548/// returns (token, match_end) when the body matches at the position after the
549/// anchor.
550fn scan_anchored<F>(s: &[u8], mut body: F, out: &mut Vec<String>)
551where
552 F: FnMut(&[u8], usize) -> Option<(String, usize)>,
553{
554 let mut last = 0usize;
555 // The `^` branch consumes nothing and only exists at position 0.
556 if last == 0 {
557 if let Some((tok, end)) = body(s, 0) {
558 out.push(tok);
559 last = end;
560 }
561 }
562 let mut p = last;
563 while p < s.len() {
564 let ch = s[p];
565 if ch == b';' || ch == b'{' || ch == b'}' {
566 if let Some((tok, end)) = body(s, p + 1) {
567 out.push(tok);
568 p = end;
569 continue;
570 }
571 }
572 p += 1;
573 }
574}
575
576/// 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