MCPcopy
hub / github.com/garrytan/gstack / inStructuralToken

Function inStructuralToken

lib/redact-engine.ts:502–524  ·  view source on GitHub ↗
(body: string, start: number, end: number)

Source from the content-addressed store, hash-verified

500}
501
502function inStructuralToken(body: string, start: number, end: number): boolean {
503 // Markdown link target: [text](...span...). The span may sit anywhere inside
504 // the parenthesized target (e.g. an email embedded in a URL). Walk backward
505 // from the span: if we reach `](` before hitting `)`/whitespace, and forward
506 // we reach `)` before whitespace, the span is inside a link target.
507 for (let i = start - 1; i >= 0; i--) {
508 const ch = body[i];
509 if (ch === ")" || ch === "\n" || ch === " " || ch === "\t") break;
510 if (ch === "(" && i > 0 && body[i - 1] === "]") {
511 for (let j = end; j < body.length; j++) {
512 const c = body[j];
513 if (c === " " || c === "\t" || c === "\n") break;
514 if (c === ")") return true;
515 }
516 break;
517 }
518 }
519 // JSON string value: "key": "...span..." — span is inside a quoted value.
520 const before = body.slice(Math.max(0, start - 80), start);
521 const after = body.slice(end, Math.min(body.length, end + 4));
522 if (/:\s*"$/.test(before) && /^"/.test(after)) return true;
523 return false;
524}
525
526function lineContaining(body: string, offset: number): string {
527 const start = body.lastIndexOf("\n", offset - 1) + 1;

Callers 1

applyRedactionsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected