(src: string)
| 587 | // ---------- Rust ---------- |
| 588 | |
| 589 | function stripRust(src: string): string { |
| 590 | const out = new BlankedText(src); |
| 591 | let i = 0; |
| 592 | const n = src.length; |
| 593 | |
| 594 | while (i < n) { |
| 595 | const c = src[i]!; |
| 596 | const c2 = src[i + 1] ?? ''; |
| 597 | |
| 598 | // Nested block comment /* ... /* ... */ ... */ |
| 599 | if (c === '/' && c2 === '*') { |
| 600 | const start = i; |
| 601 | i += 2; |
| 602 | let depth = 1; |
| 603 | while (i < n && depth > 0) { |
| 604 | if (src[i] === '/' && src[i + 1] === '*') { |
| 605 | depth++; |
| 606 | i += 2; |
| 607 | } else if (src[i] === '*' && src[i + 1] === '/') { |
| 608 | depth--; |
| 609 | i += 2; |
| 610 | } else { |
| 611 | i++; |
| 612 | } |
| 613 | } |
| 614 | out.blank(start, i); |
| 615 | continue; |
| 616 | } |
| 617 | |
| 618 | // Line comment |
| 619 | if (c === '/' && c2 === '/') { |
| 620 | const start = i; |
| 621 | while (i < n && src[i] !== '\n') i++; |
| 622 | out.blank(start, i); |
| 623 | continue; |
| 624 | } |
| 625 | |
| 626 | // String literals |
| 627 | if (c === '"') { |
| 628 | i++; |
| 629 | while (i < n && src[i] !== '"') { |
| 630 | if (src[i] === '\\' && i + 1 < n) { |
| 631 | i += 2; |
| 632 | continue; |
| 633 | } |
| 634 | i++; |
| 635 | } |
| 636 | if (i < n && src[i] === '"') i++; |
| 637 | continue; |
| 638 | } |
| 639 | |
| 640 | // Char literal — keep simple: skip 'x' or '\x' |
| 641 | if (c === "'") { |
| 642 | // Could be a lifetime, e.g. 'a, but those don't contain routing text |
| 643 | i++; |
| 644 | while (i < n && src[i] !== "'") { |
| 645 | if (src[i] === '\\' && i + 1 < n) { |
| 646 | i += 2; |
no test coverage detected