countLineMatches counts how many non-overlapping contiguous subsequences of contentLines match searchLines according to eq.
(contentLines, searchLines []string, eq func(a, b string) bool)
| 1459 | // countLineMatches counts how many non-overlapping contiguous |
| 1460 | // subsequences of contentLines match searchLines according to eq. |
| 1461 | func 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 | } |
| 1466 | outer: |
| 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 |