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

Function matching

src/extraction/languages/cpp-macro-methods.ts:185–194  ·  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

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