MCPcopy Index your code
hub / github.com/colbymchenry/codegraph / stripRust

Function stripRust

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

Source from the content-addressed store, hash-verified

400// ---------- Rust ----------
401
402function stripRust(src: string): string {
403 const out = src.split('');
404 let i = 0;
405 const n = src.length;
406
407 while (i < n) {
408 const c = src[i]!;
409 const c2 = src[i + 1] ?? '';
410
411 // Nested block comment /* ... /* ... */ ... */
412 if (c === '/' && c2 === '*') {
413 const start = i;
414 i += 2;
415 let depth = 1;
416 while (i < n && depth > 0) {
417 if (src[i] === '/' && src[i + 1] === '*') {
418 depth++;
419 i += 2;
420 } else if (src[i] === '*' && src[i + 1] === '/') {
421 depth--;
422 i += 2;
423 } else {
424 i++;
425 }
426 }
427 blankRange(out, start, i, src);
428 continue;
429 }
430
431 // Line comment
432 if (c === '/' && c2 === '/') {
433 const start = i;
434 while (i < n && src[i] !== '\n') i++;
435 blankRange(out, start, i, src);
436 continue;
437 }
438
439 // String literals
440 if (c === '"') {
441 i++;
442 while (i < n && src[i] !== '"') {
443 if (src[i] === '\\' && i + 1 < n) {
444 i += 2;
445 continue;
446 }
447 i++;
448 }
449 if (i < n && src[i] === '"') i++;
450 continue;
451 }
452
453 // Char literal — keep simple: skip 'x' or '\x'
454 if (c === "'") {
455 // Could be a lifetime, e.g. 'a, but those don't contain routing text
456 i++;
457 while (i < n && src[i] !== "'") {
458 if (src[i] === '\\' && i + 1 < n) {
459 i += 2;

Callers 1

stripCommentsForRegexFunction · 0.85

Calls 2

blankRangeFunction · 0.85
joinMethod · 0.80

Tested by

no test coverage detected