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

Function blankCCplusplusGuardBodies

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

Source from the content-addressed store, hash-verified

2005const C_PREPROC_ENDIF_RE = /^[ \t]*#[ \t]*endif\b/;
2006const C_CPLUSPLUS_GUARD_MAX_BODY_LINES = 40;
2007export function blankCCplusplusGuardBodies(source: string): string {
2008 if (source.indexOf('__cplusplus') === -1) return source;
2009 const lines = source.split('\n');
2010 const stripCr = (l: string): string => (l.endsWith('\r') ? l.slice(0, -1) : l);
2011 let changed = false;
2012 for (let i = 0; i < lines.length; i++) {
2013 if (!C_CPLUSPLUS_GUARD_OPEN_RE.test(stripCr(lines[i] as string))) continue;
2014 let end = -1;
2015 for (let j = i + 1; j < lines.length && j - i - 1 <= C_CPLUSPLUS_GUARD_MAX_BODY_LINES; j++) {
2016 const line = stripCr(lines[j] as string);
2017 if (C_PREPROC_ENDIF_RE.test(line)) {
2018 end = j;
2019 break;
2020 }
2021 if (C_PREPROC_DIRECTIVE_RE.test(line)) break; // nested directive — bail
2022 }
2023 if (end < 0) continue;
2024 for (let k = i + 1; k < end; k++) {
2025 lines[k] = (lines[k] as string).replace(/[^\r]/g, ' ');
2026 }
2027 changed = true;
2028 i = end;
2029 }
2030 return changed ? lines.join('\n') : source;
2031}
2032
2033/**
2034 * 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