MCPcopy Create free account
hub / github.com/scriptscat/scriptcat / summarizePattern

Function summarizePattern

src/pkg/utils/regex_to_glob.ts:406–425  ·  view source on GitHub ↗
(sub: string)

Source from the content-addressed store, hash-verified

404 // ----- Recursive summarizer for nested patterns -----
405 // 递归汇总:将子模式转为 glob,并估算 min/var
406 function summarizePattern(sub: string): Unit | null {
407 const g = regexToGlob(sub);
408 if (g === null) return null;
409 let min = 0,
410 varStar = false;
411 for (let k = 0; k < g.length; k++) {
412 const ch = g[k];
413 if (ch === "\\") {
414 k++;
415 if (k < g.length) min += 1;
416 } else if (ch === "*") {
417 varStar = true;
418 } else if (ch === "?") {
419 min += 1;
420 } else {
421 min += 1;
422 }
423 }
424 return { glob: g, baseGlob: "?".repeat(min), canRepeat: true, min, isLiteral: false, varLen: varStar };
425 }
426 const globIsPureLiteral = (s: string) => s.indexOf("*") === -1 && s.indexOf("?") === -1;
427
428 // ----- Group parsing (alternations, lookaheads, etc.) -----

Callers 1

parseGroupFunction · 0.85

Calls 1

regexToGlobFunction · 0.85

Tested by

no test coverage detected