MCPcopy
hub / github.com/colbymchenry/codegraph / shlexSplit

Function shlexSplit

src/resolution/import-resolver.ts:439–470  ·  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

437 * Handles double-quoted and single-quoted arguments.
438 */
439function 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.

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected