diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/field.nim | 25 | ||||
-rw-r--r-- | src/pointer.nim | 1 |
2 files changed, 17 insertions, 9 deletions
diff --git a/src/field.nim b/src/field.nim index 0a741c9..47c94b5 100644 --- a/src/field.nim +++ b/src/field.nim @@ -79,9 +79,10 @@ proc Load*(filename: string): ref Field = f.lines.add(Line()) var l = addr f.lines[0] var trailingSpaces = 0 - var data: array[255, char] + var data: array[4096, char] + var lastReadIsCR = false while true: - let n = file.readChars(data, 0, 255) + let n = file.readChars(data, 0, 4096) if n <= 0: if f.ly == 0: if l.l == 0: # we got en empty file! @@ -97,21 +98,29 @@ proc Load*(filename: string): ref Field = if data[i] == char(12): inc i continue + if lastReadIsCR and data[i] == '\n': + inc i + lastReadIsCR = false + continue if data[i] == '\n' or data[i] == '\r': if f.ly == 0: if l.l == 0: return nil f.x = l.x inc 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.add(Line()) l = addr f.lines[^1] trailingSpaces = 0 - if i+1 < n and data[i] == '\r' and data[i+1] == '\n': - inc i + if i+1 < n: + if data[i] == '\r' and data[i+1] == '\n': + inc i + else: + lastReadIsCR = true else: if data[i] == ' ': if l.l == 0: # trim leading spaces diff --git a/src/pointer.nim b/src/pointer.nim index cbf13b7..d6ce351 100644 --- a/src/pointer.nim +++ b/src/pointer.nim @@ -2,7 +2,6 @@ import defaultIO import field import stackStack -import math import os import random import times |