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