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

Function lineEquivalentMatchLines

agent/agentfiles/files.go:1283–1298  ·  view source on GitHub ↗

lineEquivalentMatchLines returns the 1-based start line of every contiguous block of contentLines that matches needleLines under eq.

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

Source from the content-addressed store, hash-verified

1281// lineEquivalentMatchLines returns the 1-based start line of every
1282// contiguous block of contentLines that matches needleLines under eq.
1283func lineEquivalentMatchLines(contentLines, needleLines []string, eq func(a, b string) bool) []int {
1284 if len(needleLines) == 0 || len(needleLines) > len(contentLines) {
1285 return nil
1286 }
1287 var starts []int
1288outer:
1289 for i := 0; i <= len(contentLines)-len(needleLines); i++ {
1290 for j, n := range needleLines {
1291 if !eq(contentLines[i+j], n) {
1292 continue outer
1293 }
1294 }
1295 starts = append(starts, i+1)
1296 }
1297 return starts
1298}
1299
1300// formatLineList renders a sorted line list as "12, 47, 89", truncated
1301// to maxHintLines entries with " and N more" when more exist.

Callers 1

inversionHintFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected