MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / applyReplacements

Function applyReplacements

src/core/tools/apply-patch/apply.ts:101–113  ·  view source on GitHub ↗

* Apply replacements to the original lines, returning the modified content. * Replacements must be applied in reverse order to preserve indices.

(lines: string[], replacements: Array<[number, number, string[]]>)

Source from the content-addressed store, hash-verified

99 * Replacements must be applied in reverse order to preserve indices.
100 */
101function applyReplacements(lines: string[], replacements: Array<[number, number, string[]]>): string[] {
102 const result = [...lines]
103
104 // Apply in reverse order so earlier replacements don't shift later indices
105 for (let i = replacements.length - 1; i >= 0; i--) {
106 const [startIdx, oldLen, newSegment] = replacements[i]!
107
108 // Remove old lines
109 result.splice(startIdx, oldLen, ...newSegment)
110 }
111
112 return result
113}
114
115/**
116 * Apply chunks to file content, returning the new content.

Callers 1

applyChunksToContentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected