MCPcopy Create free account
hub / github.com/chhoumann/quickadd / findMatchingDelimiter

Function findMatchingDelimiter

src/utils/userScriptSecrets.ts:203–247  ·  view source on GitHub ↗
(
	source: string,
	openIndex: number,
	open: "{" | "[",
	close: "}" | "]",
)

Source from the content-addressed store, hash-verified

201}
202
203function findMatchingDelimiter(
204 source: string,
205 openIndex: number,
206 open: "{" | "[",
207 close: "}" | "]",
208): number {
209 let depth = 0;
210
211 for (let current = openIndex; current < source.length; current++) {
212 const char = source[current];
213 const next = source[current + 1];
214
215 if (char === "\"" || char === "'" || char === "`") {
216 const literal = readStringLiteral(source, current);
217 if (!literal) return -1;
218 current = literal.end - 1;
219 continue;
220 }
221
222 if (char === "/" && next === "/") {
223 const newline = source.indexOf("\n", current + 2);
224 current = newline === -1 ? source.length : newline;
225 continue;
226 }
227
228 if (char === "/" && next === "*") {
229 const end = source.indexOf("*/", current + 2);
230 if (end === -1) return -1;
231 current = end + 1;
232 continue;
233 }
234
235 if (char === open) {
236 depth += 1;
237 continue;
238 }
239
240 if (char === close) {
241 depth -= 1;
242 if (depth === 0) return current;
243 }
244 }
245
246 return -1;
247}
248
249function collectStringConstants(source: string): Map<string, string> {
250 const constants = new Map<string, string>();

Callers 4

findOptionsObjectSpansFunction · 0.85
readOptionKeyFunction · 0.85

Calls 1

readStringLiteralFunction · 0.85

Tested by

no test coverage detected