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

Function countLineMatches

agent/agentfiles/files.go:1461–1477  ·  view source on GitHub ↗

countLineMatches counts how many non-overlapping contiguous subsequences of contentLines match searchLines according to eq.

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

Source from the content-addressed store, hash-verified

1459// countLineMatches counts how many non-overlapping contiguous
1460// subsequences of contentLines match searchLines according to eq.
1461func countLineMatches(contentLines, searchLines []string, eq func(a, b string) bool) int {
1462 count := 0
1463 if len(searchLines) == 0 || len(searchLines) > len(contentLines) {
1464 return count
1465 }
1466outer:
1467 for i := 0; i <= len(contentLines)-len(searchLines); i++ {
1468 for j, sLine := range searchLines {
1469 if !eq(contentLines[i+j], sLine) {
1470 continue outer
1471 }
1472 }
1473 count++
1474 i += len(searchLines) - 1 // skip past this match
1475 }
1476 return count
1477}
1478
1479// fuzzyReplaceLines handles fuzzy matching passes (2 and 3) for
1480// fuzzyReplace. When replaceAll is false and there are multiple

Callers 1

fuzzyReplaceLinesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected