MCPcopy
hub / github.com/callumalpass/tasknotes / splitListPreservingLinksAndQuotes

Function splitListPreservingLinksAndQuotes

src/utils/stringSplit.ts:11–58  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

9 * - '"Focus, Deep Work", Notes' -> ['"Focus, Deep Work"', 'Notes']
10 */
11export function splitListPreservingLinksAndQuotes(input: string): string[] {
12 if (input == null) return [];
13 const out: string[] = [];
14 let buf = "";
15 let inLink = 0; // tracks [[ ... ]] depth
16 let inQuote: '"' | "'" | null = null;
17
18 for (let i = 0; i < input.length; i++) {
19 const c = input[i];
20 const next = input[i + 1];
21
22 // Enter/exit wikilink [[...]]
23 if (!inQuote && c === "[" && next === "[") {
24 inLink++;
25 buf += "[[";
26 i++;
27 continue;
28 }
29 if (!inQuote && c === "]" && next === "]" && inLink > 0) {
30 inLink--;
31 buf += "]]";
32 i++;
33 continue;
34 }
35
36 // Enter/exit quotes (only when not inside wikilink)
37 if (!inLink && (c === '"' || c === "'")) {
38 if (inQuote === null) inQuote = c;
39 else if (inQuote === c) inQuote = null;
40 buf += c;
41 continue;
42 }
43
44 // Top-level comma = separator
45 if (c === "," && inLink === 0 && inQuote === null) {
46 const token = buf.trim();
47 if (token) out.push(token);
48 buf = "";
49 continue;
50 }
51
52 buf += c;
53 }
54
55 const last = buf.trim();
56 if (last) out.push(last);
57 return out;
58}
59
60export default splitListPreservingLinksAndQuotes;

Callers 9

buildTaskEditChangesFunction · 0.90
buildTaskCreationDataFunction · 0.90
parseDependencyInputFunction · 0.90
renderCardFunction · 0.90
createTaskFileMethod · 0.90
normalizeUserListValueFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected