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