package buffruneio
import "github.com/pelletier/go-buffruneio"
Package buffruneio provides rune-based buffered input.
Index ¶
Constants ¶
const EOF = -1
EOF is a rune value indicating end-of-file.
Variables ¶
ErrNoRuneToUnread is the error returned when UnreadRune is called with nothing to unread.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
A Reader implements rune-based input for an underlying byte stream.
func NewReader ¶
NewReader returns a new Reader reading the given input.
func (*Reader) Forget ¶
func (rd *Reader) Forget()
Forget discards buffered runes before the current input position. Calling Forget makes it impossible to UnreadRune earlier than the current input position but is necessary to avoid unbounded buffer growth.
func (*Reader) PeekRunes ¶
PeekRunes returns the next n runes in the input, without advancing the current input position.
If the input has fewer than n runes and then returns an io.EOF error, PeekRune returns a slice containing the available runes followed by EOF. On other hand, if the input ends early with a non-io.EOF error, PeekRune returns a slice containing only the available runes, with no terminating EOF.
func (*Reader) ReadRune ¶
ReadRune reads and returns the next rune from the input. The rune is also saved in an internal buffer, in case UnreadRune is called. To avoid unbounded buffer growth, the caller must call Forget at appropriate intervals.
At end of file, ReadRune returns EOF, 0, nil. On read errors other than io.EOF, ReadRune returns EOF, 0, err.
func (*Reader) UnreadRune ¶
UnreadRune rewinds the input by one rune, undoing the effect of a single ReadRune call. UnreadRune may be called multiple times to rewind a sequence of ReadRune calls, up to the last time Forget was called or the beginning of the input.
If there are no ReadRune calls left to undo, UnreadRune returns ErrNoRuneToUnread.
Source Files ¶
- Version
- v0.3.0 (latest)
- Published
- Jan 3, 2019
- Platform
- darwin/amd64
- Imports
- 4 packages
- Last checked
- now –
Tools for package owners.