MCPcopy Create free account
hub / github.com/coder/coder / seekLines

Function seekLines

agent/agentfiles/files.go:1440–1457  ·  view source on GitHub ↗

seekLines scans contentLines looking for a contiguous subsequence that matches searchLines according to the provided `eq` function. It returns the start and end (exclusive) indices into contentLines of the match.

(contentLines, searchLines []string, eq func(a, b string) bool)

Source from the content-addressed store, hash-verified

1438// searchLines according to the provided `eq` function. It returns the start and
1439// end (exclusive) indices into contentLines of the match.
1440func seekLines(contentLines, searchLines []string, eq func(a, b string) bool) (start, end int, ok bool) {
1441 if len(searchLines) == 0 {
1442 return 0, 0, true
1443 }
1444 if len(searchLines) > len(contentLines) {
1445 return 0, 0, false
1446 }
1447outer:
1448 for i := 0; i <= len(contentLines)-len(searchLines); i++ {
1449 for j, sLine := range searchLines {
1450 if !eq(contentLines[i+j], sLine) {
1451 continue outer
1452 }
1453 }
1454 return i, i + len(searchLines), true
1455 }
1456 return 0, 0, false
1457}
1458
1459// countLineMatches counts how many non-overlapping contiguous
1460// subsequences of contentLines match searchLines according to eq.

Callers 1

fuzzyReplaceLinesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected