(src: string)
| 324 | // ---------- Ruby ---------- |
| 325 | |
| 326 | function stripRuby(src: string): string { |
| 327 | const out = new BlankedText(src); |
| 328 | let i = 0; |
| 329 | const n = src.length; |
| 330 | let atLineStart = true; |
| 331 | |
| 332 | while (i < n) { |
| 333 | const c = src[i]!; |
| 334 | |
| 335 | // =begin / =end block comments must be at start of line (after optional whitespace) |
| 336 | if (atLineStart && c === '=' && src.startsWith('=begin', i)) { |
| 337 | const start = i; |
| 338 | // consume to matching =end at line start |
| 339 | i += '=begin'.length; |
| 340 | while (i < n) { |
| 341 | if (src[i] === '\n') { |
| 342 | // check next line for =end |
| 343 | let j = i + 1; |
| 344 | while (j < n && (src[j] === ' ' || src[j] === '\t')) j++; |
| 345 | if (src.startsWith('=end', j)) { |
| 346 | i = j + '=end'.length; |
| 347 | // consume rest of that line |
| 348 | while (i < n && src[i] !== '\n') i++; |
| 349 | break; |
| 350 | } |
| 351 | } |
| 352 | i++; |
| 353 | } |
| 354 | out.blank(start, i); |
| 355 | atLineStart = i > 0 && src[i - 1] === '\n'; |
| 356 | continue; |
| 357 | } |
| 358 | |
| 359 | // String literals |
| 360 | if (c === '"' || c === "'") { |
| 361 | const quote = c; |
| 362 | i++; |
| 363 | while (i < n && src[i] !== quote) { |
| 364 | if (src[i] === '\\' && i + 1 < n) { |
| 365 | i += 2; |
| 366 | continue; |
| 367 | } |
| 368 | if (src[i] === '\n') break; |
| 369 | i++; |
| 370 | } |
| 371 | if (i < n && src[i] === quote) i++; |
| 372 | atLineStart = false; |
| 373 | continue; |
| 374 | } |
| 375 | |
| 376 | // Line comment |
| 377 | if (c === '#') { |
| 378 | const start = i; |
| 379 | while (i < n && src[i] !== '\n') i++; |
| 380 | out.blank(start, i); |
| 381 | atLineStart = false; |
| 382 | continue; |
| 383 | } |
no test coverage detected