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

Function cppLiteralsBlanked

src/resolution/cpp-raw-strings.ts:140–169  ·  view source on GitHub ↗
(text: string, line: number, rawLines: Map<number, Ranges>)

Source from the content-addressed store, hash-verified

138 * and character literals blanked, raw strings included, columns kept.
139 */
140export function cppLiteralsBlanked(text: string, line: number, rawLines: Map<number, Ranges>): string {
141 const raw = rawLines.get(line);
142 const hasQuotes = text.includes('"') || text.includes('\'');
143 if (!raw && !hasQuotes) return text;
144 const blanks: Ranges = raw ? raw.slice() : [];
145 if (hasQuotes) {
146 const inRaw = (k: number): boolean => !!raw?.some(([start, end]) => k >= start && k < end);
147 for (let k = 0; k < text.length; k++) {
148 const c = text.charCodeAt(k);
149 if (c !== SLASH && c !== QUOTE && c !== APOSTROPHE) continue;
150 if (inRaw(k)) continue;
151 if (c === SLASH) {
152 const next = text.charCodeAt(k + 1);
153 if (next === SLASH) break;
154 if (next !== STAR) continue;
155 // A comment's quotes are no string's (cppCodeOf blanks the comment).
156 const close = text.indexOf('*/', k + 2);
157 if (close < 0) break;
158 k = close + 1;
159 continue;
160 }
161 if (c === APOSTROPHE && isWordCode(text.charCodeAt(k - 1))) continue;
162 let end = k + 1;
163 while (end < text.length && text.charCodeAt(end) !== c) end += text.charCodeAt(end) === BACKSLASH ? 2 : 1;
164 blanks.push([k + 1, Math.min(end, text.length)]);
165 k = end;
166 }
167 }
168 return blankRanges(text, blanks);
169}
170
171/** `text` with spaces over each of `ranges`, which may overlap and may run past its end. */
172function blankRanges(text: string, ranges: Ranges): string {

Callers 2

isCodeMethod · 0.90

Calls 5

inRawFunction · 0.85
isWordCodeFunction · 0.85
pushMethod · 0.80
blankRangesFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected