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

Function blankCppSpans

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

* Replace each [start, end) span of `source` with spaces, keeping line * endings. Given the mask the spans were found on, blank it the same way and * keep it for the next pass: a span holds whole macros (with their arguments), * so the result is what masking the new source would give.

(source: string, spans: ReadonlyArray<readonly [number, number]>, code?: string)

Source from the content-addressed store, hash-verified

773 * so the result is what masking the new source would give.
774 */
775function blankCppSpans(source: string, spans: ReadonlyArray<readonly [number, number]>, code?: string): string {
776 if (spans.length === 0) return source;
777 const ordered = [...spans].sort((a, b) => a[0] - b[0]);
778 const blank = (text: string): string => {
779 let out = '';
780 let at = 0;
781 for (const [start, end] of ordered) {
782 const from = Math.max(start, at);
783 if (from >= end) continue;
784 const span = text.slice(from, end);
785 out += text.slice(at, from) + (span.includes('\n') || span.includes('\r') ? span.replace(/[^\r\n]/g, ' ') : ' '.repeat(span.length));
786 at = end;
787 }
788 return out + text.slice(at);
789 };
790 const out = blank(source);
791 if (code !== undefined) cppMaskMemo = { source: out, code: blank(code) };
792 return out;
793}
794
795function skipCppSpace(code: string, i: number): number {
796 while (i < code.length && /\s/.test(code[i] as string)) i++;

Calls 1

blankFunction · 0.70

Tested by

no test coverage detected