-
-
Save rbehrends/c7fbe8aa8660e3d4379a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| proc linesWithEndings(file: var TFile): seq[string] = | |
| var line = "" | |
| var buf: array[8192, char] | |
| var pendingCR = false | |
| result = newSeq[string]() | |
| while not file.endOfFile: | |
| let n = readChars(file, buf, 0, sizeof(buf)) | |
| for i in 0.. <n: | |
| let ch = buf[i] | |
| case ch | |
| of '\r': | |
| if pendingCR: | |
| add(result, line) | |
| line.setLen(0) | |
| pendingCR = true | |
| add(line, ch) | |
| of '\L': | |
| pendingCR = false | |
| add(line, ch) | |
| add(result, line) | |
| line.setLen(0) | |
| else: | |
| if pendingCR: | |
| pendingCR = false | |
| add(result, line) | |
| line.setLen(0) | |
| add(line, ch) | |
| if len(line) > 0: | |
| add(result, line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment