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

Function alias_line

codegraph-kernel/src/cfnptr.rs:723–780  ·  view source on GitHub ↗
(line: &[u8])

Source from the content-addressed store, hash-verified

721 i
722}
723
724fn alias_line(line: &[u8]) -> Option<&[u8]> {
725 let mut i = skip_sp_tab(line, 0);
726 if line.get(i) != Some(&b'#') {
727 return None;
728 }
729 i = skip_sp_tab(line, i + 1);
730 if line.len() < i + 6 || &line[i..i + 6] != b"define" {
731 return None;
732 }
733 i += 6;
734 let w = skip_sp_tab(line, i);
735 if w == i || !is_word_at(line, w) {
736 return None;
737 }
738 let name_end = word_end(line, w);
739 let name = &line[w..name_end];
740 let v0 = skip_sp_tab(line, name_end);
741 if v0 == name_end {
742 return None; // [ \t]+ before the value
743 }
744 // (?:(?:struct|union)[ \t]+)* greedy, k-descending on value failure.
745 let mut stack = vec![v0];
746 loop {
747 let cur = *stack.last().unwrap();
748 let keyword_len = if line.len() >= cur + 6 && &line[cur..cur + 6] == b"struct" {
749 Some(6)
750 } else if line.len() >= cur + 5 && &line[cur..cur + 5] == b"union" {
751 Some(5)
752 } else {
753 None
754 };
755 if let Some(keyword_len) = keyword_len {
756 let e = cur + keyword_len;
757 let w2 = skip_sp_tab(line, e);
758 if w2 > e {
759 stack.push(w2);
760 continue;
761 }
762 }
763 break;
764 }
765 for &vp in stack.iter().rev() {
766 let Some(&b0) = line.get(vp) else { continue };
767 if !(b0.is_ascii_alphabetic() || b0 == b'_') {
768 continue; // value must start [A-Za-z_]
769 }
770 let ve = word_end(line, vp);
771 // [ \t\r]*$
772 let mut t = ve;
773 while t < line.len() && (line[t] == b' ' || line[t] == b'\t' || line[t] == b'\r') {
774 t += 1;
775 }
776 if t == line.len() {
777 return Some(name);
778 }
779 }
780 None

Callers 1

scan_alias_namesFunction · 0.85

Calls 6

skip_sp_tabFunction · 0.85
is_word_atFunction · 0.85
word_endFunction · 0.85
lenMethod · 0.80
getMethod · 0.65
unwrapMethod · 0.60

Tested by

no test coverage detected