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

Function blankCCplusplusGuardBodies

src/extraction/languages/c-cpp.ts:887–911  ·  view source on GitHub ↗
(source: string)

Source from the content-addressed store, hash-verified

885const C_PREPROC_ENDIF_RE = /^[ \t]*#[ \t]*endif\b/;
886const C_CPLUSPLUS_GUARD_MAX_BODY_LINES = 40;
887export function blankCCplusplusGuardBodies(source: string): string {
888 if (source.indexOf('__cplusplus') === -1) return source;
889 const lines = source.split('\n');
890 const stripCr = (l: string): string => (l.endsWith('\r') ? l.slice(0, -1) : l);
891 let changed = false;
892 for (let i = 0; i < lines.length; i++) {
893 if (!C_CPLUSPLUS_GUARD_OPEN_RE.test(stripCr(lines[i] as string))) continue;
894 let end = -1;
895 for (let j = i + 1; j < lines.length && j - i - 1 <= C_CPLUSPLUS_GUARD_MAX_BODY_LINES; j++) {
896 const line = stripCr(lines[j] as string);
897 if (C_PREPROC_ENDIF_RE.test(line)) {
898 end = j;
899 break;
900 }
901 if (C_PREPROC_DIRECTIVE_RE.test(line)) break; // nested directive — bail
902 }
903 if (end < 0) continue;
904 for (let k = i + 1; k < end; k++) {
905 lines[k] = (lines[k] as string).replace(/[^\r]/g, ' ');
906 }
907 changed = true;
908 i = end;
909 }
910 return changed ? lines.join('\n') : source;
911}
912
913/**
914 * Blank a C iterator-macro call in STATEMENT position — `ql_foreach(iter,

Callers 2

preParseCSourceFunction · 0.85
extraction.test.tsFile · 0.85

Calls 2

stripCrFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected