Trim trailing whitespace

If a license text had blank lines, they would result in a trailing
whitespace when prefixed with the line comments.

This change removes trailing whitespace from the middle lines,
leaving top and bottom as is.

Fixes #10
This commit is contained in:
alex
2018-07-21 16:24:29 +02:00
parent fbdca00396
commit 6f621186c8
30 changed files with 96 additions and 98 deletions

20
tmpl.go
View File

@@ -15,9 +15,12 @@
package main package main
import ( import (
"bufio"
"bytes" "bytes"
"fmt" "fmt"
"html/template" "html/template"
"strings"
"unicode"
) )
var licenseTemplate = make(map[string]*template.Template) var licenseTemplate = make(map[string]*template.Template)
@@ -47,21 +50,16 @@ func prefix(l string, d *copyrightData, top, mid, bot string) ([]byte, error) {
} }
var out bytes.Buffer var out bytes.Buffer
if top != "" { if top != "" {
out.WriteString(top) fmt.Fprintln(&out, top)
out.WriteRune('\n')
} }
out.WriteString(mid) s := bufio.NewScanner(&buf)
for _, c := range buf.Bytes() { for s.Scan() {
out.WriteByte(c) fmt.Fprintln(&out, strings.TrimRightFunc(mid+s.Text(), unicode.IsSpace))
if c == '\n' {
out.WriteString(mid)
}
} }
if bot != "" { if bot != "" {
out.WriteRune('\n') fmt.Fprintln(&out, bot)
out.WriteString(bot)
} }
out.Write([]byte{'\n', '\n'}) fmt.Fprintln(&out)
return out.Bytes(), nil return out.Bytes(), nil
} }