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

Function stripCStyle

src/resolution/strip-comments.ts:266–314  ·  view source on GitHub ↗
(src: string, allowSingleQuoteStrings: boolean)

Source from the content-addressed store, hash-verified

264// ---------- C-style (JS/TS/Java/C#/Swift) ----------
265
266function stripCStyle(src: string, allowSingleQuoteStrings: boolean): string {
267 const out = src.split('');
268 let i = 0;
269 const n = src.length;
270
271 while (i < n) {
272 const c = src[i]!;
273 const c2 = src[i + 1] ?? '';
274
275 // Block comment
276 if (c === '/' && c2 === '*') {
277 const start = i;
278 i += 2;
279 while (i < n && !(src[i] === '*' && src[i + 1] === '/')) i++;
280 if (i < n) i += 2;
281 blankRange(out, start, i, src);
282 continue;
283 }
284
285 // Line comment
286 if (c === '/' && c2 === '/') {
287 const start = i;
288 while (i < n && src[i] !== '\n') i++;
289 blankRange(out, start, i, src);
290 continue;
291 }
292
293 // String literals
294 if (c === '"' || (allowSingleQuoteStrings && c === "'") || c === '`') {
295 const quote = c;
296 i++;
297 while (i < n && src[i] !== quote) {
298 if (src[i] === '\\' && i + 1 < n) {
299 i += 2;
300 continue;
301 }
302 // Template literal can span lines; regular strings break on newline (treat as unterminated)
303 if (quote !== '`' && src[i] === '\n') break;
304 i++;
305 }
306 if (i < n && src[i] === quote) i++;
307 continue;
308 }
309
310 i++;
311 }
312
313 return out.join('');
314}
315
316// ---------- PHP ----------
317

Callers 1

stripCommentsForRegexFunction · 0.85

Calls 2

blankRangeFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected