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

Function scan

codegraph-kernel/src/ccpp/brace_scopes.rs:251–416  ·  view source on GitHub ↗

scanCppBraceScopes: `src` as the parser saw it (after preParse). None when the braces don't balance.

(src: &str)

Source from the content-addressed store, hash-verified

249/// scanCppBraceScopes: `src` as the parser saw it (after preParse). None when
250/// the braces don't balance.
251pub fn scan(src: &str) -> Option<BraceScopes> {
252 let s = src.as_bytes();
253 let n = s.len();
254 let mut closes: HashMap<usize, usize> = HashMap::new();
255 let mut open: Vec<usize> = Vec::new();
256 let mut branches: Vec<Branch> = Vec::new();
257 let mut namespace_at: Vec<(usize, String)> = Vec::new();
258 let mut pending_namespace: Option<(String, usize)> = None;
259 let mut balanced = true;
260 let mut line_start = true;
261 let mut word_start: usize = 0;
262 let mut word_end_at: Option<usize> = None;
263 // Past a byte-order mark, so line 1 can be a directive.
264 let mut i = if src.starts_with('\u{feff}') { 3 } else { 0 };
265 while i < n {
266 let c = s[i];
267 if c == b'\n' {
268 line_start = true;
269 i += 1;
270 continue;
271 }
272 if is_blank(c) {
273 i += 1;
274 continue;
275 }
276 if c == b'/' && at(s, i + 1) == b'/' {
277 i = line_comment_end(src, i + 2);
278 continue;
279 }
280 if c == b'/' && at(s, i + 1) == b'*' {
281 i = find(src, i + 2, "*/").map_or(n, |e| e + 2);
282 continue;
283 }
284 if c == b'#' && line_start {
285 let mut j = i + 1;
286 while j < n && is_blank(s[j]) {
287 j += 1;
288 }
289 let directive: &[u8] = match word_end(s, j) {
290 Some(e) => &s[j..e],
291 None => b"",
292 };
293 while j < n {
294 let d = s[j];
295 if d == b'\n' {
296 let mut k = j as isize - 1;
297 if k >= 0 && s[k as usize] == b'\r' {
298 k -= 1;
299 }
300 if k < 0 || s[k as usize] != b'\\' {
301 break;
302 }
303 j += 1;
304 } else if d == b'/' && at(s, j + 1) == b'/' {
305 j = line_comment_end(src, j + 2);
306 } else if d == b'/' && at(s, j + 1) == b'*' {
307 j = find(src, j + 2, "*/").map_or(n, |e| e + 2);
308 } else if d == b'"' {

Callers 1

extractFunction · 0.70

Calls 15

is_blankFunction · 0.85
line_comment_endFunction · 0.85
quoted_endFunction · 0.85
is_raw_prefixFunction · 0.85
is_raw_delimiterFunction · 0.85
is_word_charFunction · 0.85
is_word_startFunction · 0.85
namespace_headFunction · 0.85
lenMethod · 0.80
pushMethod · 0.80
atFunction · 0.70
findFunction · 0.70

Tested by

no test coverage detected