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

Function matching

src/extraction/languages/cpp-macro-methods.ts:186–195  ·  view source on GitHub ↗

Where the `close` matching the `open` at `text[from]` is, or -1.

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

Source from the content-addressed store, hash-verified

184
185/** Where the `close` matching the `open` at `text[from]` is, or -1. */
186function matching(text: string, from: number, open: string, close: string): number {
187 let depth = 0;
188 for (let i = from; i < text.length; i++) {
189 const c = text[i]!;
190 if (c === '"' || c === "'") i = quotedEnd(text, i) - 1;
191 else if (c === open) depth++;
192 else if (c === close && --depth === 0) return i;
193 }
194 return -1;
195}
196
197/** Past the string or character literal whose quote is at `i`. */
198function quotedEnd(text: string, i: number): number {

Callers 4

cppTypeTextFunction · 0.70
qualifiedCallableAtFunction · 0.70
bodyOpenAfterFunction · 0.70
cppDefinitionHeadsFunction · 0.70

Calls 1

quotedEndFunction · 0.70

Tested by

no test coverage detected