MCPcopy Index your code
hub / github.com/Waishnav/devspace / findSequence

Function findSequence

src/apply-patch.ts:228–247  ·  view source on GitHub ↗
(haystack: string[], needle: string[], from: number, endOfFile = false)

Source from the content-addressed store, hash-verified

226}
227
228function findSequence(haystack: string[], needle: string[], from: number, endOfFile = false): number {
229 if (needle.length === 0) return from;
230
231 const matchAt = (index: number, normalize: (value: string) => string): boolean =>
232 needle.every((line, offset) => normalize(haystack[index + offset] ?? "") === normalize(line));
233
234 for (const normalize of [
235 (value: string) => value,
236 (value: string) => value.trimEnd(),
237 (value: string) => value.trim(),
238 ]) {
239 const start = endOfFile ? haystack.length - needle.length : from;
240 const end = haystack.length - needle.length;
241 for (let index = start; index <= end; index += 1) {
242 if (index >= from && matchAt(index, normalize)) return index;
243 }
244 }
245
246 return -1;
247}
248
249function applyHunks(path: string, content: string, hunks: UpdateHunk[]): string {
250 const file = splitFile(content);

Callers 1

applyHunksFunction · 0.85

Calls 1

matchAtFunction · 0.85

Tested by

no test coverage detected