* Minimal shlex-style split for compiler command strings. * Handles double-quoted and single-quoted arguments.
(cmd: string)
| 611 | * Handles double-quoted and single-quoted arguments. |
| 612 | */ |
| 613 | function shlexSplit(cmd: string): string[] { |
| 614 | const result: string[] = []; |
| 615 | let i = 0; |
| 616 | while (i < cmd.length) { |
| 617 | // Skip whitespace |
| 618 | while (i < cmd.length && /\s/.test(cmd[i]!)) i++; |
| 619 | if (i >= cmd.length) break; |
| 620 | const ch = cmd[i]!; |
| 621 | if (ch === '"') { |
| 622 | i++; |
| 623 | let arg = ''; |
| 624 | while (i < cmd.length && cmd[i] !== '"') { |
| 625 | if (cmd[i] === '\\' && i + 1 < cmd.length) { i++; arg += cmd[i]; } |
| 626 | else { arg += cmd[i]; } |
| 627 | i++; |
| 628 | } |
| 629 | i++; // closing quote |
| 630 | result.push(arg); |
| 631 | } else if (ch === "'") { |
| 632 | i++; |
| 633 | let arg = ''; |
| 634 | while (i < cmd.length && cmd[i] !== "'") { arg += cmd[i]; i++; } |
| 635 | i++; // closing quote |
| 636 | result.push(arg); |
| 637 | } else { |
| 638 | let arg = ''; |
| 639 | while (i < cmd.length && !/\s/.test(cmd[i]!)) { arg += cmd[i]; i++; } |
| 640 | result.push(arg); |
| 641 | } |
| 642 | } |
| 643 | return result; |
| 644 | } |
| 645 | |
| 646 | /** |
| 647 | * Heuristic include directory discovery when no compile_commands.json exists. |
no outgoing calls
no test coverage detected