diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/field/field.go | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/pkg/field/field.go b/pkg/field/field.go index 72890fe..efd59ec 100644 --- a/pkg/field/field.go +++ b/pkg/field/field.go @@ -32,6 +32,7 @@ func Load(fd io.Reader) (*Field, error) { f := new(Field) l := new(Line) trailingSpaces := 0 + lastReadIsCR := false for { data := make([]byte, 4096) if n, errRead := fd.Read(data); errRead != nil { @@ -61,6 +62,10 @@ func Load(fd io.Reader) (*Field, error) { if data[i] == '' { continue } + if lastReadIsCR && data[i] == '\n' { + lastReadIsCR = false + continue + } if data[i] == '\n' || data[i] == '\r' { if f.ly == 0 { if l.l == 0 { @@ -69,17 +74,23 @@ func Load(fd io.Reader) (*Field, error) { f.x = l.x } f.ly++ - if f.x > l.x { - f.x = l.x - } - if f.lx < l.l+l.x-f.x { - f.lx = l.l + l.x - f.x + if l.l > 0 { + if f.x > l.x { + f.x = l.x + } + if f.lx < l.l+l.x-f.x { + f.lx = l.l + l.x - f.x + } } f.lines = append(f.lines, *l) l = new(Line) trailingSpaces = 0 - if i+1 < n && data[i] == '\r' && data[i+1] == '\n' { - i++ + if data[i] == '\r' { + if i+1 < n && data[i+1] == '\n' { + i++ + } else { + lastReadIsCR = true + } } } else { if l.l == 0 && data[i] == ' ' { |