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

Function stripGo

src/resolution/strip-comments.ts:332–401  ·  view source on GitHub ↗
(src: string)

Source from the content-addressed store, hash-verified

330// ---------- Go ----------
331
332function stripGo(src: string): string {
333 const out = src.split('');
334 let i = 0;
335 const n = src.length;
336
337 while (i < n) {
338 const c = src[i]!;
339 const c2 = src[i + 1] ?? '';
340
341 // Block comment
342 if (c === '/' && c2 === '*') {
343 const start = i;
344 i += 2;
345 while (i < n && !(src[i] === '*' && src[i + 1] === '/')) i++;
346 if (i < n) i += 2;
347 blankRange(out, start, i, src);
348 continue;
349 }
350
351 // Line comment
352 if (c === '/' && c2 === '/') {
353 const start = i;
354 while (i < n && src[i] !== '\n') i++;
355 blankRange(out, start, i, src);
356 continue;
357 }
358
359 // Raw string with backticks (no escapes, can span lines)
360 if (c === '`') {
361 i++;
362 while (i < n && src[i] !== '`') i++;
363 if (i < n) i++;
364 continue;
365 }
366
367 // Interpreted string with double quotes
368 if (c === '"') {
369 i++;
370 while (i < n && src[i] !== '"') {
371 if (src[i] === '\\' && i + 1 < n) {
372 i += 2;
373 continue;
374 }
375 if (src[i] === '\n') break;
376 i++;
377 }
378 if (i < n && src[i] === '"') i++;
379 continue;
380 }
381
382 // Rune literal with single quotes (handle as a tiny string)
383 if (c === "'") {
384 i++;
385 while (i < n && src[i] !== "'") {
386 if (src[i] === '\\' && i + 1 < n) {
387 i += 2;
388 continue;
389 }

Callers 1

stripCommentsForRegexFunction · 0.85

Calls 2

blankRangeFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected