aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorJulien Dessaux2021-10-07 18:17:03 +0200
committerJulien Dessaux2021-10-07 18:17:03 +0200
commit71099a8a4ec8819094a210084d6b28bc4945780e (patch)
tree7bc23787fa4d47d84d5dc70d7fbae5299853f82b /pkg
parentsimplified some code (diff)
downloadgofunge98-71099a8a4ec8819094a210084d6b28bc4945780e.tar.gz
gofunge98-71099a8a4ec8819094a210084d6b28bc4945780e.tar.bz2
gofunge98-71099a8a4ec8819094a210084d6b28bc4945780e.zip
Fixed tricky field loading bug
Diffstat (limited to 'pkg')
-rw-r--r--pkg/field/field.go25
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] == ' ' {