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

Function stripGo

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

Source from the content-addressed store, hash-verified

514// ---------- Go ----------
515
516function stripGo(src: string): string {
517 const out = new BlankedText(src);
518 let i = 0;
519 const n = src.length;
520
521 while (i < n) {
522 const c = src[i]!;
523 const c2 = src[i + 1] ?? '';
524
525 // Block comment
526 if (c === '/' && c2 === '*') {
527 const start = i;
528 i += 2;
529 while (i < n && !(src[i] === '*' && src[i + 1] === '/')) i++;
530 if (i < n) i += 2;
531 out.blank(start, i);
532 continue;
533 }
534
535 // Line comment
536 if (c === '/' && c2 === '/') {
537 const start = i;
538 while (i < n && src[i] !== '\n') i++;
539 out.blank(start, i);
540 continue;
541 }
542
543 // Raw string with backticks (no escapes, can span lines)
544 if (c === '`') {
545 i++;
546 while (i < n && src[i] !== '`') i++;
547 if (i < n) i++;
548 continue;
549 }
550
551 // Interpreted string with double quotes
552 if (c === '"') {
553 i++;
554 while (i < n && src[i] !== '"') {
555 if (src[i] === '\\' && i + 1 < n) {
556 i += 2;
557 continue;
558 }
559 if (src[i] === '\n') break;
560 i++;
561 }
562 if (i < n && src[i] === '"') i++;
563 continue;
564 }
565
566 // Rune literal with single quotes (handle as a tiny string)
567 if (c === "'") {
568 i++;
569 while (i < n && src[i] !== "'") {
570 if (src[i] === '\\' && i + 1 < n) {
571 i += 2;
572 continue;
573 }

Callers 1

stripCommentsForRegexFunction · 0.85

Calls 2

blankMethod · 0.95
textMethod · 0.95

Tested by

no test coverage detected