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

Function blankCCplusplusGuardBodies

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

Source from the content-addressed store, hash-verified

875const C_PREPROC_ENDIF_RE = /^[ \t]*#[ \t]*endif\b/;
876const C_CPLUSPLUS_GUARD_MAX_BODY_LINES = 40;
877export function blankCCplusplusGuardBodies(source: string): string {
878 if (source.indexOf('__cplusplus') === -1) return source;
879 const lines = source.split('\n');
880 const stripCr = (l: string): string => (l.endsWith('\r') ? l.slice(0, -1) : l);
881 let changed = false;
882 for (let i = 0; i < lines.length; i++) {
883 if (!C_CPLUSPLUS_GUARD_OPEN_RE.test(stripCr(lines[i] as string))) continue;
884 let end = -1;
885 for (let j = i + 1; j < lines.length && j - i - 1 <= C_CPLUSPLUS_GUARD_MAX_BODY_LINES; j++) {
886 const line = stripCr(lines[j] as string);
887 if (C_PREPROC_ENDIF_RE.test(line)) {
888 end = j;
889 break;
890 }
891 if (C_PREPROC_DIRECTIVE_RE.test(line)) break; // nested directive — bail
892 }
893 if (end < 0) continue;
894 for (let k = i + 1; k < end; k++) {
895 lines[k] = (lines[k] as string).replace(/[^\r]/g, ' ');
896 }
897 changed = true;
898 i = end;
899 }
900 return changed ? lines.join('\n') : source;
901}
902
903/**
904 * 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