refactor(auto-reply): share directive arg parsing

This commit is contained in:
Peter Steinberger
2026-02-15 05:05:42 +00:00
parent 5c746d7751
commit 935ca39945
3 changed files with 50 additions and 50 deletions

View File

@@ -0,0 +1,40 @@
export function skipDirectiveArgPrefix(raw: string): number {
let i = 0;
const len = raw.length;
while (i < len && /\s/.test(raw[i])) {
i += 1;
}
if (raw[i] === ":") {
i += 1;
while (i < len && /\s/.test(raw[i])) {
i += 1;
}
}
return i;
}
export function takeDirectiveToken(
raw: string,
startIndex: number,
): { token: string | null; nextIndex: number } {
let i = startIndex;
const len = raw.length;
while (i < len && /\s/.test(raw[i])) {
i += 1;
}
if (i >= len) {
return { token: null, nextIndex: i };
}
const start = i;
while (i < len && !/\s/.test(raw[i])) {
i += 1;
}
if (start === i) {
return { token: null, nextIndex: i };
}
const token = raw.slice(start, i);
while (i < len && /\s/.test(raw[i])) {
i += 1;
}
return { token, nextIndex: i };
}