MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / shlexSplit

Function shlexSplit

src/resolution/import-resolver.ts:1854–1885  ·  view source on GitHub ↗

* Minimal shlex-style split for compiler command strings. * Handles double-quoted and single-quoted arguments.

(cmd: string)

Source from the content-addressed store, hash-verified

1852 * Handles double-quoted and single-quoted arguments.
1853 */
1854function shlexSplit(cmd: string): string[] {
1855 const result: string[] = [];
1856 let i = 0;
1857 while (i < cmd.length) {
1858 // Skip whitespace
1859 while (i < cmd.length && /\s/.test(cmd[i]!)) i++;
1860 if (i >= cmd.length) break;
1861 const ch = cmd[i]!;
1862 if (ch === '"') {
1863 i++;
1864 let arg = '';
1865 while (i < cmd.length && cmd[i] !== '"') {
1866 if (cmd[i] === '\\' && i + 1 < cmd.length) { i++; arg += cmd[i]; }
1867 else { arg += cmd[i]; }
1868 i++;
1869 }
1870 i++; // closing quote
1871 result.push(arg);
1872 } else if (ch === "'") {
1873 i++;
1874 let arg = '';
1875 while (i < cmd.length && cmd[i] !== "'") { arg += cmd[i]; i++; }
1876 i++; // closing quote
1877 result.push(arg);
1878 } else {
1879 let arg = '';
1880 while (i < cmd.length && !/\s/.test(cmd[i]!)) { arg += cmd[i]; i++; }
1881 result.push(arg);
1882 }
1883 }
1884 return result;
1885}
1886
1887/**
1888 * Heuristic include directory discovery when no compile_commands.json exists.

Callers 1

readCompileDbIncludeDirsFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected