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

Function argumentsBetween

src/resolution/cpp-template-instantiations.ts:238–262  ·  view source on GitHub ↗

The arguments between the `<` at `open` and the `>` at `close`, split at the top level, each with where it starts.

(text: string, open: number, close: number)

Source from the content-addressed store, hash-verified

236
237/** The arguments between the `<` at `open` and the `>` at `close`, split at the top level, each with where it starts. */
238function argumentsBetween(text: string, open: number, close: number): Array<{ text: string; offset: number }> {
239 const out: Array<{ text: string; offset: number }> = [];
240 let depth = 0;
241 let parens = 0;
242 let start = open + 1;
243 const push = (end: number): void => {
244 const raw = text.slice(start, end);
245 const trimmed = raw.trim();
246 if (trimmed) out.push({ text: trimmed, offset: start + raw.indexOf(trimmed) });
247 };
248 for (let i = open + 1; i < close; i++) {
249 const c = text[i]!;
250 if (c === '(' || c === '[') parens++;
251 else if (c === ')' || c === ']') parens--;
252 else if (parens > 0) continue;
253 else if (c === '<') depth++;
254 else if (c === '>' && text[i - 1] !== '-') depth--;
255 else if (c === ',' && depth === 0) {
256 push(i);
257 start = i + 1;
258 }
259 }
260 push(close);
261 return out;
262}
263
264/** The `>` closing the argument list opened at `open`, or -1 when `<` opens none there. */
265function closingAngle(text: string, open: number): number {

Callers 4

qualifiersBeforeFunction · 0.85
templateOfClassMethod · 0.85
writtenAsMethod · 0.85
typeListMethod · 0.85

Calls 1

pushFunction · 0.70

Tested by

no test coverage detected