openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
44 lines (43 loc) • 966 B
JavaScript
//#region src/daemon/arg-split.ts
/** Splits service command strings while preserving quoted arguments across platform parsers. */
function splitArgsPreservingQuotes(e, t) {
const n = [];
let r = null;
let i = null;
const a = t?.escapeMode ?? "none";
const o = new Set(t?.quoteChars ?? ["\""]);
const s = t?.quoteStart ?? "anywhere";
for (let t = 0; t < e.length; t++) {
const c = e.charAt(t);
if (c === "\\" && (a === "backslash" || a === "backslash-quote-only" && e[t + 1] === "\"")) {
if (t + 1 < e.length) {
r = (r ?? "") + e[t + 1];
t++;
}
continue;
}
if (o.has(c)) {
if (i === c) {
i = null;
continue;
}
if (!i && (s === "anywhere" || !r)) {
i = c;
r ??= "";
continue;
}
}
if (!i && /\s/.test(c)) {
if (r !== null) {
n.push(r);
r = null;
}
continue;
}
r = (r ?? "") + c;
}
if (r !== null) n.push(r);
return n;
}
//#endregion
export { splitArgsPreservingQuotes as t };