MCPcopy Create free account
hub / github.com/anomalyco/opencode / seekSequence

Function seekSequence

packages/opencode/src/patch/index.ts:460–484  ·  view source on GitHub ↗
(lines: string[], pattern: string[], startIndex: number, eof = false)

Source from the content-addressed store, hash-verified

458}
459
460function seekSequence(lines: string[], pattern: string[], startIndex: number, eof = false): number {
461 if (pattern.length === 0) return -1
462
463 // Pass 1: exact match
464 const exact = tryMatch(lines, pattern, startIndex, (a, b) => a === b, eof)
465 if (exact !== -1) return exact
466
467 // Pass 2: rstrip (trim trailing whitespace)
468 const rstrip = tryMatch(lines, pattern, startIndex, (a, b) => a.trimEnd() === b.trimEnd(), eof)
469 if (rstrip !== -1) return rstrip
470
471 // Pass 3: trim (both ends)
472 const trim = tryMatch(lines, pattern, startIndex, (a, b) => a.trim() === b.trim(), eof)
473 if (trim !== -1) return trim
474
475 // Pass 4: normalized (Unicode punctuation to ASCII)
476 const normalized = tryMatch(
477 lines,
478 pattern,
479 startIndex,
480 (a, b) => normalizeUnicode(a.trim()) === normalizeUnicode(b.trim()),
481 eof,
482 )
483 return normalized
484}
485
486function generateUnifiedDiff(oldContent: string, newContent: string): string {
487 const oldLines = oldContent.split("\n")

Callers 1

computeReplacementsFunction · 0.85

Calls 2

tryMatchFunction · 0.85
normalizeUnicodeFunction · 0.85

Tested by

no test coverage detected