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

Function closesParameterList

src/extraction/languages/c-cpp.ts:1011–1027  ·  view source on GitHub ↗

True when the `)` at `code[close]` closes a function declarator's parameter list.

(code: string, close: number)

Source from the content-addressed store, hash-verified

1009
1010/** True when the `)` at `code[close]` closes a function declarator's parameter list. */
1011function closesParameterList(code: string, close: number): boolean {
1012 let depth = 0;
1013 let open = -1;
1014 for (let i = close; i >= 0 && close - i < 4000; i--) {
1015 const c = code[i];
1016 if (c === ')') depth++;
1017 else if (c === '(') {
1018 if (--depth === 0) { open = i; break; }
1019 } else if (c === ';' || c === '{' || c === '}') return false;
1020 }
1021 if (open < 0) return false;
1022 const before = code.slice(Math.max(0, open - 200), open);
1023 // `operator()(…)`, `operator==(…)`, `operator bool(…)`
1024 if (/\boperator\s*(?:\(\s*\)|\[\s*\]|[^\s\w()[\]]{1,3}|\s+[A-Za-z_][\w\s:<>*&]*)\s*$/.test(before)) return true;
1025 const name = /([A-Za-z_]\w*)\s*$/.exec(before)?.[1];
1026 return !!name && !CPP_PAREN_KEYWORDS.has(name) && !/^[A-Z][A-Z0-9_]*$/.test(name);
1027}
1028
1029/**
1030 * Blank attribute macros that open a declaration, at the start of a line or

Callers 1

Calls 2

hasMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected