* Minimal shlex-style split for compiler command strings. * Handles double-quoted and single-quoted arguments.
(cmd: string)
| 437 | * Handles double-quoted and single-quoted arguments. |
| 438 | */ |
| 439 | function shlexSplit(cmd: string): string[] { |
| 440 | const result: string[] = []; |
| 441 | let i = 0; |
| 442 | while (i < cmd.length) { |
| 443 | // Skip whitespace |
| 444 | while (i < cmd.length && /\s/.test(cmd[i]!)) i++; |
| 445 | if (i >= cmd.length) break; |
| 446 | const ch = cmd[i]!; |
| 447 | if (ch === '"') { |
| 448 | i++; |
| 449 | let arg = ''; |
| 450 | while (i < cmd.length && cmd[i] !== '"') { |
| 451 | if (cmd[i] === '\\' && i + 1 < cmd.length) { i++; arg += cmd[i]; } |
| 452 | else { arg += cmd[i]; } |
| 453 | i++; |
| 454 | } |
| 455 | i++; // closing quote |
| 456 | result.push(arg); |
| 457 | } else if (ch === "'") { |
| 458 | i++; |
| 459 | let arg = ''; |
| 460 | while (i < cmd.length && cmd[i] !== "'") { arg += cmd[i]; i++; } |
| 461 | i++; // closing quote |
| 462 | result.push(arg); |
| 463 | } else { |
| 464 | let arg = ''; |
| 465 | while (i < cmd.length && !/\s/.test(cmd[i]!)) { arg += cmd[i]; i++; } |
| 466 | result.push(arg); |
| 467 | } |
| 468 | } |
| 469 | return result; |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * Heuristic include directory discovery when no compile_commands.json exists. |
no outgoing calls
no test coverage detected