diff options
author | Tommy Nguyen <remyabel@gmail.com> | 2018-08-19 08:48:03 -0400 |
---|---|---|
committer | Tommy Nguyen <remyabel@gmail.com> | 2018-08-19 08:48:03 -0400 |
commit | 766197de9dd19fe743b21efe751c52db3e99aa3e (patch) | |
tree | 78ce80010057872348788760201612d553dea025 /pkg | |
parent | d2bdac29aa7038177ab26f91c06d9f01703d97c5 (diff) |
NormalizeLinefeeds removes rather than converts Window/Mac style lf's
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/view_helpers.go | 3 | ||||
-rw-r--r-- | pkg/utils/utils.go | 5 | ||||
-rw-r--r-- | pkg/utils/utils_test.go | 20 |
3 files changed, 15 insertions, 13 deletions
diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index c99609e3a..d6d10c780 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -219,7 +219,8 @@ func (gui *Gui) renderString(g *gocui.Gui, viewName, s string) error { return nil } v.Clear() - output := utils.NormalizeLinefeeds(string(bom.Clean([]byte(s)))) + output := string(bom.Clean([]byte(s))) + output = utils.NormalizeLinefeeds(s) fmt.Fprint(v, output) v.Wrap = true return nil diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 37e76d78a..f56ea8884 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -64,9 +64,10 @@ func TrimTrailingNewline(str string) string { return str } +// NormalizeLinefeeds - Removes all Windows and Mac style line feeds func NormalizeLinefeeds(str string) string { - str = strings.Replace(str, "\r\n", "\n", -1) - str = strings.Replace(str, "\r", "\n", -1) + str = strings.Replace(str, "\r\n", "", -1) + str = strings.Replace(str, "\r", "", -1) return str } diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go index 3a9f6817b..22a9c82dc 100644 --- a/pkg/utils/utils_test.go +++ b/pkg/utils/utils_test.go @@ -3,32 +3,32 @@ package utils import "testing" var testCases = []struct { - Input []byte + Input []byte Expected []byte }{ { // \r\n - Input: []byte{97, 115, 100, 102, 13, 10}, - Expected: []byte{97, 115, 100, 102, 10}, + Input: []byte{97, 115, 100, 102, 13, 10}, + Expected: []byte{97, 115, 100, 102}, }, { // \r - Input: []byte{97, 115, 100, 102, 13}, - Expected: []byte{97, 115, 100, 102, 10}, + Input: []byte{97, 115, 100, 102, 13}, + Expected: []byte{97, 115, 100, 102}, }, { // \n - Input: []byte{97, 115, 100, 102, 10}, + Input: []byte{97, 115, 100, 102, 10}, Expected: []byte{97, 115, 100, 102, 10}, }, - } func TestNormalizeLinefeeds(t *testing.T) { - for _, tc := range testCases { - if NormalizeLinefeeds(string(tc.Input)) != string(tc.Expected) { - t.Error("Error") + input := NormalizeLinefeeds(string(tc.Input)) + expected := string(tc.Expected) + if input != expected { + t.Error("Expected " + expected + ", got " + input) } } } |