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

Function blankCppSpans

src/extraction/languages/c-cpp.ts:776–794  ·  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

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

Calls 1

blankFunction · 0.70

Tested by

no test coverage detected