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

Function cppNamespaceBlocks

src/resolution/cpp-template-instantiations.ts:366–387  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

364 * name character: `[\w:\s]*?\s*\{` backtracks through one quadratically.)
365 */
366export function cppNamespaceBlocks(text: string): Array<{ start: number; end: number; path: readonly string[] }> {
367 const blocks: Array<{ start: number; end: number; path: readonly string[] }> = [];
368 const open: Array<{ start: number; end: number; path: readonly string[] } | null> = [];
369 let path: readonly string[] = [];
370 for (const m of text.matchAll(/\bnamespace\b(?:\s+([A-Za-z_][\w:]*(?:\s+[\w:]+)*))?\s*\{|[{}]/g)) {
371 if (m[0] === '{') open.push(null);
372 else if (m[0] === '}') {
373 const block = open.pop();
374 if (block) {
375 block.end = m.index!;
376 path = open.reduce<readonly string[]>((p, b) => b?.path ?? p, []);
377 }
378 } else {
379 const names = m[1]?.replace(/\s+/g, '') ?? '';
380 const block = { start: m.index!, end: text.length, path: names ? [...path, ...names.split('::')] : path };
381 blocks.push(block);
382 open.push(block);
383 path = block.path;
384 }
385 }
386 return blocks;
387}
388
389class TemplateInstantiations {
390 private readonly sources = new LRUCache<string, Source | null>(MAX_FILES_HELD);

Callers 3

namesFunction · 0.90
namespaceAtMethod · 0.85

Calls 1

pushMethod · 0.80

Tested by 1

namesFunction · 0.72