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

Function split_top_level

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

splitTopLevel(body, sep): split on `sep` at brace/paren/bracket depth 0.

(body: &[u8], sep: u8)

Source from the content-addressed store, hash-verified

995// ---------- struct field parsing ----------
996
997/// splitTopLevel(body, sep): split on `sep` at brace/paren/bracket depth 0.
998fn split_top_level(body: &[u8], sep: u8) -> Vec<Range> {
999 let mut out = Vec::new();
1000 let mut depth = 0i64;
1001 let mut start = 0usize;
1002 for (i, &c) in body.iter().enumerate() {
1003 match c {
1004 b'{' | b'(' | b'[' => depth += 1,
1005 b'}' | b')' | b']' => depth -= 1,
1006 _ if c == sep && depth == 0 => {
1007 out.push((start, i));
1008 start = i + 1;
1009 }
1010 _ => {}
1011 }
1012 }
1013 out.push((start, body.len()));
1014 out
1015}
1016
1017/// JS String.prototype.trim over bytes (the JS set == our jsws set).

Callers 1

parse_struct_fields_rawFunction · 0.85

Calls 2

pushMethod · 0.80
lenMethod · 0.80

Tested by

no test coverage detected