Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'd like to introduce a new method
readLine
andreadLineAlloc
(suggestions on a name would be appreciated) to the Reader interface. These functions help fulfill the outlined changes suggested in #6754 and #3822 for platform-agnostic line reading. These functions will treat a variety of cases of CR, LF, VT and FF as valid line terminators and consume all that happen at the end of a line.However... to implement these, the reader must be able to look forward and attempt to read the next character without committing to consuming that data. This is where Reader introduces an optional function on construction
peekFn
. For the most part, this change allows reading buffer data ahead of time without committing to consuming it. This was necessary for CR+LF and other edge case line termination formats.In addition, I then created
peek
equivalents ofreadByte, readStruct, readInt, readIntBig, readIntLittle ...
If a Reader does not have Peek defined, the peek functions
peek
peekAll
return 0 andpeekNoEof
and functions that rely on it returnerror.EndOfStream
.If a Reader does not have Peek defined, then the functions
readLine
andreadLineAlloc
return then upon finding one endline character.This is just a draft for now, but I'd be willing to discuss and make changes.
I'll be testing the new peek() functions and the readLine() alongside making sure I haven't broken test cases where peek is ignored. This will however force a change in the API for those who instantiate Reader() directly or extend upon it.
Additionally:
peekItemNext()
to grab the next available itempeek
functionalitypeek
functionalitypeek
functionalitypeek
functionalitypeek
functionalitypeek
functionalitypeek
functionalitypeek
functionalitypeek
functionality enabledpeek
functionality A plan for std.net #7194Tests: