* Minimal shlex-style split for compiler command strings. * Handles double-quoted and single-quoted arguments.
(cmd: string)
| 1791 | * Handles double-quoted and single-quoted arguments. |
| 1792 | */ |
| 1793 | function shlexSplit(cmd: string): string[] { |
| 1794 | const result: string[] = []; |
| 1795 | let i = 0; |
| 1796 | while (i < cmd.length) { |
| 1797 | // Skip whitespace |
| 1798 | while (i < cmd.length && /\s/.test(cmd[i]!)) i++; |
| 1799 | if (i >= cmd.length) break; |
| 1800 | const ch = cmd[i]!; |
| 1801 | if (ch === '"') { |
| 1802 | i++; |
| 1803 | let arg = ''; |
| 1804 | while (i < cmd.length && cmd[i] !== '"') { |
| 1805 | if (cmd[i] === '\\' && i + 1 < cmd.length) { i++; arg += cmd[i]; } |
| 1806 | else { arg += cmd[i]; } |
| 1807 | i++; |
| 1808 | } |
| 1809 | i++; // closing quote |
| 1810 | result.push(arg); |
| 1811 | } else if (ch === "'") { |
| 1812 | i++; |
| 1813 | let arg = ''; |
| 1814 | while (i < cmd.length && cmd[i] !== "'") { arg += cmd[i]; i++; } |
| 1815 | i++; // closing quote |
| 1816 | result.push(arg); |
| 1817 | } else { |
| 1818 | let arg = ''; |
| 1819 | while (i < cmd.length && !/\s/.test(cmd[i]!)) { arg += cmd[i]; i++; } |
| 1820 | result.push(arg); |
| 1821 | } |
| 1822 | } |
| 1823 | return result; |
| 1824 | } |
| 1825 | |
| 1826 | /** |
| 1827 | * Heuristic include directory discovery when no compile_commands.json exists. |
no test coverage detected