ledger.Files.?etLastNLines trims empty lines
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
@@ -54,6 +55,9 @@ func (files Files) TempSetLastNLines(n int, lines []string) error {
|
||||
return "", err
|
||||
}
|
||||
for i := range lines {
|
||||
if len(strings.TrimSpace(lines[i])) == 0 {
|
||||
continue
|
||||
}
|
||||
if _, err := fmt.Fprintln(w, lines[i]); err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -87,7 +91,7 @@ func peekLastNLines(w io.Writer, r *bufio.Reader, n int) ([]string, error) {
|
||||
lastNLines := make([]string, 0, n)
|
||||
for {
|
||||
line, err := r.ReadBytes('\n')
|
||||
if len(line) > 0 {
|
||||
if len(bytes.TrimSpace(line)) > 0 {
|
||||
lastNLines = append(lastNLines, string(bytes.TrimRight(line, "\n")))
|
||||
for i := 0; i < len(lastNLines)-n; i++ {
|
||||
fmt.Fprintln(w, lastNLines[i])
|
||||
|
||||
Reference in New Issue
Block a user