MCPcopy Create free account
hub / github.com/arctic-cli/interface / applyReplacements

Function applyReplacements

packages/arctic/src/patch/index.ts:391–408  ·  view source on GitHub ↗
(lines: string[], replacements: Array<[number, number, string[]]>)

Source from the content-addressed store, hash-verified

389 }
390
391 function applyReplacements(lines: string[], replacements: Array<[number, number, string[]]>): string[] {
392 // Apply replacements in reverse order to avoid index shifting
393 const result = [...lines]
394
395 for (let i = replacements.length - 1; i >= 0; i--) {
396 const [startIdx, oldLen, newSegment] = replacements[i]
397
398 // Remove old lines
399 result.splice(startIdx, oldLen)
400
401 // Insert new lines
402 for (let j = 0; j < newSegment.length; j++) {
403 result.splice(startIdx + j, 0, newSegment[j])
404 }
405 }
406
407 return result
408 }
409
410 function seekSequence(lines: string[], pattern: string[], startIndex: number): number {
411 if (pattern.length === 0) return -1

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected