countLines returns the number of lines in content, handling trailing newlines correctly.
(content string)
| 302 | |
| 303 | // countLines returns the number of lines in content, handling trailing newlines correctly. |
| 304 | func countLines(content string) int { |
| 305 | if content == "" { |
| 306 | return 0 |
| 307 | } |
| 308 | n := strings.Count(content, "\n") |
| 309 | // If file ends with newline, the last "line" is empty — don't count it |
| 310 | if strings.HasSuffix(content, "\n") { |
| 311 | return n |
| 312 | } |
| 313 | return n + 1 |
| 314 | } |
| 315 | |
| 316 | // capFiles truncates the file list to maxFiles entries. |
| 317 | func capFiles(files []FileEntry, maxFiles int) []FileEntry { |